From 20f60d3c4cbb8d97c20a259a8399420df148eeb4 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 1 May 2015 10:31:31 +0200 Subject: [PATCH] Highlighting: dedup field names when using wildcard expression to identify which fields to highlight --- .../search/highlight/HighlightPhase.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java b/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java index cd3c12591f706..0da6df7791b34 100644 --- a/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java +++ b/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java @@ -19,10 +19,9 @@ package org.elasticsearch.search.highlight; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import org.apache.lucene.index.IndexOptions; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.regex.Regex; @@ -35,8 +34,8 @@ import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.SearchContext; -import java.util.List; import java.util.Map; +import java.util.Set; import static com.google.common.collect.Maps.newHashMap; @@ -76,12 +75,12 @@ public boolean hitExecutionNeeded(SearchContext context) { public void hitExecute(SearchContext context, HitContext hitContext) { Map highlightFields = newHashMap(); for (SearchContextHighlight.Field field : context.highlight().fields()) { - List fieldNamesToHighlight; + Set fieldNamesToHighlight; if (Regex.isSimpleMatchPattern(field.field())) { DocumentMapper documentMapper = context.mapperService().documentMapper(hitContext.hit().type()); - fieldNamesToHighlight = documentMapper.mappers().simpleMatchToFullName(field.field()); + fieldNamesToHighlight = ImmutableSet.copyOf(documentMapper.mappers().simpleMatchToFullName(field.field())); } else { - fieldNamesToHighlight = ImmutableList.of(field.field()); + fieldNamesToHighlight = ImmutableSet.of(field.field()); } if (context.highlight().forceSource(field)) {