Search in sources :

Example 1 with SynonymGraphFilterFactory

use of org.apache.lucene.analysis.synonym.SynonymGraphFilterFactory in project lucene-solr by apache.

the class ManagedSynonymGraphFilterFactory method onManagedResourceInitialized.

/**
   * 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.
   */
@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);
    }
}
Also used : ResourceLoader(org.apache.lucene.analysis.util.ResourceLoader) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) HashMap(java.util.HashMap) NamedList(org.apache.solr.common.util.NamedList) IOException(java.io.IOException) Analyzer(org.apache.lucene.analysis.Analyzer) SynonymMap(org.apache.lucene.analysis.synonym.SynonymMap) SynonymGraphFilterFactory(org.apache.lucene.analysis.synonym.SynonymGraphFilterFactory) ParseException(java.text.ParseException) SynonymMap(org.apache.lucene.analysis.synonym.SynonymMap) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SolrException(org.apache.solr.common.SolrException)

Aggregations

IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 SynonymGraphFilterFactory (org.apache.lucene.analysis.synonym.SynonymGraphFilterFactory)1 SynonymMap (org.apache.lucene.analysis.synonym.SynonymMap)1 ResourceLoader (org.apache.lucene.analysis.util.ResourceLoader)1 SolrException (org.apache.solr.common.SolrException)1 NamedList (org.apache.solr.common.util.NamedList)1 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)1