Fix percolator highlight sub fetch phase to not highlight query twice (#26622)

* Fix percolator highlight sub fetch phase to not highlight query twice

The PercolatorHighlightSubFetchPhase does not override hitExecute and since it extends HighlightPhase the search hits
are highlighted twice (by the highlight phase and then by the percolator). This does not alter the results, the second highlighting
just overrides the first one but this slow down the request because it duplicates the work.
This commit is contained in:
Jim Ferenczi 2017-09-14 09:31:14 +02:00 committed by GitHub
parent ca6bce75da
commit 401f4ba2ce
2 changed files with 5 additions and 5 deletions

View File

@ -909,7 +909,7 @@ Response:
}, },
"highlight": { "highlight": {
"message": [ "message": [
"some message with the <em>number</em> <em>1</em>" " with the <em>number</em> <em>1</em>"
] ]
} }
} }

View File

@ -53,13 +53,13 @@ import java.util.Map;
* Highlighting in the case of the percolate query is a bit different, because the PercolateQuery itself doesn't get highlighted, * Highlighting in the case of the percolate query is a bit different, because the PercolateQuery itself doesn't get highlighted,
* but the source of the PercolateQuery gets highlighted by each hit containing a query. * but the source of the PercolateQuery gets highlighted by each hit containing a query.
*/ */
final class PercolatorHighlightSubFetchPhase extends HighlightPhase { final class PercolatorHighlightSubFetchPhase implements FetchSubPhase {
private final HighlightPhase highlightPhase;
PercolatorHighlightSubFetchPhase(Settings settings, Map<String, Highlighter> highlighters) { PercolatorHighlightSubFetchPhase(Settings settings, Map<String, Highlighter> highlighters) {
super(settings, highlighters); this.highlightPhase = new HighlightPhase(settings, highlighters);
} }
boolean hitsExecutionNeeded(SearchContext context) { // for testing boolean hitsExecutionNeeded(SearchContext context) { // for testing
return context.highlight() != null && locatePercolatorQuery(context.query()).isEmpty() == false; return context.highlight() != null && locatePercolatorQuery(context.query()).isEmpty() == false;
} }
@ -109,7 +109,7 @@ final class PercolatorHighlightSubFetchPhase extends HighlightPhase {
percolatorLeafReaderContext, slot, percolatorIndexSearcher percolatorLeafReaderContext, slot, percolatorIndexSearcher
); );
hitContext.cache().clear(); hitContext.cache().clear();
super.hitExecute(subSearchContext, hitContext); highlightPhase.hitExecute(subSearchContext, hitContext);
for (Map.Entry<String, HighlightField> entry : hitContext.hit().getHighlightFields().entrySet()) { for (Map.Entry<String, HighlightField> entry : hitContext.hit().getHighlightFields().entrySet()) {
if (percolateQuery.getDocuments().size() == 1) { if (percolateQuery.getDocuments().size() == 1) {
String hlFieldName; String hlFieldName;