I'm using the solrj API to query my SOLR 3.6 index. I have multiple text fields, which I would like to weight differently. From what I've read, I should be able to do this using the dismax or edismax query types. I've tried the following:
SolrQuery query = new SolrQuery();
query.setQuery( "title:apples oranges content:apples oranges");
query.setQueryType("edismax");
query.set("qf", "title^10.0 content^1.0");
QueryResponse rsp = m_Server.query( query );
But this doesn't work. I've tried the following variations to set the query type, but it doesn't seem to make a difference.
query.setQueryType("dismax");
query.set("qt","dismax");
query.set("type","edismax");
query.set("qt","edismax");
query.set("type","dismax");
I'd like to retain the full Lucene query syntax, so I prefer ExtendedDisMax to DisMax. Boosting individual terms in the query (as shown below) does work, but is not a valid solution, since the queries are automatically generated and can get arbitrarily complex is syntax.
query.setQuery( "title:apples^10.0 oranges^10.0 content:apples oranges");
Any help would be much appreciated.
Best way would be to define a request handler in your solrconfig.xml like -
<requestHandler name="search" class="solr.SearchHandler" default="true">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="defType">dismax</str>
<str name="qf">
title^1 content^0.8
</str>
<str name="q.alt">*:*</str>
<str name="rows">10</str>
<str name="fl">*,score</str>
</lst>
</requestHandler>
And use qt parameter to define the request handler -
query.set("qt","search");
You can fine tune the boost configuration just by changing in the solr config xml configurations and reloading the cores.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With