Example usage for org.apache.lucene.analysis.synonym SynonymFilterFactory inform

List of usage examples for org.apache.lucene.analysis.synonym SynonymFilterFactory inform

Introduction

In this page you can find the example usage for org.apache.lucene.analysis.synonym SynonymFilterFactory inform.

Prototype

@Override
    public void inform(ResourceLoader loader) throws IOException 

Source Link

Usage

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  www. j  a  v a2s .c om
    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// w w w  .  j  av a2  s  .  co  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/*from  w  ww.  j  a v  a 2s  .c  om*/
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);/*w  w  w .j a v a 2 s .c o  m*/
    factory.inform(new StringMockSolrResourceLoader("")); // empty file!
    TokenStream ts = factory.create(new MockTokenizer(new StringReader("GB"), MockTokenizer.WHITESPACE, false));
    assertTokenStreamContents(ts, new String[] { "GB" });
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.common.config.LuceneIAViewConfiguration.java

License:Mozilla Public License

public @Bean SynonymFilterFactory synonymFilterFactory() {
    Map<String, String> synonymFilterArgs = new HashMap<String, String>();
    synonymFilterArgs.put("synonyms", "synonyms.txt");
    synonymFilterArgs.put("expand", "true");
    synonymFilterArgs.put("ignoreCase", "true");
    synonymFilterArgs.put("luceneMatchVersion", version);
    SynonymFilterFactory synonymFilterFactory = new SynonymFilterFactory(synonymFilterArgs);

    try {//from  w  w  w.j a v a2  s.  c o  m
        ResourceLoader loader = new ClasspathResourceLoader(getClass());
        synonymFilterFactory.inform(loader);
    } catch (IOException e) {
        logger.error(".synonymFilterFactory: an error occured while creating the Filter factory: {}",
                e.getMessage());
    }
    return synonymFilterFactory;

}