简体   繁体   中英

How to load file “synonyms.txt” present on remote server using solr?

<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>

Here file "synonyms.txt" is present in current directory . How to load this file if it's location is on remote server not on local machine ?

Unfortunately, you can't just type in an URL because the ResourceLoader of the SynonymFilterFactory uses a FilesystemResourceLoader .

Thus said, you could still point Solr to anything that looks and behaves like a file, eg an NFS-mounted directory or even a locally synced Dropbox folder.

You can't load resource from remote. Instead you can http post request to put synonyms to your solr server with ManagedSynonymFilterFactory

This featured introduced in Solr 4.8.0

How to Use :

First you have to declare your filter like below

<filter class="solr.ManagedSynonymFilterFactory" managed="english"/>

You can post Synonyms to solr with the below curl request :

curl -X PUT -H 'Content-type:application/json' --data-binary '{"mad":["angry","upset"]}' "http://solr_ip:8983/solr/collection_name/schema/analysis/synonyms/english"

Here change solr_ip and collection_name with yours. and i am putting word synonyms for mad is angry,upset

And you can check your synonyms by a get request.

http://solr_ip:8983/solr/collection_name/schema/analysis/synonyms/english

For more info : https://cwiki.apache.org/confluence/display/solr/Managed+Resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM