lucene 4: migrate char filter from CharStream to Reader
This commit is contained in:
parent
f572a7bcf7
commit
097cb2dac7
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.analysis;
|
package org.elasticsearch.index.analysis;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.CharStream;
|
import java.io.Reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -28,5 +28,5 @@ public interface CharFilterFactory {
|
||||||
|
|
||||||
String name();
|
String name();
|
||||||
|
|
||||||
CharStream create(CharStream tokenStream);
|
Reader create(Reader tokenStream);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,11 +106,9 @@ public final class CustomAnalyzer extends Analyzer {
|
||||||
|
|
||||||
private Reader charFilterIfNeeded(Reader reader) {
|
private Reader charFilterIfNeeded(Reader reader) {
|
||||||
if (charFilters != null && charFilters.length > 0) {
|
if (charFilters != null && charFilters.length > 0) {
|
||||||
CharStream charStream = CharReader.get(reader);
|
|
||||||
for (CharFilterFactory charFilter : charFilters) {
|
for (CharFilterFactory charFilter : charFilters) {
|
||||||
charStream = charFilter.create(charStream);
|
reader = charFilter.create(reader);
|
||||||
}
|
}
|
||||||
reader = charStream;
|
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.index.analysis;
|
package org.elasticsearch.index.analysis;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import org.apache.lucene.analysis.CharStream;
|
|
||||||
import org.apache.lucene.analysis.charfilter.HTMLStripCharFilter;
|
import org.apache.lucene.analysis.charfilter.HTMLStripCharFilter;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.inject.assistedinject.Assisted;
|
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.Index;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -51,7 +52,7 @@ public class HtmlStripCharFilterFactory extends AbstractCharFilterFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharStream create(CharStream tokenStream) {
|
public Reader create(Reader tokenStream) {
|
||||||
return new HTMLStripCharFilter(tokenStream, escapedTags);
|
return new HTMLStripCharFilter(tokenStream, escapedTags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,8 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.analysis;
|
package org.elasticsearch.index.analysis;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.CharStream;
|
import org.apache.lucene.analysis.charfilter.MappingCharFilter;
|
||||||
import org.apache.lucene.analysis.MappingCharFilter;
|
import org.apache.lucene.analysis.charfilter.NormalizeCharMap;
|
||||||
import org.apache.lucene.analysis.NormalizeCharMap;
|
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.inject.assistedinject.Assisted;
|
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.Index;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -37,7 +37,7 @@ import java.util.regex.Pattern;
|
||||||
@AnalysisSettingsRequired
|
@AnalysisSettingsRequired
|
||||||
public class MappingCharFilterFactory extends AbstractCharFilterFactory {
|
public class MappingCharFilterFactory extends AbstractCharFilterFactory {
|
||||||
|
|
||||||
private final NormalizeCharMap normMap;
|
private final NormalizeCharMap.Builder normMapBuilder;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MappingCharFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) {
|
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");
|
throw new ElasticSearchIllegalArgumentException("mapping requires either `mappings` or `mappings_path` to be configured");
|
||||||
}
|
}
|
||||||
|
|
||||||
normMap = new NormalizeCharMap();
|
normMapBuilder = new NormalizeCharMap.Builder();
|
||||||
parseRules(rules, normMap);
|
parseRules(rules, normMapBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharStream create(CharStream tokenStream) {
|
public Reader create(Reader tokenStream) {
|
||||||
return new MappingCharFilter(normMap, tokenStream);
|
return new MappingCharFilter(normMapBuilder.build(), tokenStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
// source => target
|
// source => target
|
||||||
|
@ -63,7 +63,7 @@ public class MappingCharFilterFactory extends AbstractCharFilterFactory {
|
||||||
/**
|
/**
|
||||||
* parses a list of MappingCharFilter style rules into a normalize char map
|
* parses a list of MappingCharFilter style rules into a normalize char map
|
||||||
*/
|
*/
|
||||||
private void parseRules(List<String> rules, NormalizeCharMap map) {
|
private void parseRules(List<String> rules, NormalizeCharMap.Builder map) {
|
||||||
for (String rule : rules) {
|
for (String rule : rules) {
|
||||||
Matcher m = rulePattern.matcher(rule);
|
Matcher m = rulePattern.matcher(rule);
|
||||||
if (!m.find())
|
if (!m.find())
|
||||||
|
|
|
@ -658,7 +658,7 @@ public class IndicesAnalysisService extends AbstractComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharStream create(CharStream tokenStream) {
|
public Reader create(Reader tokenStream) {
|
||||||
return new HTMLStripCharFilter(tokenStream);
|
return new HTMLStripCharFilter(tokenStream);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -670,7 +670,7 @@ public class IndicesAnalysisService extends AbstractComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharStream create(CharStream tokenStream) {
|
public Reader create(Reader tokenStream) {
|
||||||
return new HTMLStripCharFilter(tokenStream);
|
return new HTMLStripCharFilter(tokenStream);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue