Example usage for org.apache.lucene.analysis.synonym SynonymGraphFilterFactory SynonymGraphFilterFactory

List of usage examples for org.apache.lucene.analysis.synonym SynonymGraphFilterFactory SynonymGraphFilterFactory

Introduction

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

Prototype

public SynonymGraphFilterFactory(Map<String, String> args) 

Source Link

Usage

From source file:org.apache.solr.rest.schema.analysis.ManagedSynonymGraphFilterFactory.java

License:Apache License

/**
 * Called once, during core initialization, to initialize any analysis components
 * that depend on the data managed by this resource. It is important that the
 * analysis component is only initialized once during core initialization so that
 * text analysis is consistent, especially in a distributed environment, as we
 * don't want one server applying a different set of stop words than other servers.
 *//*  www  . j a v  a 2  s . c  o m*/
@SuppressWarnings("unchecked")
@Override
public void onManagedResourceInitialized(NamedList<?> initArgs, final ManagedResource res)
        throws SolrException {
    NamedList<Object> args = (NamedList<Object>) initArgs;
    args.add("synonyms", getResourceId());
    args.add("expand", "false");
    args.add("format", "solr");

    Map<String, String> filtArgs = new HashMap<>();
    for (Map.Entry<String, ?> entry : args) {
        filtArgs.put(entry.getKey(), entry.getValue().toString());
    }
    // create the actual filter factory that pulls the synonym mappings
    // from synonymMappings using a custom parser implementation
    delegate = new SynonymGraphFilterFactory(filtArgs) {
        @Override
        protected SynonymMap loadSynonyms(ResourceLoader loader, String cname, boolean dedup, Analyzer analyzer)
                throws IOException, ParseException {

            ManagedSynonymParser parser = new ManagedSynonymParser((SynonymManager) res, dedup, analyzer);
            // null is safe here because there's no actual parsing done against a input Reader
            parser.parse(null);
            return parser.build();
        }
    };
    try {
        delegate.inform(res.getResourceLoader());
    } catch (IOException e) {
        throw new SolrException(ErrorCode.SERVER_ERROR, e);
    }
}