Wrap keyword in quotes to make highlighting work when keyword hits are accessed through the tree.

This commit is contained in:
esaunders 2016-12-06 11:17:12 -05:00
parent 7bcb31495e
commit 09c5b3ccde

View File

@ -84,7 +84,7 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
//when the results are not known and need to requery to get hits //when the results are not known and need to requery to get hits
HighlightedText(long objectId, String solrQuery, boolean isRegex, String originalQuery) { HighlightedText(long objectId, String solrQuery, boolean isRegex, String originalQuery) {
this(objectId, solrQuery, isRegex); this(objectId, KeywordSearchUtil.quoteQuery(solrQuery), isRegex);
this.originalQuery = originalQuery; this.originalQuery = originalQuery;
} }
@ -132,13 +132,16 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
* need to perform the search to get the highlights. * need to perform the search to get the highlights.
*/ */
if (hits == null) { if (hits == null) {
String queryStr = KeywordSearchUtil.escapeLuceneQuery(this.keywordHitQuery); // I don't undertand how we could get into this code with a regex query.
if (isRegex) { // Won't all regex queries have been resolved to actual literal keyword hits
//use white-space sep. field to get exact matches only of regex query result // by the time we attempt to load page content? EGS.
queryStr = Server.Schema.CONTENT_WS + ":" + "\"" + queryStr + "\""; // String queryStr = KeywordSearchUtil.escapeLuceneQuery(this.keywordHitQuery);
} // if (isRegex) {
// //use white-space sep. field to get exact matches only of regex query result
// queryStr = Server.Schema.CONTENT_WS + ":" + "\"" + queryStr + "\"";
// }
Keyword keywordQuery = new Keyword(queryStr, !isRegex); Keyword keywordQuery = new Keyword(this.keywordHitQuery, !isRegex);
List<Keyword> keywords = new ArrayList<>(); List<Keyword> keywords = new ArrayList<>();
keywords.add(keywordQuery); keywords.add(keywordQuery);
KeywordSearchQuery chunksQuery = new LuceneQuery(new KeywordList(keywords), keywordQuery); KeywordSearchQuery chunksQuery = new LuceneQuery(new KeywordList(keywords), keywordQuery);