@Before public void createAnalyzers() throws Exception { queryAnalyzer = new Analyzer() { @Override protected TokenStreamComponents createComponents(String fieldName) { // White space tokenizer, to lower case tokenizer. return new TokenStreamComponents(new MockTokenizer()); } }; SynonymMap.Builder builder = new SynonymMap.Builder(true); builder.add(new CharsRef("test"), new CharsRef("synonym1"), false); builder.add(new CharsRef("test"), new CharsRef("synonym2"), false); final SynonymMap synonyms = builder.build(); synonymAnalyzer = new Analyzer() { @Override protected TokenStreamComponents createComponents(String fieldName) { // White space tokenizer, to lower case tokenizer. MockTokenizer tokenizer = new MockTokenizer(); // Filter for adding synonyms TokenStream result = new SynonymFilter(tokenizer, synonyms, true); // Filter all non-synonyms, because the synonym filter outputs the // original token too. result = new TypeTokenFilter(result, Collections.singleton(SynonymFilter.TYPE_SYNONYM), true); return new TokenStreamComponents(tokenizer, result); } }; }
@Override public TokenStream create(TokenStream tokenStream) { return new TypeTokenFilter(tokenStream, keepTypes, true); }
@Override public TokenStream create(TokenStream input) { return new TypeTokenFilter(enablePositionIncrements, input, stopTypes, useWhitelist); }