Skip to content

Commit

Permalink
DS-402 Performance and UI improvements for itemmap
Browse files Browse the repository at this point in the history
This commit remove hardcoded reference to the author index for both discovery
and lucene provider. The admin is now able to perform a generic search or choose
from one of the customized indices or filters.
A very simple pagination, only next and previous buttons, has been introduced to
avoid performance issues with large result set.
Finally has been introduced optimization to perform the "Not owning collection"
check and, limitly to discovery, authorization check directly as part of the
search.
  • Loading branch information
Andrea Bollini committed Aug 18, 2013
1 parent b94dc47 commit 9aeafac
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 45 deletions.
12 changes: 8 additions & 4 deletions dspace-api/src/main/resources/Messages.properties
Expand Up @@ -847,6 +847,7 @@ jsp.search.filter.heading = Add filters:
jsp.search.filter.hint = Use filters to refine the search results.
jsp.search.filter.add = Add
jsp.search.filter.applied = Current filters:
jsp.search.filter.any = Any fields
jsp.search.filter.title = Title
jsp.search.filter.author = Author
jsp.search.filter.subject = Subject
Expand Down Expand Up @@ -1305,7 +1306,7 @@ jsp.tools.group-select-list.th.name = Name
jsp.tools.group-select-list.th.name.sortedby = Name ↑
jsp.tools.group-select-list.title = Select Groups
jsp.tools.itemmap-browse.add = Check the box next to items you wish to add to {0}, and choose ''Add''.
jsp.tools.itemmap-browse.heading-authors = Browse Items matching author ''{0}''
jsp.tools.itemmap-browse.heading-search = Browse Items matching query: ''{0}''
jsp.tools.itemmap-browse.heading-collection = Items Mapped to Collection {1} from Collection {0}
jsp.tools.itemmap-browse.remove = Check the box next to items you wish to unmap from {0}, and choose ''Remove''.
jsp.tools.itemmap-browse.th.action = Action
Expand All @@ -1314,6 +1315,9 @@ jsp.tools.itemmap-browse.th.date = Date
jsp.tools.itemmap-browse.th.remove = Unmap
jsp.tools.itemmap-browse.th.title = Title
jsp.tools.itemmap-browse.title = Browse Items
jsp.tools.itemmap-browse.info.change-page = Your query return lot of results. You can navigate your result with the following buttons. Please note that checked items will be mapped only clicking on the Add button.
jsp.tools.itemmap-browse.previous.button = Previous page
jsp.tools.itemmap-browse.next.button = Next page
jsp.tools.itemmap-info.button.continue = Continue
jsp.tools.itemmap-info.heading = Item Map Info
jsp.tools.itemmap-info.msg.added = Add item {0}
Expand All @@ -1325,12 +1329,12 @@ jsp.tools.itemmap-info.title = Item Map Info
jsp.tools.itemmap-main.collection = Collection: "{0}"
jsp.tools.itemmap-main.heading = Item Mapper - Map Items from Other Collections
jsp.tools.itemmap-main.info1 = There are {0} items owned by this collection, and {1} items mapped in from other collections.
jsp.tools.itemmap-main.info4 = Import By Author Match
jsp.tools.itemmap-main.info5 = Enter part of an author's name for a list of matching items
jsp.tools.itemmap-main.info4 = Import By Search
jsp.tools.itemmap-main.info5 = Enter a search query for a list of matching items
jsp.tools.itemmap-main.info6 = Browse Items Imported From Collections:
jsp.tools.itemmap-main.info7 = Click on collection names to browse for items to remove that were mapped in from that collection.
jsp.tools.itemmap-main.info8 = This collection has no items mapped into it.
jsp.tools.itemmap-main.search.button = Search Authors
jsp.tools.itemmap-main.search.button = Search
jsp.tools.itemmap-main.title = Item Mapper
jsp.tools.move-item.button = Move
jsp.tools.move-item.collection.from.msg = Collection to move from
Expand Down
Expand Up @@ -25,6 +25,7 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.dspace.app.bulkedit.DSpaceCSV;
import org.dspace.app.bulkedit.MetadataExport;
Expand Down Expand Up @@ -57,6 +58,8 @@

