use of org.apache.lucene.analysis.Analyzer in project elasticsearch by elastic.
the class PreBuiltAnalyzerTests method testThatDefaultAndStandardAnalyzerAreTheSameInstance.
public void testThatDefaultAndStandardAnalyzerAreTheSameInstance() {
Analyzer currentStandardAnalyzer = PreBuiltAnalyzers.STANDARD.getAnalyzer(Version.CURRENT);
Analyzer currentDefaultAnalyzer = PreBuiltAnalyzers.DEFAULT.getAnalyzer(Version.CURRENT);
// special case, these two are the same instance
assertThat(currentDefaultAnalyzer, is(currentStandardAnalyzer));
}
use of org.apache.lucene.analysis.Analyzer in project elasticsearch by elastic.
the class CompoundAnalysisTests method analyze.
private List<String> analyze(Settings settings, String analyzerName, String text) throws IOException {
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
AnalysisModule analysisModule = new AnalysisModule(new Environment(settings), singletonList(new AnalysisPlugin() {
@Override
public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
return singletonMap("myfilter", MyFilterTokenFilterFactory::new);
}
}));
IndexAnalyzers indexAnalyzers = analysisModule.getAnalysisRegistry().build(idxSettings);
Analyzer analyzer = indexAnalyzers.get(analyzerName).analyzer();
AllEntries allEntries = new AllEntries();
allEntries.addText("field1", text, 1.0f);
TokenStream stream = AllTokenStream.allTokenStream("_all", text, 1.0f, analyzer);
stream.reset();
CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class);
List<String> terms = new ArrayList<>();
while (stream.incrementToken()) {
String tokText = termAtt.toString();
terms.add(tokText);
}
return terms;
}
use of org.apache.lucene.analysis.Analyzer in project elasticsearch by elastic.
the class SnowballAnalyzerTests method testReusableTokenStream.
public void testReusableTokenStream() throws Exception {
Analyzer a = new SnowballAnalyzer("English");
assertAnalyzesTo(a, "he abhorred accents", new String[] { "he", "abhor", "accent" });
assertAnalyzesTo(a, "she abhorred him", new String[] { "she", "abhor", "him" });
}
use of org.apache.lucene.analysis.Analyzer in project elasticsearch by elastic.
the class FingerprintAnalyzerTests method testLimit.
public void testLimit() throws Exception {
Analyzer a = new FingerprintAnalyzer(CharArraySet.EMPTY_SET, ' ', 3);
assertAnalyzesTo(a, "e d c b a", new String[] {});
assertAnalyzesTo(a, "b a", new String[] { "a b" });
}
use of org.apache.lucene.analysis.Analyzer in project elasticsearch by elastic.
the class FingerprintAnalyzerTests method testAsciifolding.
public void testAsciifolding() throws Exception {
Analyzer a = new FingerprintAnalyzer(CharArraySet.EMPTY_SET, ' ', 255);
assertAnalyzesTo(a, "gödel escher bach", new String[] { "bach escher godel" });
assertAnalyzesTo(a, "gödel godel escher bach", new String[] { "bach escher godel" });
}
Aggregations