diff --git a/src/main/java/org/apache/lucene/search/vectorhighlight/AbstractFragmentsBuilder.java b/src/main/java/org/apache/lucene/search/vectorhighlight/AbstractFragmentsBuilder.java index a0a794c850c..183b9d5f93f 100644 --- a/src/main/java/org/apache/lucene/search/vectorhighlight/AbstractFragmentsBuilder.java +++ b/src/main/java/org/apache/lucene/search/vectorhighlight/AbstractFragmentsBuilder.java @@ -110,9 +110,10 @@ public abstract class AbstractFragmentsBuilder extends BaseFragmentsBuilder { } }); - fragInfos = getWeightedFragInfoList(fragInfos); } + fragInfos = getWeightedFragInfoList(fragInfos); + StringBuilder buffer = new StringBuilder(); int[] nextValueIndex = {0}; for (int n = 0; n < maxNumFragments && n < fragInfos.size(); n++) { diff --git a/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java b/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java index 0549ec0689c..019baa7f35f 100644 --- a/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java +++ b/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java @@ -33,11 +33,14 @@ import org.apache.lucene.search.highlight.*; import org.apache.lucene.search.highlight.Formatter; import org.apache.lucene.search.vectorhighlight.*; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FastStringReader; import org.elasticsearch.common.lucene.document.SingleFieldSelector; import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery; import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import org.elasticsearch.common.lucene.search.vectorhighlight.SimpleBoundaryScanner2; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MapperService; @@ -57,13 +60,21 @@ import static com.google.common.collect.Maps.newHashMap; /** * */ -public class HighlightPhase implements FetchSubPhase { +public class HighlightPhase extends AbstractComponent implements FetchSubPhase { public static class Encoders { public static Encoder DEFAULT = new DefaultEncoder(); public static Encoder HTML = new SimpleHTMLEncoder(); } + private final boolean termVectorMultiValue; + + @Inject + public HighlightPhase(Settings settings) { + super(settings); + this.termVectorMultiValue = componentSettings.getAsBoolean("term_vector_multi_value", true); + } + @Override public Map parseElements() { return ImmutableMap.of("highlight", new HighlighterParseElement()); @@ -243,7 +254,7 @@ public class HighlightPhase implements FetchSubPhase { FieldQuery fieldQuery = null; if (entry == null) { FragListBuilder fragListBuilder; - FragmentsBuilder fragmentsBuilder; + AbstractFragmentsBuilder fragmentsBuilder; BoundaryScanner boundaryScanner = SimpleBoundaryScanner2.DEFAULT; if (field.boundaryMaxScan() != SimpleBoundaryScanner2.DEFAULT_MAX_SCAN || field.boundaryChars() != SimpleBoundaryScanner2.DEFAULT_BOUNDARY_CHARS) { @@ -278,6 +289,7 @@ public class HighlightPhase implements FetchSubPhase { } } } + fragmentsBuilder.setDiscreteMultiValueHighlighting(termVectorMultiValue); entry = new MapperHighlightEntry(); entry.fragListBuilder = fragListBuilder; entry.fragmentsBuilder = fragmentsBuilder;