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 Andrea Campi <an...@zephirworks.com> on 2009/11/19 13:02:48 UTC
nested queries
Hi,
I'm trying to wrap my head around nested queries and I'm having some
trouble figuring out how far can I go with them. I have to say
documentation is still a bit sparse... :/
I'm trying to build a query that would search the same term(s) on
different fields with different boosts, like:
text:something OR ftext:something^1000
In addition I am adding a function query to manipulate the score further.
To make things easier and more maintainable, I'd like to use nested
queries for that; I'd like to be able to write:
q={!boost b=$dateboost v=ftext:$terms^1000 OR
text:$terms}&dateboost=product(...etc.)&terms=something
Or even better:
q={!boost b=$dateboost v=$qq}&qq={!query v=ftext:$terms^1000 OR
text:$terms}&dateboost=product(...etc.)&terms=something
I tried both of the above (and some other variations, with parenthesis
etc) but it looks like variables are replaced only if they are the only
thing that appears after a v=.
For instance, this works perfectly:
q={!boost b=$dateboost v=$qq}&qq={!query
v=$terms}&dateboost=product(...etc.)&terms=something
whereas even this fails:
q={!boost b=$dateboost v=$qq}&qq={!query
v=text:$terms}&dateboost=product(...etc.)&terms=something
Do you guys see any way to obtain what I want--or to do it better?
Thanks in advance,
Andrea
Re: nested queries
Posted by Jay Hill <ja...@gmail.com>.
I don't think your queries are actually nested queries. Nested queries key
off of the "magic" field name _query_. You're right however that there is
very little in the way of documentation of examples of nested queries. If
you haven't seen this blog about them yet you might find this a helpful
overview of nested queries:
http://www.lucidimagination.com/blog/2009/03/31/nested-queries-in-solr/
-Jay
On Thu, Nov 19, 2009 at 6:15 AM, Andrea Campi
<an...@zephirworks.com>wrote:
> Grant,
>
> Grant Ingersoll wrote:
>
>> On Nov 19, 2009, at 7:02 AM, Andrea Campi wrote:
>>
>>
>>>
>>> To make things easier and more maintainable, I'd like to use nested
>>> queries for that; I'd like to be able to write:
>>>
>>> q={!boost b=$dateboost v=ftext:$terms^1000 OR
>>> text:$terms}&dateboost=product(...etc.)&terms=something
>>>
>>> Or even better:
>>>
>>> q={!boost b=$dateboost v=$qq}&qq={!query v=ftext:$terms^1000 OR
>>> text:$terms}&dateboost=product(...etc.)&terms=something
>>>
>>>
>>>
>>
>> Sounds like you might benefit from using the Dismax Parser. You can
>> specify the field boosting thing in your config and also add the bf (boost
>> function) capability.
>>
>>
> I tried that but the customer prefers the lucene syntax for the actual
> query.
>
> However, now that you mention this, I should probably be able to use Dismax
> but specify the lucene syntax for the actual search on the 'text' field,
> right?
> I will try that, thanks.
>
> Bye,
> Andrea
>
Re: nested queries
Posted by Andrea Campi <an...@zephirworks.com>.
Grant,
Grant Ingersoll wrote:
> On Nov 19, 2009, at 7:02 AM, Andrea Campi wrote:
>
>>
>> To make things easier and more maintainable, I'd like to use nested queries for that; I'd like to be able to write:
>>
>> q={!boost b=$dateboost v=ftext:$terms^1000 OR text:$terms}&dateboost=product(...etc.)&terms=something
>>
>> Or even better:
>>
>> q={!boost b=$dateboost v=$qq}&qq={!query v=ftext:$terms^1000 OR text:$terms}&dateboost=product(...etc.)&terms=something
>>
>>
>
> Sounds like you might benefit from using the Dismax Parser. You can specify the field boosting thing in your config and also add the bf (boost function) capability.
>
I tried that but the customer prefers the lucene syntax for the actual
query.
However, now that you mention this, I should probably be able to use
Dismax but specify the lucene syntax for the actual search on the 'text'
field, right?
I will try that, thanks.
Bye,
Andrea
Re: nested queries
Posted by Grant Ingersoll <gs...@apache.org>.
On Nov 19, 2009, at 7:02 AM, Andrea Campi wrote:
> Hi,
>
> I'm trying to wrap my head around nested queries and I'm having some trouble figuring out how far can I go with them. I have to say documentation is still a bit sparse... :/
>
>
> I'm trying to build a query that would search the same term(s) on different fields with different boosts, like:
>
> text:something OR ftext:something^1000
>
> In addition I am adding a function query to manipulate the score further.
>
>
> To make things easier and more maintainable, I'd like to use nested queries for that; I'd like to be able to write:
>
> q={!boost b=$dateboost v=ftext:$terms^1000 OR text:$terms}&dateboost=product(...etc.)&terms=something
>
> Or even better:
>
> q={!boost b=$dateboost v=$qq}&qq={!query v=ftext:$terms^1000 OR text:$terms}&dateboost=product(...etc.)&terms=something
>
>
> I tried both of the above (and some other variations, with parenthesis etc) but it looks like variables are replaced only if they are the only thing that appears after a v=.
> For instance, this works perfectly:
>
> q={!boost b=$dateboost v=$qq}&qq={!query v=$terms}&dateboost=product(...etc.)&terms=something
>
> whereas even this fails:
>
> q={!boost b=$dateboost v=$qq}&qq={!query v=text:$terms}&dateboost=product(...etc.)&terms=something
>
>
> Do you guys see any way to obtain what I want--or to do it better?
Sounds like you might benefit from using the Dismax Parser. You can specify the field boosting thing in your config and also add the bf (boost function) capability.