Reputation: 78
I have developed a solr component which expands users query and adds additional clauses to the query. For this expansion we are making request to external REST api's. This query expansion logic is mainly in prepare() method. Everything works as expected in standalone mode. When we deploy this plugin in SolrCloud environment each shard is calling external REST api for query expansion.
My question is that can we make only one call to external REST api since its the same request sent from each shard to external service. How can we modify our component to make only one call per search request ?
Upvotes: 0
Views: 166
Reputation: 442
In the prepare() method, right before your external API call, you can check RequestBuilder.isDistrib()
. This boolean will be true for a request that is about to be distributed. You can then use this information to determine whether you can just execute the external request or you need to set one of the SolrCloud hosts that does this job.
How to determine the SolrCloud host to use for the external API? You could...
After you got an answer from the external API, you can use modifyRequest()
to update all other hosts on the results.
Please read more in the Solr Wiki.
Upvotes: 1
Reputation: 1042
The approach you can use is like:
Make your requestHandler be aware of special flag which will trigger / not trigger your own custom logic. What I mean looks like this (I know it is not fancy):
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
...
SolrParams params = req.getParams();
if (req.getParams().get("apiCallWasSent") == null) {
makeApiCall(req, rsp);
params = new ModifiableSolrParams(params);
params.add("apiCallWasSent", "true");
req.setParams(params);
}
...
super.handleRequestBody(req, rsp);
}
QParserPlugin
. But component also can handle those clauses.Upvotes: 0