mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-13 21:13:19 +00:00
ExportMetadata method now in SearchMetadataExportReader. Cleaned up code. Added some comments.
This commit is contained in:
@@ -17,13 +17,10 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import org.apache.excalibur.source.SourceValidity;
|
import org.apache.excalibur.source.SourceValidity;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.util.MetadataExposure;
|
import org.dspace.app.util.MetadataExposure;
|
||||||
import org.dspace.app.bulkedit.DSpaceCSV;
|
|
||||||
import org.dspace.app.bulkedit.MetadataExport;
|
|
||||||
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
|
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
|
||||||
import org.dspace.app.xmlui.utils.DSpaceValidity;
|
import org.dspace.app.xmlui.utils.DSpaceValidity;
|
||||||
import org.dspace.app.xmlui.utils.HandleUtil;
|
import org.dspace.app.xmlui.utils.HandleUtil;
|
||||||
import org.dspace.app.xmlui.utils.UIException;
|
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.Message;
|
||||||
import org.dspace.app.xmlui.wing.WingException;
|
import org.dspace.app.xmlui.wing.WingException;
|
||||||
import org.dspace.app.xmlui.wing.element.*;
|
import org.dspace.app.xmlui.wing.element.*;
|
||||||
@@ -31,8 +28,6 @@ import org.dspace.authorize.AuthorizeException;
|
|||||||
import org.dspace.content.*;
|
import org.dspace.content.*;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.ItemIterator;
|
|
||||||
import org.dspace.core.Context;
|
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.LogManager;
|
import org.dspace.core.LogManager;
|
||||||
import org.dspace.discovery.*;
|
import org.dspace.discovery.*;
|
||||||
@@ -69,24 +64,27 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
*/
|
*/
|
||||||
private static final Message T_head1_community =
|
private static final Message T_head1_community =
|
||||||
message("xmlui.Discovery.AbstractSearch.head1_community");
|
message("xmlui.Discovery.AbstractSearch.head1_community");
|
||||||
|
|
||||||
private static final Message T_head1_collection =
|
private static final Message T_head1_collection =
|
||||||
message("xmlui.Discovery.AbstractSearch.head1_collection");
|
message("xmlui.Discovery.AbstractSearch.head1_collection");
|
||||||
|
|
||||||
private static final Message T_head1_none =
|
private static final Message T_head1_none =
|
||||||
message("xmlui.Discovery.AbstractSearch.head1_none");
|
message("xmlui.Discovery.AbstractSearch.head1_none");
|
||||||
|
|
||||||
private static final Message T_no_results =
|
private static final Message T_no_results =
|
||||||
message("xmlui.ArtifactBrowser.AbstractSearch.no_results");
|
message("xmlui.ArtifactBrowser.AbstractSearch.no_results");
|
||||||
|
|
||||||
private static final Message T_all_of_dspace =
|
private static final Message T_all_of_dspace =
|
||||||
message("xmlui.ArtifactBrowser.AbstractSearch.all_of_dspace");
|
message("xmlui.ArtifactBrowser.AbstractSearch.all_of_dspace");
|
||||||
|
|
||||||
private static final Message T_sort_by_relevance =
|
private static final Message T_sort_by_relevance =
|
||||||
message("xmlui.Discovery.AbstractSearch.sort_by.relevance");
|
message("xmlui.Discovery.AbstractSearch.sort_by.relevance");
|
||||||
private static final Message T_sort_by =
|
|
||||||
message("xmlui.Discovery.AbstractSearch.sort_by.head");
|
private static final Message T_sort_by = message("xmlui.Discovery.AbstractSearch.sort_by.head");
|
||||||
private static final Message T_rpp =
|
|
||||||
message("xmlui.Discovery.AbstractSearch.rpp");
|
private static final Message T_rpp = message("xmlui.Discovery.AbstractSearch.rpp");
|
||||||
private static final Message T_result_head_3 =
|
private static final Message T_result_head_3 = message("xmlui.Discovery.AbstractSearch.head3");
|
||||||
message("xmlui.Discovery.AbstractSearch.head3");
|
private static final Message T_result_head_2 = message("xmlui.Discovery.AbstractSearch.head2");
|
||||||
private static final Message T_result_head_2 =
|
|
||||||
message("xmlui.Discovery.AbstractSearch.head2");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached query results
|
* Cached query results
|
||||||
@@ -290,6 +288,7 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
Division results = search.addDivision("search-results", "primary");
|
Division results = search.addDivision("search-results", "primary");
|
||||||
buildSearchControls(results);
|
buildSearchControls(results);
|
||||||
|
|
||||||
|
|
||||||
DSpaceObject searchScope = getScope();
|
DSpaceObject searchScope = getScope();
|
||||||
|
|
||||||
int displayedResults;
|
int displayedResults;
|
||||||
@@ -714,29 +713,34 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
* Query DSpace for a list of all items / collections / or communities that
|
* Query DSpace for a list of all items / collections / or communities that
|
||||||
* match the given search query.
|
* match the given search query.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* @param scope the dspace object parent
|
* @param scope the dspace object parent
|
||||||
*/
|
*/
|
||||||
public void performSearch(DSpaceObject scope) throws UIException, SearchServiceException
|
public void performSearch(DSpaceObject scope) throws UIException, SearchServiceException {
|
||||||
|
|
||||||
|
if (queryResults != null)
|
||||||
{
|
{
|
||||||
if (queryResults != null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String query = getQuery();
|
String query = getQuery();
|
||||||
|
|
||||||
|
//DSpaceObject scope = getScope();
|
||||||
|
|
||||||
int page = getParameterPage();
|
int page = getParameterPage();
|
||||||
|
|
||||||
List<String> filterQueries = new ArrayList<String>();
|
List<String> filterQueries = new ArrayList<String>();
|
||||||
|
|
||||||
String[] fqs = getFilterQueries();
|
String[] fqs = getFilterQueries();
|
||||||
|
|
||||||
if (fqs != null) {
|
if (fqs != null)
|
||||||
|
{
|
||||||
filterQueries.addAll(Arrays.asList(fqs));
|
filterQueries.addAll(Arrays.asList(fqs));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.queryArgs = new DiscoverQuery();
|
|
||||||
|
|
||||||
queryArgs.setMaxResults(getParameterRpp());
|
this.queryArgs = new DiscoverQuery();
|
||||||
|
|
||||||
//Add the configured default filter queries
|
//Add the configured default filter queries
|
||||||
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(scope);
|
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(scope);
|
||||||
@@ -747,34 +751,40 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
queryArgs.addFilterQueries(filterQueries.toArray(new String[filterQueries.size()]));
|
queryArgs.addFilterQueries(filterQueries.toArray(new String[filterQueries.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
queryArgs.setMaxResults(getParameterRpp());
|
||||||
|
|
||||||
String sortBy = ObjectModelHelper.getRequest(objectModel).getParameter("sort_by");
|
String sortBy = ObjectModelHelper.getRequest(objectModel).getParameter("sort_by");
|
||||||
DiscoverySortConfiguration searchSortConfiguration = discoveryConfiguration.getSearchSortConfiguration();
|
DiscoverySortConfiguration searchSortConfiguration = discoveryConfiguration.getSearchSortConfiguration();
|
||||||
if(sortBy == null) {
|
if(sortBy == null){
|
||||||
//Attempt to find the default one, if none found we use SCORE
|
//Attempt to find the default one, if none found we use SCORE
|
||||||
sortBy = "score";
|
sortBy = "score";
|
||||||
if(searchSortConfiguration != null) {
|
if(searchSortConfiguration != null){
|
||||||
for (DiscoverySortFieldConfiguration sortFieldConfiguration : searchSortConfiguration.getSortFields()) {
|
for (DiscoverySortFieldConfiguration sortFieldConfiguration : searchSortConfiguration.getSortFields()) {
|
||||||
if(sortFieldConfiguration.equals(searchSortConfiguration.getDefaultSort())) {
|
if(sortFieldConfiguration.equals(searchSortConfiguration.getDefaultSort())){
|
||||||
sortBy = SearchUtils.getSearchService().toSortFieldIndex(sortFieldConfiguration.getMetadataField(), sortFieldConfiguration.getType());
|
sortBy = SearchUtils.getSearchService().toSortFieldIndex(sortFieldConfiguration.getMetadataField(), sortFieldConfiguration.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String sortOrder = ObjectModelHelper.getRequest(objectModel).getParameter("order");
|
String sortOrder = ObjectModelHelper.getRequest(objectModel).getParameter("order");
|
||||||
if(sortOrder == null && searchSortConfiguration != null) {
|
if(sortOrder == null && searchSortConfiguration != null){
|
||||||
sortOrder = searchSortConfiguration.getDefaultSortOrder().toString();
|
sortOrder = searchSortConfiguration.getDefaultSortOrder().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sortOrder == null || sortOrder.equalsIgnoreCase("DESC")) {
|
if (sortOrder == null || sortOrder.equalsIgnoreCase("DESC"))
|
||||||
|
{
|
||||||
queryArgs.setSortField(sortBy, DiscoverQuery.SORT_ORDER.desc);
|
queryArgs.setSortField(sortBy, DiscoverQuery.SORT_ORDER.desc);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
queryArgs.setSortField(sortBy, DiscoverQuery.SORT_ORDER.asc);
|
queryArgs.setSortField(sortBy, DiscoverQuery.SORT_ORDER.asc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String groupBy = ObjectModelHelper.getRequest(objectModel).getParameter("group_by");
|
String groupBy = ObjectModelHelper.getRequest(objectModel).getParameter("group_by");
|
||||||
|
|
||||||
|
|
||||||
// Enable groupBy collapsing if designated
|
// Enable groupBy collapsing if designated
|
||||||
if (groupBy != null && !groupBy.equalsIgnoreCase("none")) {
|
if (groupBy != null && !groupBy.equalsIgnoreCase("none")) {
|
||||||
/** Construct a Collapse Field Query */
|
/** Construct a Collapse Field Query */
|
||||||
@@ -789,20 +799,26 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
// TODO: I think that can be more transparently done in the solr solrconfig.xml with DISMAX and boosting
|
// TODO: I think that can be more transparently done in the solr solrconfig.xml with DISMAX and boosting
|
||||||
/** sort in groups to get publications to top */
|
/** sort in groups to get publications to top */
|
||||||
queryArgs.setSortField("dc.type", DiscoverQuery.SORT_ORDER.asc);
|
queryArgs.setSortField("dc.type", DiscoverQuery.SORT_ORDER.asc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
queryArgs.setQuery(query != null && !query.trim().equals("") ? query : null);
|
queryArgs.setQuery(query != null && !query.trim().equals("") ? query : null);
|
||||||
|
|
||||||
if (page > 1) {
|
if (page > 1)
|
||||||
|
{
|
||||||
queryArgs.setStart((page - 1) * queryArgs.getMaxResults());
|
queryArgs.setStart((page - 1) * queryArgs.getMaxResults());
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
queryArgs.setStart(0);
|
queryArgs.setStart(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(discoveryConfiguration.getHitHighlightingConfiguration() != null) {
|
if(discoveryConfiguration.getHitHighlightingConfiguration() != null)
|
||||||
|
{
|
||||||
List<DiscoveryHitHighlightFieldConfiguration> metadataFields = discoveryConfiguration.getHitHighlightingConfiguration().getMetadataFields();
|
List<DiscoveryHitHighlightFieldConfiguration> metadataFields = discoveryConfiguration.getHitHighlightingConfiguration().getMetadataFields();
|
||||||
for (DiscoveryHitHighlightFieldConfiguration fieldConfiguration : metadataFields) {
|
for (DiscoveryHitHighlightFieldConfiguration fieldConfiguration : metadataFields)
|
||||||
|
{
|
||||||
queryArgs.addHitHighlightingField(new DiscoverHitHighlightingField(fieldConfiguration.getField(), fieldConfiguration.getMaxSize(), fieldConfiguration.getSnippets()));
|
queryArgs.addHitHighlightingField(new DiscoverHitHighlightingField(fieldConfiguration.getField(), fieldConfiguration.getMaxSize(), fieldConfiguration.getSnippets()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -812,150 +828,7 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
this.queryResults = SearchUtils.getSearchService().search(context, scope, queryArgs);
|
this.queryResults = SearchUtils.getSearchService().search(context, scope, queryArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Export the search results as a csv file
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public DSpaceCSV exportMetadata(Context context, Request request, Map objectModel, String query, String scopeString, String filters) throws IOException, UIException, SearchServiceException, SQLException
|
|
||||||
{
|
|
||||||
DiscoverResult qResults = new DiscoverResult();
|
|
||||||
DiscoverQuery qArgs = new DiscoverQuery();
|
|
||||||
|
|
||||||
try {
|
|
||||||
scopeString = scopeString.replace("~", "/");
|
|
||||||
}
|
|
||||||
catch(NullPointerException e) { }
|
|
||||||
|
|
||||||
// Are we in a community or collection?
|
|
||||||
DSpaceObject scope;
|
|
||||||
if (scopeString == null || "".equals(scopeString)) {
|
|
||||||
// get the search scope from the url handle
|
|
||||||
scope = HandleUtil.obtainHandle(objectModel);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Get the search scope from the location parameter
|
|
||||||
scope = HandleManager.resolveToObject(context, scopeString);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> filterQueries = new ArrayList<String>();
|
|
||||||
|
|
||||||
String[] fqs = filters.split(",");
|
|
||||||
|
|
||||||
if (fqs != null) {
|
|
||||||
filterQueries.addAll(Arrays.asList(fqs));
|
|
||||||
}
|
|
||||||
|
|
||||||
qArgs.setMaxResults(getParameterRpp());
|
|
||||||
|
|
||||||
//Add the configured default filter queries
|
|
||||||
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(scope);
|
|
||||||
List<String> defaultFilterQueries = discoveryConfiguration.getDefaultFilterQueries();
|
|
||||||
qArgs.addFilterQueries(defaultFilterQueries.toArray(new String[defaultFilterQueries.size()]));
|
|
||||||
|
|
||||||
if (filterQueries.size() > 0) {
|
|
||||||
qArgs.addFilterQueries(filterQueries.toArray(new String[filterQueries.size()]));
|
|
||||||
}
|
|
||||||
|
|
||||||
String sortBy = ObjectModelHelper.getRequest(objectModel).getParameter("sort_by");
|
|
||||||
DiscoverySortConfiguration searchSortConfiguration = discoveryConfiguration.getSearchSortConfiguration();
|
|
||||||
if(sortBy == null) {
|
|
||||||
//Attempt to find the default one, if none found we use SCORE
|
|
||||||
sortBy = "score";
|
|
||||||
if(searchSortConfiguration != null) {
|
|
||||||
for (DiscoverySortFieldConfiguration sortFieldConfiguration : searchSortConfiguration.getSortFields()) {
|
|
||||||
if(sortFieldConfiguration.equals(searchSortConfiguration.getDefaultSort())) {
|
|
||||||
sortBy = SearchUtils.getSearchService().toSortFieldIndex(sortFieldConfiguration.getMetadataField(), sortFieldConfiguration.getType());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String sortOrder = ObjectModelHelper.getRequest(objectModel).getParameter("order");
|
|
||||||
if(sortOrder == null && searchSortConfiguration != null) {
|
|
||||||
sortOrder = searchSortConfiguration.getDefaultSortOrder().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sortOrder == null || sortOrder.equalsIgnoreCase("DESC")) {
|
|
||||||
qArgs.setSortField(sortBy, DiscoverQuery.SORT_ORDER.desc);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qArgs.setSortField(sortBy, DiscoverQuery.SORT_ORDER.asc);
|
|
||||||
}
|
|
||||||
|
|
||||||
String groupBy = ObjectModelHelper.getRequest(objectModel).getParameter("group_by");
|
|
||||||
|
|
||||||
// Enable groupBy collapsing if designated
|
|
||||||
if (groupBy != null && !groupBy.equalsIgnoreCase("none")) {
|
|
||||||
/** Construct a Collapse Field Query */
|
|
||||||
qArgs.addProperty("collapse.field", groupBy);
|
|
||||||
qArgs.addProperty("collapse.threshold", "1");
|
|
||||||
qArgs.addProperty("collapse.includeCollapsedDocs.fl", "handle");
|
|
||||||
qArgs.addProperty("collapse.facet", "before");
|
|
||||||
|
|
||||||
//queryArgs.a type:Article^2
|
|
||||||
|
|
||||||
// TODO: This is a hack to get Publications (Articles) to always be at the top of Groups.
|
|
||||||
// TODO: I think that can be more transparently done in the solr solrconfig.xml with DISMAX and boosting
|
|
||||||
/** sort in groups to get publications to top */
|
|
||||||
qArgs.setSortField("dc.type", DiscoverQuery.SORT_ORDER.asc);
|
|
||||||
}
|
|
||||||
|
|
||||||
qArgs.setQuery(query != null && !query.trim().equals("") ? query : null);
|
|
||||||
|
|
||||||
qArgs.setStart(0);
|
|
||||||
|
|
||||||
if(discoveryConfiguration.getHitHighlightingConfiguration() != null) {
|
|
||||||
List<DiscoveryHitHighlightFieldConfiguration> metadataFields = discoveryConfiguration.getHitHighlightingConfiguration().getMetadataFields();
|
|
||||||
for (DiscoveryHitHighlightFieldConfiguration fieldConfiguration : metadataFields) {
|
|
||||||
qArgs.addHitHighlightingField(new DiscoverHitHighlightingField(fieldConfiguration.getField(), fieldConfiguration.getMaxSize(), fieldConfiguration.getSnippets()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qArgs.setSpellCheck(discoveryConfiguration.isSpellCheckEnabled());
|
|
||||||
|
|
||||||
qResults = SearchUtils.getSearchService().search(context, scope, qArgs);
|
|
||||||
|
|
||||||
qArgs.setMaxResults(safeLongToInt(qResults.getTotalSearchResults()));
|
|
||||||
|
|
||||||
qResults = SearchUtils.getSearchService().search(context, scope, qArgs);
|
|
||||||
|
|
||||||
Item[] resultsItems;
|
|
||||||
|
|
||||||
// Get a list of found items
|
|
||||||
ArrayList<Item> items = new ArrayList<Item>();
|
|
||||||
for (DSpaceObject resultDSO : qResults.getDspaceObjects()) {
|
|
||||||
if (resultDSO instanceof Item) {
|
|
||||||
items.add((Item) resultDSO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultsItems = new Item[items.size()];
|
|
||||||
resultsItems = items.toArray(resultsItems);
|
|
||||||
|
|
||||||
// Log the attempt
|
|
||||||
log.info(LogManager.getHeader(context, "metadataexport", "exporting_search"));
|
|
||||||
|
|
||||||
// Export a search view
|
|
||||||
ArrayList iids = new ArrayList();
|
|
||||||
for (Item item : items) {
|
|
||||||
iids.add(item.getID());
|
|
||||||
}
|
|
||||||
ItemIterator ii = new ItemIterator(context, iids);
|
|
||||||
MetadataExport exporter = new MetadataExport(context, ii, false);
|
|
||||||
|
|
||||||
// Perform the export
|
|
||||||
DSpaceCSV csv = exporter.export();
|
|
||||||
log.info(LogManager.getHeader(context, "metadataexport", "exported_file:search-results.csv"));
|
|
||||||
|
|
||||||
return csv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int safeLongToInt(long l) {
|
|
||||||
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
|
|
||||||
throw new IllegalArgumentException(l + " cannot be cast to int.");
|
|
||||||
}
|
|
||||||
return (int) l;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of the filter queries for use in rendering pages, creating page more urls, ....
|
* Returns a list of the filter queries for use in rendering pages, creating page more urls, ....
|
||||||
@@ -1069,7 +942,8 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
* @param parameters
|
* @param parameters
|
||||||
* @return The post URL
|
* @return The post URL
|
||||||
*/
|
*/
|
||||||
protected abstract String generateURL(Map<String, String> parameters) throws UIException;
|
protected abstract String generateURL(Map<String, String> parameters)
|
||||||
|
throws UIException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1082,13 +956,17 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
super.recycle();
|
super.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void buildSearchControls(Division div) throws WingException, SQLException
|
|
||||||
{
|
protected void buildSearchControls(Division div)
|
||||||
|
throws WingException, SQLException {
|
||||||
|
|
||||||
|
|
||||||
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
|
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
|
||||||
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(dso);
|
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(dso);
|
||||||
|
|
||||||
Division searchControlsGear = div.addDivision("masked-page-control").addDivision("search-controls-gear", "controls-gear-wrapper");
|
Division searchControlsGear = div.addDivision("masked-page-control").addDivision("search-controls-gear", "controls-gear-wrapper");
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add sort by options, the gear will be rendered by a combination of javascript & css
|
* Add sort by options, the gear will be rendered by a combination of javascript & css
|
||||||
*/
|
*/
|
||||||
@@ -1134,6 +1012,7 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
protected DSpaceObject getScope() throws SQLException {
|
protected DSpaceObject getScope() throws SQLException {
|
||||||
Request request = ObjectModelHelper.getRequest(objectModel);
|
Request request = ObjectModelHelper.getRequest(objectModel);
|
||||||
String scopeString = request.getParameter("scope");
|
String scopeString = request.getParameter("scope");
|
||||||
|
|
||||||
// Are we in a community or collection?
|
// Are we in a community or collection?
|
||||||
DSpaceObject dso;
|
DSpaceObject dso;
|
||||||
if (scopeString == null || "".equals(scopeString))
|
if (scopeString == null || "".equals(scopeString))
|
||||||
@@ -1146,6 +1025,7 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
// Get the search scope from the location parameter
|
// Get the search scope from the location parameter
|
||||||
dso = HandleManager.resolveToObject(context, scopeString);
|
dso = HandleManager.resolveToObject(context, scopeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dso;
|
return dso;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1193,3 +1073,4 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement
|
|||||||
+ countCollections + "," + countItems + ")"));
|
+ countCollections + "," + countItems + ")"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -79,7 +79,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
|
|||||||
*
|
*
|
||||||
* language FIXME: add languages
|
* language FIXME: add languages
|
||||||
*
|
*
|
||||||
* context no context options are added.
|
* context - export metadata if in discover
|
||||||
*
|
*
|
||||||
* action no action options are added.
|
* action no action options are added.
|
||||||
*/
|
*/
|
||||||
@@ -89,6 +89,8 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
|
|||||||
Context context = ContextUtil.obtainContext(objectModel);
|
Context context = ContextUtil.obtainContext(objectModel);
|
||||||
Request request = ObjectModelHelper.getRequest(objectModel);
|
Request request = ObjectModelHelper.getRequest(objectModel);
|
||||||
|
|
||||||
|
// code remnants left behind, probably can be deleted
|
||||||
|
|
||||||
//List test = options.addList("browse");
|
//List test = options.addList("browse");
|
||||||
//List discovery = options.addList("discovery-search");
|
//List discovery = options.addList("discovery-search");
|
||||||
//discovery.setHead("Discovery");
|
//discovery.setHead("Discovery");
|
||||||
@@ -124,15 +126,22 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
|
|||||||
options.addList("account");
|
options.addList("account");
|
||||||
options.addList("administrative");
|
options.addList("administrative");
|
||||||
|
|
||||||
|
// get uri to see if using discovery and if under a specific handle
|
||||||
String uri = request.getSitemapURI();
|
String uri = request.getSitemapURI();
|
||||||
|
|
||||||
|
// check value in dspace.cfg
|
||||||
String search_export_config = ConfigurationManager.getProperty("xmlui.search.metadata_export");
|
String search_export_config = ConfigurationManager.getProperty("xmlui.search.metadata_export");
|
||||||
|
|
||||||
|
// get query
|
||||||
String query = decodeFromURL(request.getParameter("query"));
|
String query = decodeFromURL(request.getParameter("query"));
|
||||||
|
|
||||||
|
// get scope, if not under handle returns null
|
||||||
String scope= request.getParameter("scope");
|
String scope= request.getParameter("scope");
|
||||||
|
|
||||||
|
// used to serialize all query filters together
|
||||||
String filters = "";
|
String filters = "";
|
||||||
|
|
||||||
|
// get all query filters
|
||||||
String[] fqs = DiscoveryUIUtils.getFilterQueries(ObjectModelHelper.getRequest(objectModel), context);
|
String[] fqs = DiscoveryUIUtils.getFilterQueries(ObjectModelHelper.getRequest(objectModel), context);
|
||||||
|
|
||||||
if (fqs != null)
|
if (fqs != null)
|
||||||
@@ -146,28 +155,29 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(uri.contains("discover")) {
|
if(uri.contains("discover")) {
|
||||||
|
// check scope
|
||||||
if(scope == null || "".equals(scope))
|
if(scope == null || "".equals(scope))
|
||||||
scope = "/";
|
scope = "/";
|
||||||
|
// check query
|
||||||
if(query == null || "".equals(query))
|
if(query == null || "".equals(query))
|
||||||
query = "*";
|
query = "*";
|
||||||
|
// check if under a handle, already in discovery
|
||||||
if(uri.contains("handle")) {
|
if(uri.contains("handle")) {
|
||||||
scope = uri.replace("handle/", "").replace("/discover", "");
|
scope = uri.replace("handle/", "").replace("/discover", "");
|
||||||
}
|
}
|
||||||
|
// replace forward slash to pass through sitemap
|
||||||
try {
|
try {
|
||||||
scope = scope.replace("/", "~");
|
scope = scope.replace("/", "~");
|
||||||
}
|
}
|
||||||
catch(NullPointerException e) { }
|
catch(NullPointerException e) { }
|
||||||
if(search_export_config != null) {
|
if(search_export_config != null) {
|
||||||
|
// some logging
|
||||||
if(false) {
|
if(true) {
|
||||||
log.warn("**************************************");
|
log.info("uri: " + uri);
|
||||||
log.warn("uri: " + uri);
|
log.info("query: " + query);
|
||||||
log.warn("query: " + query);
|
log.info("scope: " + scope);
|
||||||
log.warn("scope: " + scope);
|
log.info("filters: " + filters);
|
||||||
log.warn("filters: " + filters);
|
|
||||||
log.warn("**************************************");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(search_export_config.equals("admin")) {
|
if(search_export_config.equals("admin")) {
|
||||||
if(AuthorizeManager.isAdmin(context)) {
|
if(AuthorizeManager.isAdmin(context)) {
|
||||||
List results = options.addList("context");
|
List results = options.addList("context");
|
||||||
|
@@ -17,6 +17,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import org.apache.avalon.excalibur.pool.Recyclable;
|
import org.apache.avalon.excalibur.pool.Recyclable;
|
||||||
import org.apache.avalon.framework.parameters.Parameters;
|
import org.apache.avalon.framework.parameters.Parameters;
|
||||||
import org.apache.cocoon.ProcessingException;
|
import org.apache.cocoon.ProcessingException;
|
||||||
@@ -29,17 +31,13 @@ import org.apache.cocoon.reading.AbstractReader;
|
|||||||
|
|
||||||
import org.dspace.app.bulkedit.DSpaceCSV;
|
import org.dspace.app.bulkedit.DSpaceCSV;
|
||||||
import org.dspace.app.bulkedit.MetadataExport;
|
import org.dspace.app.bulkedit.MetadataExport;
|
||||||
|
|
||||||
import org.dspace.app.xmlui.wing.WingException;
|
import org.dspace.app.xmlui.wing.WingException;
|
||||||
import org.dspace.app.xmlui.wing.element.Body;
|
import org.dspace.app.xmlui.wing.element.Body;
|
||||||
import org.dspace.app.xmlui.utils.UIException;
|
import org.dspace.app.xmlui.utils.UIException;
|
||||||
import org.dspace.app.xmlui.utils.AuthenticationUtil;
|
import org.dspace.app.xmlui.utils.AuthenticationUtil;
|
||||||
import org.dspace.app.xmlui.utils.ContextUtil;
|
import org.dspace.app.xmlui.utils.ContextUtil;
|
||||||
|
import org.dspace.app.xmlui.utils.HandleUtil;
|
||||||
import org.dspace.app.xmlui.aspect.discovery.AbstractSearch;
|
import org.dspace.app.xmlui.aspect.discovery.AbstractSearch;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.authorize.AuthorizeManager;
|
import org.dspace.authorize.AuthorizeManager;
|
||||||
import org.dspace.handle.HandleManager;
|
import org.dspace.handle.HandleManager;
|
||||||
@@ -47,15 +45,21 @@ import org.dspace.core.Context;
|
|||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.LogManager;
|
import org.dspace.core.LogManager;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
|
import org.dspace.content.*;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Community;
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.content.ItemIterator;
|
import org.dspace.content.ItemIterator;
|
||||||
|
import org.dspace.discovery.*;
|
||||||
|
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||||
|
import org.dspace.discovery.configuration.DiscoveryHitHighlightFieldConfiguration;
|
||||||
|
import org.dspace.discovery.configuration.DiscoverySortConfiguration;
|
||||||
|
import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* AbstractReader that generates a CSV of search
|
* SearchMetadataExportReader that generates a CSV of search
|
||||||
* result metadata using MetadataExport
|
* result metadata using MetadataExport
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -114,15 +118,13 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl
|
|||||||
String scope = par.getParameter("scope");
|
String scope = par.getParameter("scope");
|
||||||
String filters = par.getParameter("filters");
|
String filters = par.getParameter("filters");
|
||||||
|
|
||||||
ExportSearch exportSearch = new ExportSearch();
|
|
||||||
|
|
||||||
Context context = ContextUtil.obtainContext(objectModel);
|
Context context = ContextUtil.obtainContext(objectModel);
|
||||||
|
|
||||||
String search_export_config = ConfigurationManager.getProperty("xmlui.search.metadata_export");
|
String search_export_config = ConfigurationManager.getProperty("xmlui.search.metadata_export");
|
||||||
|
|
||||||
if(search_export_config.equals("admin")) {
|
if(search_export_config.equals("admin")) {
|
||||||
if(AuthorizeManager.isAdmin(context)) {
|
if(AuthorizeManager.isAdmin(context)) {
|
||||||
csv = exportSearch.exportMetadata(context, this.request, objectModel, query, scope, filters);
|
csv = exportMetadata(context, objectModel, query, scope, filters);
|
||||||
filename = "search-results.csv";
|
filename = "search-results.csv";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -148,7 +150,7 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl
|
|||||||
}
|
}
|
||||||
else if(search_export_config.equals("user")) {
|
else if(search_export_config.equals("user")) {
|
||||||
if(AuthenticationUtil.isLoggedIn(request)) {
|
if(AuthenticationUtil.isLoggedIn(request)) {
|
||||||
csv = exportSearch.exportMetadata(context, this.request, objectModel, query, scope, filters);
|
csv = exportMetadata(context, objectModel, query, scope, filters);
|
||||||
filename = "search-results.csv";
|
filename = "search-results.csv";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -160,7 +162,7 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(search_export_config.equals("anonymous")) {
|
else if(search_export_config.equals("anonymous")) {
|
||||||
csv = exportSearch.exportMetadata(context, this.request, objectModel, query, scope, filters);
|
csv = exportMetadata(context, objectModel, query, scope, filters);
|
||||||
filename = "search-results.csv";
|
filename = "search-results.csv";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,13 +196,172 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl
|
|||||||
this.response = null;
|
this.response = null;
|
||||||
this.request = null;
|
this.request = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class ExportSearch extends AbstractSearch
|
/**
|
||||||
{
|
* Save and return the search results as a csv file
|
||||||
public ExportSearch() {}
|
*
|
||||||
protected String getQuery() throws UIException { return null; }
|
* @params context, objectModel, query, scopeString, filters
|
||||||
protected String getBasicUrl() throws SQLException { return null; }
|
*
|
||||||
protected String generateURL(Map<String, String> parameters) throws UIException { return null; }
|
* @throws IOException, UIException, SearchServiceException, SQLException
|
||||||
public void addBody(Body body) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException {}
|
*/
|
||||||
|
public DSpaceCSV exportMetadata(Context context, Map objectModel, String query, String scopeString, String filters) throws IOException, UIException, SearchServiceException, SQLException
|
||||||
|
{
|
||||||
|
DiscoverResult qResults = new DiscoverResult();
|
||||||
|
DiscoverQuery qArgs = new DiscoverQuery();
|
||||||
|
|
||||||
|
try {
|
||||||
|
scopeString = scopeString.replace("~", "/");
|
||||||
|
}
|
||||||
|
catch(NullPointerException e) { }
|
||||||
|
|
||||||
|
// Are we in a community or collection?
|
||||||
|
DSpaceObject scope;
|
||||||
|
if (scopeString == null || "".equals(scopeString)) {
|
||||||
|
// get the search scope from the url handle
|
||||||
|
scope = HandleUtil.obtainHandle(objectModel);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Get the search scope from the location parameter
|
||||||
|
scope = HandleManager.resolveToObject(context, scopeString);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> filterQueries = new ArrayList<String>();
|
||||||
|
|
||||||
|
String[] fqs = filters.split(",");
|
||||||
|
|
||||||
|
if (fqs != null) {
|
||||||
|
filterQueries.addAll(Arrays.asList(fqs));
|
||||||
|
}
|
||||||
|
|
||||||
|
// some arbitrary value for first search
|
||||||
|
qArgs.setMaxResults(10);
|
||||||
|
|
||||||
|
//Add the configured default filter queries
|
||||||
|
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(scope);
|
||||||
|
List<String> defaultFilterQueries = discoveryConfiguration.getDefaultFilterQueries();
|
||||||
|
qArgs.addFilterQueries(defaultFilterQueries.toArray(new String[defaultFilterQueries.size()]));
|
||||||
|
|
||||||
|
if (filterQueries.size() > 0) {
|
||||||
|
qArgs.addFilterQueries(filterQueries.toArray(new String[filterQueries.size()]));
|
||||||
|
}
|
||||||
|
|
||||||
|
String sortBy = ObjectModelHelper.getRequest(objectModel).getParameter("sort_by");
|
||||||
|
DiscoverySortConfiguration searchSortConfiguration = discoveryConfiguration.getSearchSortConfiguration();
|
||||||
|
if(sortBy == null) {
|
||||||
|
//Attempt to find the default one, if none found we use SCORE
|
||||||
|
sortBy = "score";
|
||||||
|
if(searchSortConfiguration != null) {
|
||||||
|
for (DiscoverySortFieldConfiguration sortFieldConfiguration : searchSortConfiguration.getSortFields()) {
|
||||||
|
if(sortFieldConfiguration.equals(searchSortConfiguration.getDefaultSort())) {
|
||||||
|
sortBy = SearchUtils.getSearchService().toSortFieldIndex(sortFieldConfiguration.getMetadataField(), sortFieldConfiguration.getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String sortOrder = ObjectModelHelper.getRequest(objectModel).getParameter("order");
|
||||||
|
if(sortOrder == null && searchSortConfiguration != null) {
|
||||||
|
sortOrder = searchSortConfiguration.getDefaultSortOrder().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sortOrder == null || sortOrder.equalsIgnoreCase("DESC")) {
|
||||||
|
qArgs.setSortField(sortBy, DiscoverQuery.SORT_ORDER.desc);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qArgs.setSortField(sortBy, DiscoverQuery.SORT_ORDER.asc);
|
||||||
|
}
|
||||||
|
|
||||||
|
String groupBy = ObjectModelHelper.getRequest(objectModel).getParameter("group_by");
|
||||||
|
|
||||||
|
// Enable groupBy collapsing if designated
|
||||||
|
if (groupBy != null && !groupBy.equalsIgnoreCase("none")) {
|
||||||
|
/** Construct a Collapse Field Query */
|
||||||
|
qArgs.addProperty("collapse.field", groupBy);
|
||||||
|
qArgs.addProperty("collapse.threshold", "1");
|
||||||
|
qArgs.addProperty("collapse.includeCollapsedDocs.fl", "handle");
|
||||||
|
qArgs.addProperty("collapse.facet", "before");
|
||||||
|
|
||||||
|
//queryArgs.a type:Article^2
|
||||||
|
|
||||||
|
// TODO: This is a hack to get Publications (Articles) to always be at the top of Groups.
|
||||||
|
// TODO: I think that can be more transparently done in the solr solrconfig.xml with DISMAX and boosting
|
||||||
|
/** sort in groups to get publications to top */
|
||||||
|
qArgs.setSortField("dc.type", DiscoverQuery.SORT_ORDER.asc);
|
||||||
|
}
|
||||||
|
|
||||||
|
qArgs.setQuery(query != null && !query.trim().equals("") ? query : null);
|
||||||
|
|
||||||
|
// no paging required
|
||||||
|
qArgs.setStart(0);
|
||||||
|
|
||||||
|
if(discoveryConfiguration.getHitHighlightingConfiguration() != null) {
|
||||||
|
List<DiscoveryHitHighlightFieldConfiguration> metadataFields = discoveryConfiguration.getHitHighlightingConfiguration().getMetadataFields();
|
||||||
|
for (DiscoveryHitHighlightFieldConfiguration fieldConfiguration : metadataFields) {
|
||||||
|
qArgs.addHitHighlightingField(new DiscoverHitHighlightingField(fieldConfiguration.getField(), fieldConfiguration.getMaxSize(), fieldConfiguration.getSnippets()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qArgs.setSpellCheck(discoveryConfiguration.isSpellCheckEnabled());
|
||||||
|
|
||||||
|
// search once to get total search results
|
||||||
|
qResults = SearchUtils.getSearchService().search(context, scope, qArgs);
|
||||||
|
|
||||||
|
// set max results to total search results
|
||||||
|
qArgs.setMaxResults(safeLongToInt(qResults.getTotalSearchResults()));
|
||||||
|
|
||||||
|
// search again to return all search results
|
||||||
|
qResults = SearchUtils.getSearchService().search(context, scope, qArgs);
|
||||||
|
|
||||||
|
Item[] resultsItems;
|
||||||
|
|
||||||
|
// Get a list of found items
|
||||||
|
ArrayList<Item> items = new ArrayList<Item>();
|
||||||
|
for (DSpaceObject resultDSO : qResults.getDspaceObjects()) {
|
||||||
|
if (resultDSO instanceof Item) {
|
||||||
|
items.add((Item) resultDSO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultsItems = new Item[items.size()];
|
||||||
|
resultsItems = items.toArray(resultsItems);
|
||||||
|
|
||||||
|
// Log the attempt
|
||||||
|
log.info(LogManager.getHeader(context, "metadataexport", "exporting_search"));
|
||||||
|
|
||||||
|
// Export a search view
|
||||||
|
ArrayList iids = new ArrayList();
|
||||||
|
for (Item item : items) {
|
||||||
|
iids.add(item.getID());
|
||||||
|
}
|
||||||
|
ItemIterator ii = new ItemIterator(context, iids);
|
||||||
|
MetadataExport exporter = new MetadataExport(context, ii, false);
|
||||||
|
|
||||||
|
// Perform the export
|
||||||
|
DSpaceCSV csv = exporter.export();
|
||||||
|
log.info(LogManager.getHeader(context, "metadataexport", "exported_file:search-results.csv"));
|
||||||
|
|
||||||
|
return csv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int safeLongToInt(long l) {
|
||||||
|
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
|
||||||
|
throw new IllegalArgumentException(l + " cannot be cast to int.");
|
||||||
|
}
|
||||||
|
return (int) l;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of the filter queries for use in rendering pages, creating page more urls, ....
|
||||||
|
* @return an array containing the filter queries
|
||||||
|
*/
|
||||||
|
protected Map<String, String[]> getParameterFilterQueries()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Map<String, String[]> result = new HashMap<String, String[]>();
|
||||||
|
result.put("fq", ObjectModelHelper.getRequest(objectModel).getParameterValues("fq"));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -2064,7 +2064,7 @@ mirage2.item-view.bitstream.href.label.2 = title
|
|||||||
# records the original IP address.
|
# records the original IP address.
|
||||||
#xmlui.controlpanel.activity.ipheader = X-Forward-For
|
#xmlui.controlpanel.activity.ipheader = X-Forward-For
|
||||||
|
|
||||||
xmlui.search.metadata_export = anonymous
|
xmlui.search.metadata_export = admin
|
||||||
|
|
||||||
#---------------------------------------------------------------#
|
#---------------------------------------------------------------#
|
||||||
#----------------REQUEST ITEM CONFIGURATION---------------------#
|
#----------------REQUEST ITEM CONFIGURATION---------------------#
|
||||||
|
Reference in New Issue
Block a user