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

痴心易碎 提交于 2019-11-30 02:30:31

I think you can build your own SynonymFilterFactory that extends the original and use your a custom FSTSynonymFilterFactory as delegator. your SynonymFilterFactory should extends the original SlowSynonymFilterFactory and call:

map = loadSolrSynonyms(loader, true, analyzer);

whenever you want to reload the synonym file.

For reloading your file when it changes you can use a watchdog thread that awke up every X time and check whether the sysnonim file was changed or you can use some file watcher to get notification when the file was changed.

Solr provides Managed Synonym Graph Filter to manage synonyms using a REST API (in this example via /solr/collection_name/schema/analysis/synonyms/english endpoint):

<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>

A core reload is needed to apply synonyms changes. Solr provides a REST API for this too CoreAdmin API Reload admin/cores?action=RELOAD&core=core-name

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!