mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
Fixed search metadata export by passing query and filter to processQuery of AbstractSearch.
This commit is contained in:
@@ -731,22 +731,17 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
||||
*
|
||||
* @param scope the dspace object parent
|
||||
*/
|
||||
public DiscoverQuery prepareQuery(DSpaceObject scope) throws UIException, SearchServiceException {
|
||||
public DiscoverQuery prepareQuery(DSpaceObject scope, String query, String[] fqs) throws UIException, SearchServiceException {
|
||||
|
||||
this.queryArgs = new DiscoverQuery();
|
||||
|
||||
// possibly an argument
|
||||
int page = getParameterPage();
|
||||
|
||||
String query = getQuery();
|
||||
|
||||
|
||||
// Escape any special characters in this user-entered query
|
||||
query = DiscoveryUIUtils.escapeQueryChars(query);
|
||||
|
||||
List<String> filterQueries = new ArrayList<String>();
|
||||
|
||||
String[] fqs = getFilterQueries();
|
||||
|
||||
if (fqs != null)
|
||||
{
|
||||
filterQueries.addAll(Arrays.asList(fqs));
|
||||
@@ -850,7 +845,7 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
||||
return;
|
||||
}
|
||||
|
||||
this.queryResults = SearchUtils.getSearchService().search(context, scope, prepareQuery(scope));
|
||||
this.queryResults = SearchUtils.getSearchService().search(context, scope, prepareQuery(scope, getQuery(), getFilterQueries()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -20,26 +20,13 @@ import org.apache.excalibur.source.impl.validity.NOPValidity;
|
||||
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
|
||||
import org.dspace.app.xmlui.utils.HandleUtil;
|
||||
import org.dspace.app.xmlui.utils.UIException;
|
||||
import org.dspace.app.xmlui.utils.ContextUtil;
|
||||
import org.dspace.app.xmlui.wing.Message;
|
||||
import org.dspace.app.xmlui.wing.WingException;
|
||||
import org.dspace.app.xmlui.wing.element.List;
|
||||
import org.dspace.app.xmlui.wing.element.Options;
|
||||
import org.dspace.app.xmlui.wing.element.PageMeta;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.discovery.*;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Navigation that adds code needed for discovery search
|
||||
*
|
||||
@@ -49,18 +36,12 @@ import org.apache.log4j.Logger;
|
||||
*/
|
||||
public class Navigation extends AbstractDSpaceTransformer implements CacheableProcessingComponent
|
||||
{
|
||||
private static final Logger log = Logger.getLogger(Navigation.class);
|
||||
private static final Message T_context_head = message("xmlui.administrative.Navigation.context_head");
|
||||
private static final Message T_export_metadata = message("xmlui.administrative.Navigation.context_search_export_metadata");
|
||||
|
||||
private AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||
|
||||
/**
|
||||
* Generate the unique caching key.
|
||||
* This key must be unique inside the space of this component.
|
||||
*/
|
||||
public Serializable getKey() {
|
||||
try {
|
||||
try {
|
||||
Request request = ObjectModelHelper.getRequest(objectModel);
|
||||
String key = request.getScheme() + request.getServerName() + request.getServerPort() + request.getSitemapURI() + request.getQueryString();
|
||||
|
||||
@@ -97,24 +78,24 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
|
||||
*
|
||||
* language FIXME: add languages
|
||||
*
|
||||
* context - export metadata if in discover
|
||||
* context no context options are added.
|
||||
*
|
||||
* action no action options are added.
|
||||
*/
|
||||
public void addOptions(Options options) throws SAXException, WingException,
|
||||
UIException, SQLException, IOException, AuthorizeException
|
||||
{
|
||||
Context context = ContextUtil.obtainContext(objectModel);
|
||||
Request request = ObjectModelHelper.getRequest(objectModel);
|
||||
|
||||
// code remnants left behind, probably can be deleted
|
||||
|
||||
//List test = options.addList("browse");
|
||||
//List discovery = options.addList("discovery-search");
|
||||
//discovery.setHead("Discovery");
|
||||
//discovery.addItem().addXref(contextPath + "/discover" , "Discover");
|
||||
// DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
|
||||
|
||||
/*
|
||||
// List test = options.addList("browse");
|
||||
|
||||
// List discovery = options.addList("discovery-search");
|
||||
|
||||
// discovery.setHead("Discovery");
|
||||
//
|
||||
// discovery.addItem().addXref(contextPath + "/discover" , "Discover");
|
||||
|
||||
/*
|
||||
List browse = options.addList("browse");
|
||||
|
||||
browse.setHead(T_head_browse);
|
||||
@@ -124,6 +105,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
|
||||
|
||||
browseGlobal.setHead(T_head_all_of_dspace);
|
||||
|
||||
|
||||
if (dso != null)
|
||||
{
|
||||
if (dso instanceof Collection)
|
||||
@@ -136,80 +118,15 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
|
||||
}
|
||||
}
|
||||
browseGlobal.addItem().addXref(contextPath + "/community-list", T_head_all_of_dspace );
|
||||
*/
|
||||
*/
|
||||
|
||||
/* regulate the ordering */
|
||||
options.addList("discovery");
|
||||
options.addList("browse");
|
||||
options.addList("account");
|
||||
options.addList("context");
|
||||
options.addList("administrative");
|
||||
|
||||
// get uri to see if using discovery and if under a specific handle
|
||||
String uri = request.getSitemapURI();
|
||||
|
||||
// check value in dspace.cfg
|
||||
String search_export_config = ConfigurationManager.getProperty("xmlui.search.metadata_export");
|
||||
|
||||
// get query
|
||||
String query = decodeFromURL(request.getParameter("query"));
|
||||
|
||||
// get scope, if not under handle returns null
|
||||
String scope= request.getParameter("scope");
|
||||
|
||||
// used to serialize all query filters together
|
||||
String filters = "";
|
||||
|
||||
// get all query filters
|
||||
String[] fqs = DiscoveryUIUtils.getFilterQueries(ObjectModelHelper.getRequest(objectModel), context);
|
||||
|
||||
if (fqs != null)
|
||||
{
|
||||
for(int i = 0; i < fqs.length; i++) {
|
||||
if(i < fqs.length - 1)
|
||||
filters += fqs[i] + ",";
|
||||
else
|
||||
filters += fqs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(uri.contains("discover")) {
|
||||
// check scope
|
||||
if(scope == null || "".equals(scope))
|
||||
scope = "/";
|
||||
// check query
|
||||
if(query == null || "".equals(query))
|
||||
query = "*";
|
||||
// check if under a handle, already in discovery
|
||||
if(uri.contains("handle")) {
|
||||
scope = uri.replace("handle/", "").replace("/discover", "");
|
||||
}
|
||||
// replace forward slash to pass through sitemap
|
||||
try {
|
||||
scope = scope.replace("/", "~");
|
||||
}
|
||||
catch(NullPointerException e) { }
|
||||
if(search_export_config != null) {
|
||||
// some logging
|
||||
|
||||
log.info("uri: " + uri);
|
||||
log.info("query: " + query);
|
||||
log.info("scope: " + scope);
|
||||
log.info("filters: " + filters);
|
||||
|
||||
if(search_export_config.equals("admin")) {
|
||||
if(authorizeService.isAdmin(context)) {
|
||||
List results = options.addList("context");
|
||||
results.setHead(T_context_head);
|
||||
results.addItem().addXref(contextPath + "/discover/csv/" + query + "/" + scope + "/" + filters, T_export_metadata);
|
||||
}
|
||||
}
|
||||
else if(search_export_config.equals("user") || search_export_config.equals("anonymous")){
|
||||
List results = options.addList("context");
|
||||
results.setHead(T_context_head);
|
||||
results.addItem().addXref(contextPath + "/discover/csv/" + query + "/" + scope + "/" + filters, T_export_metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,9 +136,14 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
|
||||
WingException, UIException, SQLException, IOException,
|
||||
AuthorizeException
|
||||
{
|
||||
|
||||
// Add metadata for quick searches:
|
||||
pageMeta.addMetadata("search", "simpleURL").addContent("/discover");
|
||||
pageMeta.addMetadata("search", "advancedURL").addContent(contextPath + "/discover");
|
||||
pageMeta.addMetadata("search", "simpleURL").addContent(
|
||||
"/discover");
|
||||
pageMeta.addMetadata("search", "advancedURL").addContent(
|
||||
contextPath + "/discover");
|
||||
pageMeta.addMetadata("search", "queryField").addContent("query");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -110,7 +110,7 @@ public abstract class AbstractDSpaceTransformer extends AbstractWingTransformer
|
||||
"An error was encountered while processing the '"+this.getComponentName()+"' Wing based component: "
|
||||
+ this.getClass().getName(), e);
|
||||
}
|
||||
|
||||
|
||||
/** What to add at the end of the body */
|
||||
public void addBody(Body body) throws SAXException, WingException,
|
||||
UIException, SQLException, IOException, AuthorizeException, ProcessingException
|
||||
|
@@ -10,8 +10,6 @@ package org.dspace.app.xmlui.cocoon;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -67,9 +65,7 @@ import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration;
|
||||
*/
|
||||
|
||||
public class SearchMetadataExportReader extends AbstractReader implements Recyclable
|
||||
{
|
||||
private static Logger log = Logger.getLogger(MetadataExportReader.class);
|
||||
|
||||
{
|
||||
/**
|
||||
* Messages to be sent when the user is not authorized to view
|
||||
* a particular bitstream. They will be redirected to the login
|
||||
@@ -98,23 +94,18 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl
|
||||
|
||||
/** The Cocoon request */
|
||||
protected Request request;
|
||||
|
||||
|
||||
private static Logger log = Logger.getLogger(SearchMetadataExportReader.class);
|
||||
|
||||
private AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||
private HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
|
||||
|
||||
private DSpaceCSV csv = null;
|
||||
private String filename = null;
|
||||
|
||||
private SimpleSearch simpleSearch = null;
|
||||
|
||||
|
||||
private AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||
|
||||
private HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
|
||||
|
||||
|
||||
public SearchMetadataExportReader() {
|
||||
simpleSearch = new SimpleSearch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set up the export reader.
|
||||
*
|
||||
@@ -169,6 +160,8 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl
|
||||
}
|
||||
}
|
||||
|
||||
simpleSearch = new SimpleSearch();
|
||||
|
||||
csv = exportMetadata(context, objectModel, query, scope, filters);
|
||||
filename = "search-results.csv";
|
||||
|
||||
@@ -217,27 +210,27 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl
|
||||
|
||||
DiscoverQuery qArgs = new DiscoverQuery();
|
||||
|
||||
try {
|
||||
scopeString = scopeString.replace("~", "/");
|
||||
}
|
||||
catch(NullPointerException e) { }
|
||||
|
||||
// Are we in a community or collection?
|
||||
// Are we in a community or collection?
|
||||
DSpaceObject scope;
|
||||
if (scopeString == null || "".equals(scopeString)) {
|
||||
// get the search scope from the url handle
|
||||
|
||||
if(scopeString != null && scopeString.length() > 0) {
|
||||
scopeString = scopeString.replace("~", "/");
|
||||
// Get the search scope from the location parameter
|
||||
scope = handleService.resolveToObject(context, scopeString);
|
||||
}
|
||||
else {
|
||||
// get the search scope from the url handle
|
||||
scope = HandleUtil.obtainHandle(objectModel);
|
||||
}
|
||||
else {
|
||||
// Get the search scope from the location parameter
|
||||
scope = handleService.resolveToObject(context, scopeString);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// set the object model on the simple search object
|
||||
simpleSearch.objectModel = objectModel;
|
||||
|
||||
|
||||
// prepare query from SimpleSearch object
|
||||
qArgs = simpleSearch.prepareQuery(scope);
|
||||
qArgs = simpleSearch.prepareQuery(scope, query, filters.split(","));
|
||||
|
||||
// no paging required
|
||||
qArgs.setStart(0);
|
||||
@@ -265,10 +258,13 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl
|
||||
// Log the attempt
|
||||
log.info(LogManager.getHeader(context, "metadataexport", "exporting_search"));
|
||||
|
||||
MetadataExport exporter = new MetadataExport(context, items.iterator(), false);
|
||||
Iterator<Item> toExport = items.iterator();
|
||||
|
||||
MetadataExport exporter = new MetadataExport(context, toExport, false);
|
||||
|
||||
// Perform the export
|
||||
DSpaceCSV csv = exporter.export();
|
||||
DSpaceCSV csv = exporter.export();
|
||||
|
||||
log.info(LogManager.getHeader(context, "metadataexport", "exported_file:search-results.csv"));
|
||||
|
||||
return csv;
|
||||
|
@@ -30,10 +30,10 @@ and searching the repository.
|
||||
<map:transformer name="SiteRecentSubmissions" src="org.dspace.app.xmlui.aspect.discovery.SiteRecentSubmissions"/>
|
||||
<map:transformer name="SidebarFacetsTransformer" src="org.dspace.app.xmlui.aspect.discovery.SidebarFacetsTransformer"/>
|
||||
|
||||
|
||||
<map:transformer name="CommunitySearch" src="org.dspace.app.xmlui.aspect.discovery.CommunitySearch"/>
|
||||
<map:transformer name="CommunityRecentSubmissions" src="org.dspace.app.xmlui.aspect.discovery.CommunityRecentSubmissions"/>
|
||||
|
||||
<map:transformer name="CSVExportDiscoveryNavigation" src="org.dspace.app.xmlui.aspect.discovery.CSVExportDiscoveryNavigation"/>
|
||||
|
||||
<map:transformer name="CollectionSearch" src="org.dspace.app.xmlui.aspect.discovery.CollectionSearch"/>
|
||||
<map:transformer name="CollectionRecentSubmissions" src="org.dspace.app.xmlui.aspect.discovery.CollectionRecentSubmissions"/>
|
||||
@@ -76,7 +76,7 @@ and searching the repository.
|
||||
3) Metadata about the search urls.
|
||||
-->
|
||||
<map:transform type="Navigation"/>
|
||||
|
||||
|
||||
<!--
|
||||
Display the DSpace homepage. This includes the news.xml file
|
||||
along with a list of top level communities in DSpace.
|
||||
@@ -110,6 +110,7 @@ and searching the repository.
|
||||
|
||||
<!-- Search -->
|
||||
<map:match pattern="discover">
|
||||
<map:transform type="CSVExportDiscoveryNavigation"/>
|
||||
<map:act type="DiscoverySearchLoggerAction"/>
|
||||
<map:transform type="SidebarFacetsTransformer"/>
|
||||
<map:transform type="SimpleSearch"/>
|
||||
@@ -147,6 +148,7 @@ and searching the repository.
|
||||
|
||||
<!-- Simple search -->
|
||||
<map:match pattern="handle/*/*/discover">
|
||||
<map:transform type="CSVExportDiscoveryNavigation"/>
|
||||
<map:act type="DiscoverySearchLoggerAction"/>
|
||||
<map:transform type="SidebarFacetsTransformer"/>
|
||||
<map:transform type="SimpleSearch"/>
|
||||
|
@@ -192,8 +192,20 @@
|
||||
<map:reader name="ExportReader" src="org.dspace.app.xmlui.cocoon.ItemExportDownloadReader"/>
|
||||
<map:reader name="MetadataExportReader" src="org.dspace.app.xmlui.cocoon.MetadataExportReader"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<map:reader name="SearchMetadataExportReader" src="org.dspace.app.xmlui.cocoon.SearchMetadataExportReader"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<map:reader name="CSVOutputter" src="org.dspace.app.xmlui.aspect.statisticsElasticSearch.CSVOutputter"/>
|
||||
|
||||
<map:reader name="OpenURLReader" src="org.dspace.app.xmlui.cocoon.OpenURLReader"/>
|
||||
@@ -391,6 +403,11 @@
|
||||
</map:read>
|
||||
</map:match>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<map:match pattern="discover/csv/*/*/*">
|
||||
<map:read type="SearchMetadataExportReader">
|
||||
<map:parameter name="query" value="{1}"/>
|
||||
@@ -399,6 +416,11 @@
|
||||
</map:read>
|
||||
</map:match>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<map:match pattern="handle/*/*/stats/csv">
|
||||
<map:match type="StatisticsAuthorizedMatcher" pattern="READ">
|
||||
<map:read type="CSVOutputter"/>
|
||||
|
Reference in New Issue
Block a user