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 joelmats <jo...@gmail.com> on 2011/07/01 12:19:06 UTC

optional nested queries

Hello!

Is it possible to have an optional nested query. I have 2 nested queries and
would like to have the first query mandatory but the second optional. ie..
if there is a match on the second query, i would like it to improve the
score but it is not required.

A sample query I am currently using is:
sort=score+desc&fl=*+score&start=0&q=_query_:"{!dismax qf='name_text
categories_text people_texts' mm='1' hl='on' hl.simple.pre='@@@hl@@@'
hl.simple.post='@@@endhl@@@' hl.fl='people_texts'}mr+milk" _query_:"{!dismax
qf='city_text' mm='1'}new york"&rows=10&debugQuery=on

However, it seems that if the second query fails to match, the whole query
fails.

Thanks!

J



--
View this message in context: http://lucene.472066.n3.nabble.com/optional-nested-queries-tp3128847p3128847.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: optional nested queries

Posted by joelmats <jo...@gmail.com>.
Thanks!

I was wondering why my highlighting wasnt' working either.

--
View this message in context: http://lucene.472066.n3.nabble.com/optional-nested-queries-tp3128847p3130593.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: optional nested queries

Posted by Erik Hatcher <er...@gmail.com>.
Put an OR between your two nested queries to ensure you're using that operator.  Also, those hl params in your first dismax don't really belong there and should be separate parameters globally.

	Erik

On Jul 1, 2011, at 06:19 , joelmats wrote:

> Hello!
> 
> Is it possible to have an optional nested query. I have 2 nested queries and
> would like to have the first query mandatory but the second optional. ie..
> if there is a match on the second query, i would like it to improve the
> score but it is not required.
> 
> A sample query I am currently using is:
> sort=score+desc&fl=*+score&start=0&q=_query_:"{!dismax qf='name_text
> categories_text people_texts' mm='1' hl='on' hl.simple.pre='@@@hl@@@'
> hl.simple.post='@@@endhl@@@' hl.fl='people_texts'}mr+milk" _query_:"{!dismax
> qf='city_text' mm='1'}new york"&rows=10&debugQuery=on
> 
> However, it seems that if the second query fails to match, the whole query
> fails.
> 
> Thanks!
> 
> J
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/optional-nested-queries-tp3128847p3128847.html
> Sent from the Solr - User mailing list archive at Nabble.com.


Re: optional nested queries

Posted by kenf_nc <ke...@realestate.com>.
I don't use dismax, but do something similar with a regular query. I have a
field defined in my schema.xml called 'dummy' (not sure why its called that
actually) but it defaults to 1 on every document indexed. So say I want to
give a score bump to documents that have an image, I can do queries like:

q=Some+search+text+AND+(has_image:true^.5 OR dummy:1)

I'm doing that from memory haven't actually tested so my syntax may be off,
but i hope you get the idea. Basically the first part of the OR query in
parenthesis is your optional nested query, if it fails, or even if the
document doesn't have a field called has_image at all, the dummy:1 will
always pass.

Ken

--
View this message in context: http://lucene.472066.n3.nabble.com/optional-nested-queries-tp3128847p3129064.html
Sent from the Solr - User mailing list archive at Nabble.com.