mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Improved resilience of query object when index is lacking necessary information, improve efficiency of search results by not using handles if the resource ID is available
git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@2521 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -165,6 +165,8 @@ public class DSQuery
|
||||
Query myquery = qp.parse(querystring);
|
||||
Hits hits = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (args.getSortOption() == null)
|
||||
{
|
||||
hits = searcher.search(myquery, new Sort(new SortField[] { new SortField("type"), SortField.FIELD_SCORE }));
|
||||
@@ -174,6 +176,14 @@ public class DSQuery
|
||||
SortField[] sortFields = new SortField[] { new SortField("type"), new SortField("sort_" + args.getSortOption().getName(), SortOption.DESCENDING.equals(args.getSortOrder())), SortField.FIELD_SCORE };
|
||||
hits = searcher.search(myquery, new Sort(sortFields));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Lucene can throw an exception if it is unable to determine a sort time from the specified field
|
||||
// Provide a fall back that just works on relevancy.
|
||||
log.error("Unable to use speficied sort option: " + (args.getSortOption() == null ? "type/relevance": args.getSortOption().getName()));
|
||||
hits = searcher.search(myquery, new Sort(SortField.FIELD_SCORE));
|
||||
}
|
||||
|
||||
// set total number of hits
|
||||
qr.setHitCount(hits.length());
|
||||
|
@@ -109,9 +109,9 @@ public class SimpleSearchServlet extends DSpaceServlet
|
||||
start = 0;
|
||||
}
|
||||
|
||||
List itemHandles = new ArrayList();
|
||||
List collectionHandles = new ArrayList();
|
||||
List communityHandles = new ArrayList();
|
||||
int collCount = 0;
|
||||
int commCount = 0;
|
||||
int itemCount = 0;
|
||||
|
||||
Item[] resultsItems;
|
||||
Collection[] resultsCollections;
|
||||
@@ -228,8 +228,39 @@ public class SimpleSearchServlet extends DSpaceServlet
|
||||
}
|
||||
|
||||
// now instantiate the results and put them in their buckets
|
||||
for (int i = 0; i < qResults.getHitHandles().size(); i++)
|
||||
for (int i = 0; i < qResults.getHitTypes().size(); i++)
|
||||
{
|
||||
Integer myType = (Integer) qResults.getHitTypes().get(i);
|
||||
|
||||
// add the handle to the appropriate lists
|
||||
switch (myType.intValue())
|
||||
{
|
||||
case Constants.ITEM:
|
||||
itemCount++;
|
||||
break;
|
||||
|
||||
case Constants.COLLECTION:
|
||||
collCount++;
|
||||
break;
|
||||
|
||||
case Constants.COMMUNITY:
|
||||
commCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Make objects from the handles - make arrays, fill them out
|
||||
resultsCommunities = new Community[commCount];
|
||||
resultsCollections = new Collection[collCount];
|
||||
resultsItems = new Item[itemCount];
|
||||
|
||||
collCount = 0;
|
||||
commCount = 0;
|
||||
itemCount = 0;
|
||||
|
||||
for (int i = 0; i < qResults.getHitTypes().size(); i++)
|
||||
{
|
||||
Integer myId = (Integer) qResults.getHitIds().get(i);
|
||||
String myHandle = (String) qResults.getHitHandles().get(i);
|
||||
Integer myType = (Integer) qResults.getHitTypes().get(i);
|
||||
|
||||
@@ -237,76 +268,63 @@ public class SimpleSearchServlet extends DSpaceServlet
|
||||
switch (myType.intValue())
|
||||
{
|
||||
case Constants.ITEM:
|
||||
itemHandles.add(myHandle);
|
||||
if (myId != null)
|
||||
{
|
||||
resultsItems[itemCount] = Item.find(context, myId);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultsItems[itemCount] = (Item)HandleManager.resolveToObject(context, myHandle);
|
||||
}
|
||||
|
||||
if (resultsItems[itemCount] == null)
|
||||
{
|
||||
throw new SQLException("Query \"" + query
|
||||
+ "\" returned unresolvable item");
|
||||
}
|
||||
itemCount++;
|
||||
break;
|
||||
|
||||
case Constants.COLLECTION:
|
||||
collectionHandles.add(myHandle);
|
||||
if (myId != null)
|
||||
{
|
||||
resultsCollections[collCount] = Collection.find(context, myId);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultsCollections[collCount] = (Collection)HandleManager.resolveToObject(context, myHandle);
|
||||
}
|
||||
|
||||
if (resultsCollections[collCount] == null)
|
||||
{
|
||||
throw new SQLException("Query \"" + query
|
||||
+ "\" returned unresolvable collection");
|
||||
}
|
||||
|
||||
collCount++;
|
||||
break;
|
||||
|
||||
case Constants.COMMUNITY:
|
||||
communityHandles.add(myHandle);
|
||||
if (myId != null)
|
||||
{
|
||||
resultsCommunities[commCount] = Community.find(context, myId);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultsCommunities[commCount] = (Community)HandleManager.resolveToObject(context, myHandle);
|
||||
}
|
||||
|
||||
if (resultsCommunities[commCount] == null)
|
||||
{
|
||||
throw new SQLException("Query \"" + query
|
||||
+ "\" returned unresolvable community");
|
||||
}
|
||||
|
||||
commCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int numCommunities = communityHandles.size();
|
||||
int numCollections = collectionHandles.size();
|
||||
int numItems = itemHandles.size();
|
||||
|
||||
// Make objects from the handles - make arrays, fill them out
|
||||
resultsCommunities = new Community[numCommunities];
|
||||
resultsCollections = new Collection[numCollections];
|
||||
resultsItems = new Item[numItems];
|
||||
|
||||
for (int i = 0; i < numItems; i++)
|
||||
{
|
||||
String myhandle = (String) itemHandles.get(i);
|
||||
|
||||
Object o = HandleManager.resolveToObject(context, myhandle);
|
||||
|
||||
resultsItems[i] = (Item) o;
|
||||
|
||||
if (resultsItems[i] == null)
|
||||
{
|
||||
throw new SQLException("Query \"" + query
|
||||
+ "\" returned unresolvable handle: " + myhandle);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < collectionHandles.size(); i++)
|
||||
{
|
||||
String myhandle = (String) collectionHandles.get(i);
|
||||
|
||||
Object o = HandleManager.resolveToObject(context, myhandle);
|
||||
|
||||
resultsCollections[i] = (Collection) o;
|
||||
|
||||
if (resultsCollections[i] == null)
|
||||
{
|
||||
throw new SQLException("Query \"" + query
|
||||
+ "\" returned unresolvable handle: " + myhandle);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < communityHandles.size(); i++)
|
||||
{
|
||||
String myhandle = (String) communityHandles.get(i);
|
||||
|
||||
Object o = HandleManager.resolveToObject(context, myhandle);
|
||||
|
||||
resultsCommunities[i] = (Community) o;
|
||||
|
||||
if (resultsCommunities[i] == null)
|
||||
{
|
||||
throw new SQLException("Query \"" + query
|
||||
+ "\" returned unresolvable handle: " + myhandle);
|
||||
}
|
||||
}
|
||||
|
||||
// Log
|
||||
log.info(LogManager.getHeader(context, "search", logInfo + "query=\""
|
||||
+ query + "\",results=(" + resultsCommunities.length + ","
|
||||
|
Reference in New Issue
Block a user