public void testBackwardsCompatibilityEdgeNgramTokenFilter() throws Exception { int iters = scaledRandomIntBetween(20, 100); for (int i = 0; i < iters; i++) { final Index index = new Index("test", "_na_"); final String name = "ngr"; Version v = randomVersion(random()); Builder builder = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3); boolean reverse = random().nextBoolean(); if (reverse) { builder.put("side", "back"); } Settings settings = builder.build(); Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build(); Tokenizer tokenizer = new MockTokenizer(); tokenizer.setReader(new StringReader("foo bar")); TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create(tokenizer); if (reverse) { assertThat(edgeNGramTokenFilter, instanceOf(ReverseStringFilter.class)); } else { assertThat(edgeNGramTokenFilter, instanceOf(EdgeNGramTokenFilter.class)); } } }
@Override public ReverseStringFilter create(TokenStream in) { if (luceneMatchVersion == null) { return new ReverseStringFilter(in); } return new ReverseStringFilter(luceneMatchVersion,in); }
@Override public TokenStream create(TokenStream tokenStream) { return new ReverseStringFilter(tokenStream); }
@Override protected TokenStreamComponents createComponents(String fieldName, Reader reader) { final Tokenizer tokenizer = new KeywordTokenizer(reader); return new TokenStreamComponents(tokenizer, new ReverseStringFilter(new EdgeNGramTokenFilter(new ReverseStringFilter(tokenizer), 10, 20))); }
@Override public ReverseStringFilter create(TokenStream in) { assureMatchVersion(); return new ReverseStringFilter(luceneMatchVersion,in); }
@Override public ReverseStringFilter create(TokenStream in) { return new ReverseStringFilter(luceneMatchVersion,in); }
@Override protected TokenStreamComponents createComponents(String fieldName, Reader reader) { final Tokenizer tokenizer = new KeywordTokenizer(reader); return new TokenStreamComponents(tokenizer, new ReverseStringFilter(TEST_VERSION_CURRENT, new EdgeNGramTokenFilter(TEST_VERSION_CURRENT, new ReverseStringFilter(TEST_VERSION_CURRENT, tokenizer), 10, 20))); }