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:
Graham Triggs
2008-01-13 19:19:19 +00:00
parent 654462dbe0
commit a2f335d697
2 changed files with 83 additions and 55 deletions

View File

@@ -165,14 +165,24 @@ public class DSQuery
Query myquery = qp.parse(querystring);
Hits hits = null;
if (args.getSortOption() == null)
try
{
hits = searcher.search(myquery, new Sort(new SortField[] { new SortField("type"), SortField.FIELD_SCORE }));
if (args.getSortOption() == null)
{
hits = searcher.search(myquery, new Sort(new SortField[] { new SortField("type"), SortField.FIELD_SCORE }));
}
else
{
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));
}
}
else
catch (Exception e)
{
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));
// 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