List of usage examples for org.apache.lucene.analysis.synonym SynonymFilterFactory create
@Override
public TokenStream create(TokenStream input)
From source file:org.apache.solr.analysis.TestSynonymFilterFactory.java
License:Apache License
/** test that we can parse and use the solr syn file */ public void testSynonyms() throws Exception { SynonymFilterFactory factory = new SynonymFilterFactory(); Map<String, String> args = new HashMap<String, String>(); args.put("synonyms", "synonyms.txt"); factory.setLuceneMatchVersion(TEST_VERSION_CURRENT); factory.init(args);/*from ww w .j a v a 2 s .c o m*/ factory.inform(new SolrResourceLoader(null, null)); TokenStream ts = factory.create(new MockTokenizer(new StringReader("GB"), MockTokenizer.WHITESPACE, false)); assertTrue(ts instanceof SynonymFilter); assertTokenStreamContents(ts, new String[] { "GB", "gib", "gigabyte", "gigabytes" }, new int[] { 1, 0, 0, 0 }); }
From source file:org.apache.solr.analysis.TestSynonymFilterFactory.java
License:Apache License
/** test that we can parse and use the solr syn file, with the old impl * @deprecated Remove this test in Lucene 5.0 */ @Deprecated/* ww w . j av a 2 s . c o m*/ public void testSynonymsOld() throws Exception { SynonymFilterFactory factory = new SynonymFilterFactory(); Map<String, String> args = new HashMap<String, String>(); args.put("synonyms", "synonyms.txt"); factory.setLuceneMatchVersion(Version.LUCENE_33); factory.init(args); factory.inform(new SolrResourceLoader(null, null)); TokenStream ts = factory.create(new MockTokenizer(new StringReader("GB"), MockTokenizer.WHITESPACE, false)); assertTrue(ts instanceof SlowSynonymFilter); assertTokenStreamContents(ts, new String[] { "GB", "gib", "gigabyte", "gigabytes" }, new int[] { 1, 0, 0, 0 }); }
From source file:org.apache.solr.analysis.TestSynonymFilterFactory.java
License:Apache License
/** test multiword offsets with the old impl * @deprecated Remove this test in Lucene 5.0 */ @Deprecated// w w w . j a va2s. c o m public void testMultiwordOffsetsOld() throws Exception { SynonymFilterFactory factory = new SynonymFilterFactory(); Map<String, String> args = new HashMap<String, String>(); args.put("synonyms", "synonyms.txt"); factory.setLuceneMatchVersion(Version.LUCENE_33); factory.init(args); factory.inform(new StringMockSolrResourceLoader("national hockey league, nhl")); TokenStream ts = factory.create( new MockTokenizer(new StringReader("national hockey league"), MockTokenizer.WHITESPACE, false)); // WTF? assertTokenStreamContents(ts, new String[] { "national", "nhl", "hockey", "league" }, new int[] { 0, 0, 0, 0 }, new int[] { 22, 22, 22, 22 }, new int[] { 1, 0, 1, 1 }); }
From source file:org.apache.solr.analysis.TestSynonymFilterFactory.java
License:Apache License
/** if the synonyms are completely empty, test that we still analyze correctly */ public void testEmptySynonyms() throws Exception { SynonymFilterFactory factory = new SynonymFilterFactory(); Map<String, String> args = new HashMap<String, String>(); args.put("synonyms", "synonyms.txt"); factory.setLuceneMatchVersion(TEST_VERSION_CURRENT); factory.init(args);/*from w ww . j av a 2 s . co m*/ factory.inform(new StringMockSolrResourceLoader("")); // empty file! TokenStream ts = factory.create(new MockTokenizer(new StringReader("GB"), MockTokenizer.WHITESPACE, false)); assertTokenStreamContents(ts, new String[] { "GB" }); }