mallik
mallik

Reputation: 567

How to call solr analysis api in java?

Is there a way to call solrs analysis api in java using solr-core and get the analyzed tokens.

Analysis api takes fieldName or fieldType and values and give the analyzed tokens.

Is there a way to get those tokens from java?

I found the following link: FieldAnalysisRequestHandler, But I could not get any examples to use it.

Upvotes: 1

Views: 654

Answers (1)

Simon
Simon

Reputation: 857

In the Admin UI (for which the FieldAnalysisRequestHandler is meant) you can call it by selecting a core and then go to the "Analysis" entry. See https://cwiki.apache.org/confluence/x/UYDxAQ or https://cwiki.apache.org/confluence/x/FoDxAQ for that.

From a client (which I guess you mean, as you tagged this question with solrj) you need to call the correct URL. Typically the FieldAnalysisRequestHandler is bound to /analysis/field, see your solrconfig.xml.

From Solrj it should work like this:

SolrQuery query = new SolrQuery();
solrQuery.setRequestHandler("/analysis/field");
solrQuery.set("analysis.fieldtype", "mytype");
solrQuery.set("analysis.fieldvalue", "myval");
QueryResponse solrResponse = solrServer.query(solrQuery);

But it doesn't seem like there's a great support for this in Solrj, probably because it's meant to be called from the Solr Admin UI as mentioned.

Upvotes: 1

Related Questions