From 7271a80b501ce6e1e96c501618632911c199e1e2 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Fri, 29 Jul 2011 21:31:48 +0300 Subject: [PATCH] Stop Token Filter - enable_position_increments, closes #1182. --- .../index/analysis/StopTokenFilterFactory.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopTokenFilterFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopTokenFilterFactory.java index f43a571c729..53721718796 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopTokenFilterFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopTokenFilterFactory.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.analysis.StopAnalyzer; import org.apache.lucene.analysis.StopFilter; import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.util.Version; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; @@ -40,14 +41,19 @@ public class StopTokenFilterFactory extends AbstractTokenFilterFactory { private final boolean ignoreCase; + private final boolean enablePositionIncrements; + @Inject public StopTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { super(index, indexSettings, name, settings); this.stopWords = Analysis.parseStopWords(env, settings, StopAnalyzer.ENGLISH_STOP_WORDS_SET); this.ignoreCase = settings.getAsBoolean("ignore_case", false); + this.enablePositionIncrements = settings.getAsBoolean("enable_position_increments", version.onOrAfter(Version.LUCENE_29)); } @Override public TokenStream create(TokenStream tokenStream) { - return new StopFilter(version, tokenStream, stopWords, ignoreCase); + StopFilter filter = new StopFilter(version, tokenStream, stopWords, ignoreCase); + filter.setEnablePositionIncrements(enablePositionIncrements); + return filter; } public Set stopWords() { @@ -57,4 +63,8 @@ public class StopTokenFilterFactory extends AbstractTokenFilterFactory { public boolean ignoreCase() { return ignoreCase; } + + public boolean enablePositionIncrements() { + return this.enablePositionIncrements; + } }