You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Joe <jo...@gmail.com> on 2012/04/26 00:57:36 UTC

Boosting fields in SOLR using Solrj

Hi,

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.

--
View this message in context: http://lucene.472066.n3.nabble.com/Boosting-fields-in-SOLR-using-Solrj-tp3939789p3939789.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Boosting fields in SOLR using Solrj

Posted by Joe <jo...@gmail.com>.
Thanks Kuli. I tried this, but then it only returns hits for the query in the
title field. I managed to get this work, by making edismax the default query
type in the request handler in solrconfig.xml. This is still a bit of a
hack, since I can't select different query types from solrj. If I add a
second result handler for search, it seems to get overridden by the existing
one. 

--
View this message in context: http://lucene.472066.n3.nabble.com/Boosting-fields-in-SOLR-using-Solrj-tp3939789p3945486.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Boosting fields in SOLR using Solrj

Posted by Michael Kuhlmann <ku...@solarier.de>.
Am 26.04.2012 00:57, schrieb Joe:
> Hi,
>
> 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 );

Why do you try to construct your own query, when you're using an edismax 
query with a defined qf parameter?

What you're searching is the text "title:apples oranges content:apples 
oranges". Depending on your analyzer chain, it might be that title:appes 
and content:apples are kept as one token, so nothing is found because 
there's no such token in the index.

Why don't you simply query for "apples oranges"? That's how (e)dismax is 
made for. Have a deeper look at http://wiki.apache.org/solr/DisMax.

BTW, if you used the above query in a Lucene parser, it would look for 
"apples" in title and content field, but look for "oranges" in your 
default search field. This is because you didn't quote "apples oranges". 
Since you want to use Edismax, you can ignore this, it's just that you 
current query won't work as expected in both cases.

-Kuli

Re: Boosting fields in SOLR using Solrj

Posted by Joe <jo...@gmail.com>.
I finally figured this out. The answer is here (see my comment to the
answer):
http://stackoverflow.com/questions/10324969/boosting-fields-in-solr-using-solrj

--
View this message in context: http://lucene.472066.n3.nabble.com/Boosting-fields-in-SOLR-using-Solrj-tp3939789p3945626.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Boosting fields in SOLR using Solrj

Posted by Joe <jo...@gmail.com>.
Thanks Ryan. I created a second requestHandler, which works fine in the
browser.
In solrj, how do I tell the SolrQuery which request handler to use? It
always seems to default to another requestHandler.


--
View this message in context: http://lucene.472066.n3.nabble.com/Boosting-fields-in-SOLR-using-Solrj-tp3939789p3945496.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Boosting fields in SOLR using Solrj

Posted by Ryan McKinley <ry...@gmail.com>.
I would suggest debugging with browser requests -- then switching to
Solrj after you are at 1st base.

In particular, try adding the &debugQuery=true parameter to the
request and see what solr thinks is happening.

The value that will "work" for the 'qt' parameter depends on what is
configured in solrconfig.xml -- I suspect you want to point to a
requestHandler that is configured to use edismax query parser.  This
can be configured by default with:

<lst name="defaults">
<str name="defType">edismax</str>
</lst>

ryan


On Wed, Apr 25, 2012 at 3:57 PM, Joe <jo...@gmail.com> wrote:
> Hi,
>
> 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.
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Boosting-fields-in-SOLR-using-Solrj-tp3939789p3939789.html
> Sent from the Solr - User mailing list archive at Nabble.com.