Greenhorn
Greenhorn

Reputation: 1821

Distributed search using solrj?

Can I perform a distributed search using solrj? If so how? (note : not solr)

I don't find any documentation in this aspect. Kindly help me if you find any/have used this before.

Upvotes: 4

Views: 1691

Answers (1)

stzoannos
stzoannos

Reputation: 938

Assuming that your shards are:

"localhost:8983/solr" and "localhost:7574/solr"

You may perform a distributed search with solrj like:

String shards = "localhost:8983/solr,localhost:7574/solr";
StringBuffer request = new StringBuffer();
request.append("&q=" + query);
request.append("&shards=" + shards);
SolrParams solrParams = SolrRequestParsers.parseQueryString(request
                .toString());
QueryResponse rsp = server.query(solrParams);

alternatively, you may use the ModifiableSolrParams class:

String shards = "localhost:8983/solr,localhost:7574/solr";
ModifiableSolrParams solrParams = new ModifiableSolrParams();
solrParams.set("q", query);
solrParams.set("shards", shards);
QueryResponse rsp = server.query(solrParams);

Upvotes: 8

Related Questions