Bypass highlight query terms extraction on empty fields (#32090)

Dealing with empty fields in the highlight phase can
slow down the query because the query terms extraction is done independently
on each field. This change shortcuts the highlighting performed by the unified highlighter
for fields that are not present in the document. In such cases there is nothing to higlight so
we don't need to visit the query to build the highligh builder.
This commit is contained in:
Jim Ferenczi 2018-07-17 00:26:01 +02:00 committed by GitHub
parent d596447f3d
commit f699cb9f55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -76,6 +76,9 @@ public class UnifiedHighlighter implements Highlighter {
fieldValues = fieldValues.stream()
.map((s) -> convertFieldValue(fieldType, s))
.collect(Collectors.toList());
if (fieldValues.size() == 0) {
return null;
}
final IndexSearcher searcher = new IndexSearcher(hitContext.reader());
final CustomUnifiedHighlighter highlighter;
final String fieldValue = mergeFieldValues(fieldValues, MULTIVAL_SEP_CHAR);