Reputation:
I am using solr synonym in my application.. here is query to from which i am getting synonym
http://localhost:8983/solr/analysis/field?analysis.query='+request.term+'&analysis.fieldname=description&analysis.showmatch=true&wt=json&indent=true
I tried same using solrj to get synonym
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/analysis/field");
params.set("analysis.query", queryterm);
params.set("analysis.fieldname", "description");
params.set("analysis.showmatch", true);
try {
resp1 = server.query(params);
System.out.println(resp1);
} catch (SolrServerException ex) {
System.out.println(ex);
}
SolrDocumentList results = resp1.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i).getFieldValue("description").toString());
}
How to get synonym?
Upvotes: 0
Views: 744
Reputation: 9320
You can't get synonyms via SolrJ. The only way here - is to use RestAPI (Solr 4.8+)
Synonyms For the most part, the API for managing synonyms behaves similar to the API for stop words, except instead of working with a list of words, we need to work with a map, where the value for each entry in the map is a set of synonyms for a term. As with stop words, the example server ships with a minimal set of English synonym mappings that is activated by the following field type definition in schema.xml:
<fieldType name="managed_en" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.ManagedSynonymFilterFactory"
managed="english" />
</analyzer>
</fieldType>
To get the map of managed English synonyms, send a GET request to:
curl "http://localhost:8983/solr/collection1/schema/analysis/
synonyms/english"
More info about that - http://lucidworks.com/blog/introducing-solrs-restmanager-and-managed-stop-words-and-synonyms/
Upvotes: 1