|
@@ -26,11 +26,9 @@ import org.elasticsearch.index.mapper.KeywordFieldMapper;
|
|
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
|
|
import org.elasticsearch.index.mapper.SourceFieldMapper;
|
|
import org.elasticsearch.index.mapper.SourceFieldMapper;
|
|
|
import org.elasticsearch.index.mapper.TextFieldMapper;
|
|
import org.elasticsearch.index.mapper.TextFieldMapper;
|
|
|
-import org.elasticsearch.index.query.QueryShardContext;
|
|
|
|
|
-import org.elasticsearch.search.SearchShardTarget;
|
|
|
|
|
|
|
+import org.elasticsearch.search.fetch.FetchContext;
|
|
|
import org.elasticsearch.search.fetch.FetchSubPhase;
|
|
import org.elasticsearch.search.fetch.FetchSubPhase;
|
|
|
import org.elasticsearch.search.fetch.FetchSubPhaseProcessor;
|
|
import org.elasticsearch.search.fetch.FetchSubPhaseProcessor;
|
|
|
-import org.elasticsearch.search.internal.SearchContext;
|
|
|
|
|
import org.elasticsearch.search.lookup.SearchLookup;
|
|
import org.elasticsearch.search.lookup.SearchLookup;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -50,16 +48,16 @@ public class HighlightPhase implements FetchSubPhase {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public FetchSubPhaseProcessor getProcessor(SearchContext context, SearchLookup lookup) {
|
|
|
|
|
|
|
+ public FetchSubPhaseProcessor getProcessor(FetchContext context, SearchLookup lookup) {
|
|
|
if (context.highlight() == null) {
|
|
if (context.highlight() == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return getProcessor(context.getQueryShardContext(), context.shardTarget(), context.highlight(), context.parsedQuery().query());
|
|
|
|
|
|
|
+ return getProcessor(context, context.highlight(), context.parsedQuery().query());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public FetchSubPhaseProcessor getProcessor(QueryShardContext qsc, SearchShardTarget target, SearchHighlightContext hc, Query query) {
|
|
|
|
|
- Map<String, Function<HitContext, FieldHighlightContext>> contextBuilders = contextBuilders(qsc, target, hc, query);
|
|
|
|
|
|
|
+ public FetchSubPhaseProcessor getProcessor(FetchContext context, SearchHighlightContext highlightContext, Query query) {
|
|
|
|
|
+ Map<String, Function<HitContext, FieldHighlightContext>> contextBuilders = contextBuilders(context, highlightContext, query);
|
|
|
return new FetchSubPhaseProcessor() {
|
|
return new FetchSubPhaseProcessor() {
|
|
|
@Override
|
|
@Override
|
|
|
public void setNextReader(LeafReaderContext readerContext) {
|
|
public void setNextReader(LeafReaderContext readerContext) {
|
|
@@ -99,22 +97,21 @@ public class HighlightPhase implements FetchSubPhase {
|
|
|
return highlighter;
|
|
return highlighter;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Map<String, Function<HitContext, FieldHighlightContext>> contextBuilders(QueryShardContext context,
|
|
|
|
|
- SearchShardTarget shardTarget,
|
|
|
|
|
- SearchHighlightContext highlight,
|
|
|
|
|
|
|
+ private Map<String, Function<HitContext, FieldHighlightContext>> contextBuilders(FetchContext context,
|
|
|
|
|
+ SearchHighlightContext highlightContext,
|
|
|
Query query) {
|
|
Query query) {
|
|
|
Map<String, Function<HitContext, FieldHighlightContext>> builders = new LinkedHashMap<>();
|
|
Map<String, Function<HitContext, FieldHighlightContext>> builders = new LinkedHashMap<>();
|
|
|
- for (SearchHighlightContext.Field field : highlight.fields()) {
|
|
|
|
|
|
|
+ for (SearchHighlightContext.Field field : highlightContext.fields()) {
|
|
|
Highlighter highlighter = getHighlighter(field);
|
|
Highlighter highlighter = getHighlighter(field);
|
|
|
Collection<String> fieldNamesToHighlight;
|
|
Collection<String> fieldNamesToHighlight;
|
|
|
if (Regex.isSimpleMatchPattern(field.field())) {
|
|
if (Regex.isSimpleMatchPattern(field.field())) {
|
|
|
- fieldNamesToHighlight = context.getMapperService().simpleMatchToFullName(field.field());
|
|
|
|
|
|
|
+ fieldNamesToHighlight = context.mapperService().simpleMatchToFullName(field.field());
|
|
|
} else {
|
|
} else {
|
|
|
fieldNamesToHighlight = Collections.singletonList(field.field());
|
|
fieldNamesToHighlight = Collections.singletonList(field.field());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (highlight.forceSource(field)) {
|
|
|
|
|
- SourceFieldMapper sourceFieldMapper = context.getMapperService().documentMapper().sourceMapper();
|
|
|
|
|
|
|
+ if (highlightContext.forceSource(field)) {
|
|
|
|
|
+ SourceFieldMapper sourceFieldMapper = context.mapperService().documentMapper().sourceMapper();
|
|
|
if (sourceFieldMapper.enabled() == false) {
|
|
if (sourceFieldMapper.enabled() == false) {
|
|
|
throw new IllegalArgumentException("source is forced for fields " + fieldNamesToHighlight
|
|
throw new IllegalArgumentException("source is forced for fields " + fieldNamesToHighlight
|
|
|
+ " but _source is disabled");
|
|
+ " but _source is disabled");
|
|
@@ -123,7 +120,7 @@ public class HighlightPhase implements FetchSubPhase {
|
|
|
|
|
|
|
|
boolean fieldNameContainsWildcards = field.field().contains("*");
|
|
boolean fieldNameContainsWildcards = field.field().contains("*");
|
|
|
for (String fieldName : fieldNamesToHighlight) {
|
|
for (String fieldName : fieldNamesToHighlight) {
|
|
|
- MappedFieldType fieldType = context.getMapperService().fieldType(fieldName);
|
|
|
|
|
|
|
+ MappedFieldType fieldType = context.mapperService().fieldType(fieldName);
|
|
|
if (fieldType == null) {
|
|
if (fieldType == null) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -148,9 +145,9 @@ public class HighlightPhase implements FetchSubPhase {
|
|
|
|
|
|
|
|
Query highlightQuery = field.fieldOptions().highlightQuery();
|
|
Query highlightQuery = field.fieldOptions().highlightQuery();
|
|
|
|
|
|
|
|
- boolean forceSource = highlight.forceSource(field);
|
|
|
|
|
|
|
+ boolean forceSource = highlightContext.forceSource(field);
|
|
|
builders.put(fieldName,
|
|
builders.put(fieldName,
|
|
|
- hc -> new FieldHighlightContext(fieldType.name(), field, fieldType, shardTarget, context, hc,
|
|
|
|
|
|
|
+ hc -> new FieldHighlightContext(fieldType.name(), field, fieldType, context, hc,
|
|
|
highlightQuery == null ? query : highlightQuery, forceSource));
|
|
highlightQuery == null ? query : highlightQuery, forceSource));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|