小智 8
假设你的碎片是:
"localhost:8983/solr"和"localhost:7574/solr"
您可以使用solrj执行分布式搜索,例如:
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);
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用ModifiableSolrParams类:
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);
Run Code Online (Sandbox Code Playgroud)