From 097cb2dac7b1578f8a32d85a7367d755920c11db Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Thu, 25 Oct 2012 21:23:47 -0400 Subject: [PATCH] lucene 4: migrate char filter from CharStream to Reader --- .../index/analysis/CharFilterFactory.java | 4 ++-- .../index/analysis/CustomAnalyzer.java | 4 +--- .../analysis/HtmlStripCharFilterFactory.java | 5 +++-- .../analysis/MappingCharFilterFactory.java | 18 +++++++++--------- .../analysis/IndicesAnalysisService.java | 4 ++-- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/analysis/CharFilterFactory.java b/src/main/java/org/elasticsearch/index/analysis/CharFilterFactory.java index 4df5a3c08f2..d3587cfe272 100644 --- a/src/main/java/org/elasticsearch/index/analysis/CharFilterFactory.java +++ b/src/main/java/org/elasticsearch/index/analysis/CharFilterFactory.java @@ -19,7 +19,7 @@ package org.elasticsearch.index.analysis; -import org.apache.lucene.analysis.CharStream; +import java.io.Reader; /** * @@ -28,5 +28,5 @@ public interface CharFilterFactory { String name(); - CharStream create(CharStream tokenStream); + Reader create(Reader tokenStream); } diff --git a/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzer.java b/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzer.java index 62c530e41ff..15d6a706006 100644 --- a/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzer.java +++ b/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzer.java @@ -106,11 +106,9 @@ public final class CustomAnalyzer extends Analyzer { private Reader charFilterIfNeeded(Reader reader) { if (charFilters != null && charFilters.length > 0) { - CharStream charStream = CharReader.get(reader); for (CharFilterFactory charFilter : charFilters) { - charStream = charFilter.create(charStream); + reader = charFilter.create(reader); } - reader = charStream; } return reader; } diff --git a/src/main/java/org/elasticsearch/index/analysis/HtmlStripCharFilterFactory.java b/src/main/java/org/elasticsearch/index/analysis/HtmlStripCharFilterFactory.java index 4cb3ea41b98..1c6d9f4c378 100644 --- a/src/main/java/org/elasticsearch/index/analysis/HtmlStripCharFilterFactory.java +++ b/src/main/java/org/elasticsearch/index/analysis/HtmlStripCharFilterFactory.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.analysis; import com.google.common.collect.ImmutableSet; -import org.apache.lucene.analysis.CharStream; import org.apache.lucene.analysis.charfilter.HTMLStripCharFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; @@ -28,6 +27,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; +import java.io.Reader; + /** * */ @@ -51,7 +52,7 @@ public class HtmlStripCharFilterFactory extends AbstractCharFilterFactory { } @Override - public CharStream create(CharStream tokenStream) { + public Reader create(Reader tokenStream) { return new HTMLStripCharFilter(tokenStream, escapedTags); } } diff --git a/src/main/java/org/elasticsearch/index/analysis/MappingCharFilterFactory.java b/src/main/java/org/elasticsearch/index/analysis/MappingCharFilterFactory.java index 848cbd25a55..a74b5b6a796 100644 --- a/src/main/java/org/elasticsearch/index/analysis/MappingCharFilterFactory.java +++ b/src/main/java/org/elasticsearch/index/analysis/MappingCharFilterFactory.java @@ -19,9 +19,8 @@ package org.elasticsearch.index.analysis; -import org.apache.lucene.analysis.CharStream; -import org.apache.lucene.analysis.MappingCharFilter; -import org.apache.lucene.analysis.NormalizeCharMap; +import org.apache.lucene.analysis.charfilter.MappingCharFilter; +import org.apache.lucene.analysis.charfilter.NormalizeCharMap; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; @@ -30,6 +29,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; +import java.io.Reader; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -37,7 +37,7 @@ import java.util.regex.Pattern; @AnalysisSettingsRequired public class MappingCharFilterFactory extends AbstractCharFilterFactory { - private final NormalizeCharMap normMap; + private final NormalizeCharMap.Builder normMapBuilder; @Inject public MappingCharFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { @@ -48,13 +48,13 @@ public class MappingCharFilterFactory extends AbstractCharFilterFactory { throw new ElasticSearchIllegalArgumentException("mapping requires either `mappings` or `mappings_path` to be configured"); } - normMap = new NormalizeCharMap(); - parseRules(rules, normMap); + normMapBuilder = new NormalizeCharMap.Builder(); + parseRules(rules, normMapBuilder); } @Override - public CharStream create(CharStream tokenStream) { - return new MappingCharFilter(normMap, tokenStream); + public Reader create(Reader tokenStream) { + return new MappingCharFilter(normMapBuilder.build(), tokenStream); } // source => target @@ -63,7 +63,7 @@ public class MappingCharFilterFactory extends AbstractCharFilterFactory { /** * parses a list of MappingCharFilter style rules into a normalize char map */ - private void parseRules(List rules, NormalizeCharMap map) { + private void parseRules(List rules, NormalizeCharMap.Builder map) { for (String rule : rules) { Matcher m = rulePattern.matcher(rule); if (!m.find()) diff --git a/src/main/java/org/elasticsearch/indices/analysis/IndicesAnalysisService.java b/src/main/java/org/elasticsearch/indices/analysis/IndicesAnalysisService.java index 49d7a2f3d9f..198e5133893 100644 --- a/src/main/java/org/elasticsearch/indices/analysis/IndicesAnalysisService.java +++ b/src/main/java/org/elasticsearch/indices/analysis/IndicesAnalysisService.java @@ -658,7 +658,7 @@ public class IndicesAnalysisService extends AbstractComponent { } @Override - public CharStream create(CharStream tokenStream) { + public Reader create(Reader tokenStream) { return new HTMLStripCharFilter(tokenStream); } })); @@ -670,7 +670,7 @@ public class IndicesAnalysisService extends AbstractComponent { } @Override - public CharStream create(CharStream tokenStream) { + public Reader create(Reader tokenStream) { return new HTMLStripCharFilter(tokenStream); } }));