Skip to content

Commit

Permalink
Fix percolator highlight sub fetch phase to not highlight query twice (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
jimczi committed Sep 14, 2017
1 parent a6e5af1 commit b54a051
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/reference/search/request/highlighting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ Response:
},
"highlight": {
"message": [
"some message with the <em>number</em> <em>1</em>"
" with the <em>number</em> <em>1</em>"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
* 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.
*/
final class PercolatorHighlightSubFetchPhase extends HighlightPhase {
final class PercolatorHighlightSubFetchPhase implements FetchSubPhase {
private final HighlightPhase highlightPhase;

PercolatorHighlightSubFetchPhase(Settings settings, Map<String, Highlighter> highlighters) {
super(settings, highlighters);
this.highlightPhase = new HighlightPhase(settings, highlighters);
}


boolean hitsExecutionNeeded(SearchContext context) { // for testing
return context.highlight() != null && locatePercolatorQuery(context.query()).isEmpty() == false;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept
percolatorLeafReaderContext, slot, percolatorIndexSearcher
);
hitContext.cache().clear();
super.hitExecute(subSearchContext, hitContext);
highlightPhase.hitExecute(subSearchContext, hitContext);
for (Map.Entry<String, HighlightField> entry : hitContext.hit().getHighlightFields().entrySet()) {
if (percolateQuery.getDocuments().size() == 1) {
String hlFieldName;
Expand Down

0 comments on commit b54a051

Please sign in to comment.