public class DiscoverySearchRequestProcessor implements SearchRequestProcessor
{
private static final int ITEMMAP_RESULT_PAGE_SIZE = 50;

private static String msgKey = "org.dspace.app.webui.servlet.FeedServlet";

/** log4j category */
Expand All @@ -65,12 +68,26 @@ public class DiscoverySearchRequestProcessor implements SearchRequestProcessor
// locale-sensitive metadata labels
private Map<String, Map<String, String>> localeLabels = null;

private List<String> searchIndices = null;

public synchronized void init()
{
if (localeLabels == null)
{
localeLabels = new HashMap<String, Map<String, String>>();
}

if (searchIndices == null)
{
searchIndices = new ArrayList<String>();
DiscoveryConfiguration discoveryConfiguration = SearchUtils
.getDiscoveryConfiguration();
searchIndices.add("any");
for (DiscoverySearchFilter sFilter : discoveryConfiguration.getSearchFilters())
{
searchIndices.add(sFilter.getIndexFieldName());
}
}
}

public void doOpenSearch(Context context, HttpServletRequest request,
Expand Down Expand Up @@ -490,12 +507,20 @@ public void doAdvancedSearch(Context context, HttpServletRequest request,
public void doItemMapSearch(Context context, HttpServletRequest request,
HttpServletResponse response) throws SearchProcessorException, ServletException, IOException
{
String name = (String) request.getParameter("namepart");
String queryString = (String) request.getParameter("query");
Collection collection = (Collection) request.getAttribute("collection");

int page = UIUtil.getIntParameter(request, "page")-1;
int offset = page > 0? page * ITEMMAP_RESULT_PAGE_SIZE:0;
String idx = (String) request.getParameter("index");
if (StringUtils.isNotBlank(idx) && !idx.equalsIgnoreCase("any"))
{
queryString = idx + ":(" + queryString + ")";
}
DiscoverQuery query = new DiscoverQuery();
query.setQuery("author:"+name);
query.setMaxResults(Integer.MAX_VALUE);
query.setQuery(queryString);
query.addFilterQueries("-location:l"+collection.getID());
query.setMaxResults(ITEMMAP_RESULT_PAGE_SIZE);
query.setStart(offset);

DiscoverResult results = null;
try
Expand All @@ -510,33 +535,35 @@ public void doItemMapSearch(Context context, HttpServletRequest request,
Map<Integer, Item> items = new HashMap<Integer, Item>();

List<DSpaceObject> resultDSOs = results.getDspaceObjects();
try
for (DSpaceObject dso : resultDSOs)
{
for (DSpaceObject dso : resultDSOs)
if (dso != null && dso.getType() == Constants.ITEM)
{
if (dso.getType() == Constants.ITEM)
{
Item item = (Item) dso;
if (item.isOwningCollection(collection) || item.isIn(collection))
{
continue;
}
if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.READ))
{
items.put(Integer.valueOf(item.getID()), item);
}
}
// no authorization check is required as discovery is right aware
Item item = (Item) dso;
items.put(Integer.valueOf(item.getID()), item);
}
}
catch (SQLException e)
{
throw new SearchProcessorException(e.getMessage(), e);
}

request.setAttribute("browsetext", name);
request.setAttribute("browsetext", queryString);
request.setAttribute("items", items);
request.setAttribute("more", results.getTotalSearchResults() > offset + ITEMMAP_RESULT_PAGE_SIZE);
request.setAttribute("browsetype", "Add");
request.setAttribute("page", page > 0 ? page + 1 : 1);

JSPManager.showJSP(request, response, "itemmap-browse.jsp");
}

@Override
public String getI18NKeyPrefix()
{
return "jsp.search.filter.";
}

@Override
public List<String> getSearchIndices()
{
init();
return searchIndices;
}
}
Expand Up @@ -38,6 +38,7 @@
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.ItemIterator;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.I18nUtil;
Expand All @@ -54,6 +55,8 @@

public class LuceneSearchRequestProcessor implements SearchRequestProcessor
{
private static final int ITEMMAP_RESULT_PAGE_SIZE = 50;

/** log4j category */
private static Logger log = Logger.getLogger(SimpleSearchServlet.class);

Expand All @@ -62,12 +65,42 @@ public class LuceneSearchRequestProcessor implements SearchRequestProcessor

private static String msgKey = "org.dspace.app.webui.servlet.FeedServlet";

private List<String> searchIndices = null;

public synchronized void init()
{
if (localeLabels == null)
{
localeLabels = new HashMap<String, Map<String, String>>();
}

if (searchIndices == null)
{
searchIndices = new ArrayList<String>();
String definition;

int idx = 1;

while ( ((definition = ConfigurationManager.getProperty("jspui.search.index.display." + idx))) != null){
String index = definition;
searchIndices.add(index);
idx++;
}

// backward compatibility
if (searchIndices.size() == 0)
{
searchIndices.add("ANY");
searchIndices.add("author");
searchIndices.add("title");
searchIndices.add("keyword");
searchIndices.add("abstract");
searchIndices.add("series");
searchIndices.add("sponsor");
searchIndices.add("identifier");
searchIndices.add("language");
}
}
}

/**
Expand Down Expand Up @@ -676,12 +709,19 @@ else if (container instanceof Community)
public void doItemMapSearch(Context context, HttpServletRequest request,
HttpServletResponse response) throws SearchProcessorException, ServletException, IOException
{
String name = (String) request.getParameter("namepart");
String query = (String) request.getParameter("query");
int page = UIUtil.getIntParameter(request, "page")-1;
int offset = page > 0? page * ITEMMAP_RESULT_PAGE_SIZE:0;
Collection collection = (Collection) request.getAttribute("collection");

String idx = (String) request.getParameter("index");
if (StringUtils.isNotBlank(idx) && !idx.equalsIgnoreCase("any"))
{
query = idx + ":(" + query + ")";
}
QueryArgs queryArgs = new QueryArgs();
queryArgs.setQuery("author:"+name);
queryArgs.setPageSize(Integer.MAX_VALUE);
queryArgs.setQuery(query + " -location:l" + collection.getID());
queryArgs.setPageSize(ITEMMAP_RESULT_PAGE_SIZE);
queryArgs.setStart(offset);
QueryResults results = DSQuery.doQuery(context, queryArgs);

Map<Integer, Item> items = new HashMap<Integer, Item>();
Expand All @@ -695,10 +735,6 @@ public void doItemMapSearch(Context context, HttpServletRequest request,
if (resultDSO.getType() == Constants.ITEM)
{
Item item = (Item) resultDSO;
if (item.isOwningCollection(collection) || item.isIn(collection))
{
continue;
}
if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.READ))
{
items.put(Integer.valueOf(item.getID()), item);
Expand All @@ -711,9 +747,11 @@ public void doItemMapSearch(Context context, HttpServletRequest request,
throw new SearchProcessorException(e.getMessage(), e);
}

request.setAttribute("browsetext", name);
request.setAttribute("browsetext", query);
request.setAttribute("items", items);
request.setAttribute("more", results.getHitCount() > offset + ITEMMAP_RESULT_PAGE_SIZE);
request.setAttribute("browsetype", "Add");
request.setAttribute("page", page > 0 ? page + 1 : 1);

JSPManager.showJSP(request, response, "itemmap-browse.jsp");
}
Expand Down Expand Up @@ -782,4 +820,17 @@ private Map<String, String> getLocaleLabels(Locale locale)
}
return labelMap;
}

@Override
public String getI18NKeyPrefix()
{
return "jsp.search.advanced.type.";
}

@Override
public List<String> getSearchIndices()
{
init();
return searchIndices;
}
}
Expand Up @@ -8,6 +8,7 @@
package org.dspace.app.webui.search;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -32,5 +33,9 @@ public void doOpenSearch(Context context, HttpServletRequest request,
public void doItemMapSearch(Context context, HttpServletRequest request,
HttpServletResponse response) throws SearchProcessorException,
IOException, ServletException;

public List<String> getSearchIndices();

public String getI18NKeyPrefix();

}
Expand Up @@ -191,6 +191,9 @@ protected void doDSPost(Context context, HttpServletRequest request,
.setAttribute("all_collections", Collection
.findAll(context));

request.setAttribute("searchIndices",
internalLogic.getSearchIndices());
request.setAttribute("prefixKey", internalLogic.getI18NKeyPrefix());
// show this page when we're done
jspPage = "itemmap-main.jsp";

Expand Down Expand Up @@ -297,7 +300,7 @@ else if (action.equals("Add"))
// show the page
JSPManager.showJSP(request, response, jspPage);
}
else if (action.equals("Search Authors"))
else if (action.equals("search"))
{
request.setAttribute("collection", myCollection);
try
Expand All @@ -306,6 +309,7 @@ else if (action.equals("Search Authors"))
}
catch (SearchProcessorException e)
{
log.error(e.getMessage(), e);
throw new ServletException(e.getMessage(), e);
}
}
Expand Down

0 comments on commit 9aeafac

Please sign in to comment.