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 Upayavira <uv...@odoko.co.uk> on 2013/04/10 13:22:12 UTC

Combining join queries

I'm sure the best way for me to solve this issue myself is to ask it
publicly, so...

If I have two {!join} queries that select a collection of documents
each, how do I create a filter query that combines their results?

If I do fq={!join....} {!join...} it only considers the first.

>From what I understand, the Lucene query parser should combine these two
with an implicit OR, no?

Upayavira

Re: Combining join queries

Posted by Upayavira <uv...@odoko.co.uk>.
Many thanks Yonik!

Upayavira

On Thu, Apr 11, 2013, at 09:32 PM, Yonik Seeley wrote:
> On Wed, Apr 10, 2013 at 7:33 AM, Upayavira <uv...@odoko.co.uk> wrote:
> > On Wed, Apr 10, 2013, at 12:22 PM, Upayavira wrote:
> >> I'm sure the best way for me to solve this issue myself is to ask it
> >> publicly, so...
> >>
> >> If I have two {!join} queries that select a collection of documents
> >> each, how do I create a filter query that combines their results?
> >>
> >> If I do fq={!join....} {!join...} it only considers the first.
> >>
> >> From what I understand, the Lucene query parser should combine these two
> >> with an implicit OR, no?
> >
> > Yup. My theory worked, I did solve it myself.
> >
> > If I instead do fq=_query_:"{!join...}" _query_:"{!join...}" it works
> > fine, but the shortened syntax above, which I believe is supposed to
> > work, doesn't. This is using Solr 4.0.
> 
> Support was first added in 4.1 for this.
> 
> If a query starts with {!join... then that will use the join query
> parser (which will consider *everything* after part of the "from"
> query.).  If you want "lucene" syntax with two embedded join queries,
> then just make sure that the query string does not start with {!
> 
> for example:
> fq= {!join from=f1 to=f2 v='f3:term1'} {!join from=f3 to=f4 v='f4:term2'}
> 
> (notice the space before the {! that prevents invoking a different
> query parser and thus invokes the default lucene syntax)
> 
> -Yonik
> http://lucidworks.com

Re: Combining join queries

Posted by Yonik Seeley <yo...@lucidworks.com>.
On Wed, Apr 10, 2013 at 7:33 AM, Upayavira <uv...@odoko.co.uk> wrote:
> On Wed, Apr 10, 2013, at 12:22 PM, Upayavira wrote:
>> I'm sure the best way for me to solve this issue myself is to ask it
>> publicly, so...
>>
>> If I have two {!join} queries that select a collection of documents
>> each, how do I create a filter query that combines their results?
>>
>> If I do fq={!join....} {!join...} it only considers the first.
>>
>> From what I understand, the Lucene query parser should combine these two
>> with an implicit OR, no?
>
> Yup. My theory worked, I did solve it myself.
>
> If I instead do fq=_query_:"{!join...}" _query_:"{!join...}" it works
> fine, but the shortened syntax above, which I believe is supposed to
> work, doesn't. This is using Solr 4.0.

Support was first added in 4.1 for this.

If a query starts with {!join... then that will use the join query
parser (which will consider *everything* after part of the "from"
query.).  If you want "lucene" syntax with two embedded join queries,
then just make sure that the query string does not start with {!

for example:
fq= {!join from=f1 to=f2 v='f3:term1'} {!join from=f3 to=f4 v='f4:term2'}

(notice the space before the {! that prevents invoking a different
query parser and thus invokes the default lucene syntax)

-Yonik
http://lucidworks.com

Re: Combining join queries

Posted by Upayavira <uv...@odoko.co.uk>.
On Wed, Apr 10, 2013, at 12:22 PM, Upayavira wrote:
> I'm sure the best way for me to solve this issue myself is to ask it
> publicly, so...
> 
> If I have two {!join} queries that select a collection of documents
> each, how do I create a filter query that combines their results?
> 
> If I do fq={!join....} {!join...} it only considers the first.
> 
> From what I understand, the Lucene query parser should combine these two
> with an implicit OR, no?

Yup. My theory worked, I did solve it myself.

If I instead do fq=_query_:"{!join...}" _query_:"{!join...}" it works
fine, but the shortened syntax above, which I believe is supposed to
work, doesn't. This is using Solr 4.0.

Upayavira