Is there a way to dynamically update the synonyms file without restarting the Solr server?

As we know, there is a synonym.txt file in the conf directory that I wanted to update whenever I found a few new synonyms words ...

So, is there a way to update this file dynamically without restarting the Solr server, and my search result will consider new synonyms

Please help me if anyone has an idea .. thanks in advance ...

+4
source share
2 answers

I think you can create your own SynonymFilterFactory , which extends the original and uses a custom FSTSynonymFilterFactory as a delegation. your SynonymFilterFactory should extend the original SlowSynonymFilterFactory and call:

map = loadSolrSynonyms(loader, true, analyzer); 

when you want to reload the synonym file.

To reload the file when changing it, you can use the watchdog timer thread that runs every X times and checks if the sysnonim file has been changed, or you can use some file watcher to be notified when the file has been changed.

+7
source

Solr provides a Managed Synonym Graph Filter for managing synonyms using the REST API (in this example, through the endpoint /solr/collection_name/schema/analysis/synonyms/english ):

 <analyzer type="index"> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.ManagedSynonymGraphFilterFactory" managed="english"/> <filter class="solr.FlattenGraphFilterFactory"/> <!-- required on index analyzers after graph filters --> </analyzer> <analyzer type="query"> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.ManagedSynonymGraphFilterFactory" managed="english"/> </analyzer> 

To use synonyms, a kernel reboot is required. Solr provides a REST API for this as well. CoreAdmin admin/cores?action=RELOAD&core=core-name API Update

The RELOAD action loads the new kernel from the configuration of the existing registered Solr kernel. While the new kernel is initializing, the existing one will continue to process requests. When the new Solr core is ready, it takes over and the old core is unloaded.

0
source

All Articles