On 6/24/2013 1:27 PM, Ashwin Tandel wrote:
Does Solr provides any java API/Client library to generate (e)dismax Query.

for eg. using Java Code/API I wish to generate query like
'q=video&defType=edismax&qf=features^20.0+text^0.3&bq=cat:electronics^5.0'

You can use the SolrJ library.  http://wiki.apache.org/solr/Solrj

Here's some sample code. It's not the best Java in the world, but it gives you an idea:

// If not using SolrCloud:
String url = "http://server:port/solr/corename";;
SolrServer server = new HttpSolrServer(url);

// If using SolrCloud:
String zkHost = "server1:2181,server2:2181,server3:2181/chroot";
SolrServer server = new CloudSolrServer(zkHost);

// Setting up the query:
// q=video&defType=edismax&qf=features^20.0+text^0.3
// &bq=cat:electronics^5.0
SolrQuery query = new SolrQuery();
query.setQuery("video");
query.set("defType", "edismax");
query.set("qf", "features^20 text^0.3");
query.set("bq", "cat:electronics^5.0");

// Working with the response
QueryResponse response = server.query(query);
long numFound = response.getResults().getNumFound();
SolrDocument doc = response.getResults().get(0);
for (String field : doc.getFieldNames()) {
        System.out.println
          (field + ": " + doc.get(field) + "\n");
}

Thanks,
Shawn

Reply via email to