Merge pull request #1201 from sidheshenator/keywordsearch_output_consistency

Get consistent snippets across multiple runs
This commit is contained in:
Richard Cordovano 2015-04-20 13:13:43 -04:00
commit 351bc652d9

View File

@ -268,11 +268,7 @@ class LuceneQuery implements KeywordSearchQuery {
q.setQuery(theQueryStr); q.setQuery(theQueryStr);
q.setRows(MAX_RESULTS); q.setRows(MAX_RESULTS);
if (snippets) { q.setFields(Server.Schema.ID.toString());
q.setFields(Server.Schema.ID.toString());
} else {
q.setFields(Server.Schema.ID.toString());
}
for (KeywordQueryFilter filter : filters) { for (KeywordQueryFilter filter : filters) {
q.addFilterQuery(filter.toString()); q.addFilterQuery(filter.toString());
@ -438,6 +434,8 @@ class LuceneQuery implements KeywordSearchQuery {
if (contentHighlights == null) { if (contentHighlights == null) {
return ""; return "";
} else { } else {
// Sort contentHighlights in order to get consistently same snippet.
contentHighlights.sort(null);
// extracted content is HTML-escaped, but snippet goes in a plain text field // extracted content is HTML-escaped, but snippet goes in a plain text field
return EscapeUtil.unEscapeHtml(contentHighlights.get(0)).trim(); return EscapeUtil.unEscapeHtml(contentHighlights.get(0)).trim();
} }