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 Bruce Johnson <hb...@gmail.com> on 2014/07/09 17:24:41 UTC

Complement of {!join}

=== Short-version ===
Is there a way to join on the complement of a query? I want the only the
Solr documents for which the nested join query does not match.

=== Longer-version ===
Query-time joins with {!join} are great at modeling the SQL equivalent of
patterns like this:

SELECT book_name FROM books WHERE id
IN (SELECT book_id FROM chapters WHERE chapter_title = "Foo")

This would find the name of books having chapters entitled "Foo". (Assuming
the chapters table have the column 'book_id' that point back to the book
record containing them.)

That's great.

Is there a way in Solr to query for the complement of that? In SQL terms,
this:

SELECT book_name FROM books WHERE id
NOT IN (SELECT book_id FROM chapters WHERE chapter_title = "Foo")

This would find books that do not have chapters entitled "Foo".

It isn't the same as querying (in Solr terms) for something like

{!join to=id from=book_id}-chapter_title:"Foo" // note the negation

because it would still match other chapters in the same book that are not
entitled "Foo", causing the join to still identify the book based on its
other non-Foo chapters.

Any advice would be greatly appreciated. I'm also open to other ways of
thinking about the problem. Perhaps there are alternative indexing patterns
that could accomplish the same goal.

Many thanks,
Bruce

Re: Complement of {!join}

Posted by Chris Hostetter <ho...@fucit.org>.
: So, I think a lot of people may be missing that power. I suspect it's

I've added some comments to the relevant pages as reminders to go back and 
add more detail later so we don't lose track of the doc feedback expressed 
in this thread ... when i get more time i'll try to go back and fill that 
in.


-Hoss
http://www.lucidworks.com/

Re: Complement of {!join}

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Yes, slide 11 of first presentation and slide 35 of the second one do
show that the _query or {!} can be used multiple types in one top
query. The other slides/links do not, they only show it once.

So, I think a lot of people may be missing that power. I suspect it's
a bit like using the bbox search to see who is available to work the
night shift example.

In any case, I put it on my blog todo list. I already have a Solr
example for it (https://gist.github.com/arafalov/5e04884e5aefaf46678c),
as well as - for those curious - an ElasticSearch counter example:
https://gist.github.com/mattweber/9cb7d0d9fc112dffa8de (not tested).

Regards,
  Alex.
Personal website: http://www.outerthoughts.com/
Current project: http://www.solr-start.com/ - Accelerating your Solr proficiency


On Thu, Jul 10, 2014 at 8:42 PM, Erik Hatcher <er...@gmail.com> wrote:
> Yeah, using multiple _query_’s has always been possible.  _query_ is just a special field name that gets interpreted specially.  Same with _val_ for function queries.
>
> It’s a feature that’s been leveraged and “documented” (by way of presentation materials and blogs, at least) such as:
>
>   - http://www.slideshare.net/erikhatcher/solr-query-parsing (slides 6 and 11)
>   - http://www.slideshare.net/erikhatcher/solr-black-belt-preconference (slide 35)
>   - http://searchhub.org/2009/03/31/nested-queries-in-solr/
>
> My favorite example of this is Stanford’s library advanced search - http://searchworks.stanford.edu/advanced - where it uses a different dismax “sub”query for each field (which actually corresponds to multiple underlying Solr fields each).
>
> Best,
>         Erik
>
>
>
> On Jul 10, 2014, at 12:19 AM, Alexandre Rafalovitch <ar...@gmail.com> wrote:
>
>> Well, even JIRA and the release notes concentrates on a replacement of
>> _query_ with {!}. But not about having multiple of them. Was it
>> possible to have multiple _query_ segments in one 'q' query? I was not
>> aware of that either.
>>
>> Basically, I am suggesting that somebody who knows this in depth
>> should write an article. I feel it is a powerful feature of Solr, but
>> I was even hesitant to use it in my own config because all the online
>> examples were for a single-use.
>>
>> Regards,
>>   Alex.
>> Personal website: http://www.outerthoughts.com/
>> Current project: http://www.solr-start.com/ - Accelerating your Solr proficiency
>>
>>
>> On Thu, Jul 10, 2014 at 11:18 AM, Jack Krupansky
>> <ja...@basetechnology.com> wrote:
>>> From the Solr 4.1 release notes:
>>>
>>> * Solr QParsers may now be directly invoked in the lucene query syntax
>>> via localParams and without the _query_ magic field hack.
>>> Example: foo AND {!term f=myfield v=$qq}
>>>
>>> -- Jack Krupansky
>>>
>>> -----Original Message----- From: Jack Krupansky
>>> Sent: Thursday, July 10, 2014 12:14 AM
>>>
>>> To: solr-user@lucene.apache.org
>>> Subject: Re: Complement of {!join}
>>>
>>> I think this is the Jira that implemented that feature:
>>> SOLR-4093 - localParams syntax for standard query parser
>>> https://issues.apache.org/jira/browse/SOLR-4093
>>>
>>> Yeah, I don't think this is fully documented anywhere, other than the Jira
>>> and the patch itself.
>>>
>>> I think I had finished my query parser doc in my e-book before 4.1 came out.
>>> This was the point where the "divorce" between the Lucene and Solr query
>>> parsers took place, because the feature needed to be added to the query
>>> parser grammar, but the Lucene guys objected to this "Solr feature."
>>>
>>> -- Jack Krupansky
>>>
>>> -----Original Message----- From: Alexandre Rafalovitch
>>> Sent: Wednesday, July 9, 2014 9:10 PM
>>> To: solr-user@lucene.apache.org
>>> Subject: Re: Complement of {!join}
>>>
>>> Ok, so cannot be eDisMax at the top.
>>>
>>> However, the point I really am trying to make does not seem to be in
>>> those links. All the examples of local parameters I have seen use them
>>> at the start of the query as a standalone component. I haven't seen
>>> examples where a query string contains several of them together and
>>> uses different query parsers. The only example I do remember seeing
>>> multiple query parsers used together was when each one of them was
>>> done separately in 'fq' clauses.
>>>
>>> Additionally, even now I don't know how the end of the content after
>>> the local parameter closing brace is determined. I used line breaks
>>> for my example, also (brackets) seem to work. But I don't remember
>>> seeing the exact rules.
>>>
>>> So, I still think the world could benefit from a very visible example
>>> showing multi-clause query with different sub-clauses using different
>>> query parsers. Perhaps even on that same linked page on Wiki. And/Or a
>>> presentation on "Did you know this about Solr?" at the next big
>>> conference.
>>>
>>> Regards,
>>>  Alex.
>>>
>>> Personal website: http://www.outerthoughts.com/
>>> Current project: http://www.solr-start.com/ - Accelerating your Solr
>>> proficiency
>>>
>>>
>>> On Thu, Jul 10, 2014 at 7:53 AM, Chris Hostetter
>>> <ho...@fucit.org> wrote:
>>>>
>>>> :
>>>> : Somebody (with more knowledge) should write up an in-depth article on
>>>> : this issue and whether the parent parser has to be default (lucene) or
>>>> : whatever.
>>>>
>>>> It's a feature of Solr's standard query parser...
>>>>
>>>> https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing
>>>> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser
>>>>
>>>> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser
>>>>
>>>>
>>>>
>>>> -Hoss
>>>> http://www.lucidworks.com/
>>>
>>>
>

Re: Complement of {!join}

Posted by Erik Hatcher <er...@gmail.com>.
Yeah, using multiple _query_’s has always been possible.  _query_ is just a special field name that gets interpreted specially.  Same with _val_ for function queries.

It’s a feature that’s been leveraged and “documented” (by way of presentation materials and blogs, at least) such as:

  - http://www.slideshare.net/erikhatcher/solr-query-parsing (slides 6 and 11)
  - http://www.slideshare.net/erikhatcher/solr-black-belt-preconference (slide 35)
  - http://searchhub.org/2009/03/31/nested-queries-in-solr/

My favorite example of this is Stanford’s library advanced search - http://searchworks.stanford.edu/advanced - where it uses a different dismax “sub”query for each field (which actually corresponds to multiple underlying Solr fields each).

Best,
	Erik



On Jul 10, 2014, at 12:19 AM, Alexandre Rafalovitch <ar...@gmail.com> wrote:

> Well, even JIRA and the release notes concentrates on a replacement of
> _query_ with {!}. But not about having multiple of them. Was it
> possible to have multiple _query_ segments in one 'q' query? I was not
> aware of that either.
> 
> Basically, I am suggesting that somebody who knows this in depth
> should write an article. I feel it is a powerful feature of Solr, but
> I was even hesitant to use it in my own config because all the online
> examples were for a single-use.
> 
> Regards,
>   Alex.
> Personal website: http://www.outerthoughts.com/
> Current project: http://www.solr-start.com/ - Accelerating your Solr proficiency
> 
> 
> On Thu, Jul 10, 2014 at 11:18 AM, Jack Krupansky
> <ja...@basetechnology.com> wrote:
>> From the Solr 4.1 release notes:
>> 
>> * Solr QParsers may now be directly invoked in the lucene query syntax
>> via localParams and without the _query_ magic field hack.
>> Example: foo AND {!term f=myfield v=$qq}
>> 
>> -- Jack Krupansky
>> 
>> -----Original Message----- From: Jack Krupansky
>> Sent: Thursday, July 10, 2014 12:14 AM
>> 
>> To: solr-user@lucene.apache.org
>> Subject: Re: Complement of {!join}
>> 
>> I think this is the Jira that implemented that feature:
>> SOLR-4093 - localParams syntax for standard query parser
>> https://issues.apache.org/jira/browse/SOLR-4093
>> 
>> Yeah, I don't think this is fully documented anywhere, other than the Jira
>> and the patch itself.
>> 
>> I think I had finished my query parser doc in my e-book before 4.1 came out.
>> This was the point where the "divorce" between the Lucene and Solr query
>> parsers took place, because the feature needed to be added to the query
>> parser grammar, but the Lucene guys objected to this "Solr feature."
>> 
>> -- Jack Krupansky
>> 
>> -----Original Message----- From: Alexandre Rafalovitch
>> Sent: Wednesday, July 9, 2014 9:10 PM
>> To: solr-user@lucene.apache.org
>> Subject: Re: Complement of {!join}
>> 
>> Ok, so cannot be eDisMax at the top.
>> 
>> However, the point I really am trying to make does not seem to be in
>> those links. All the examples of local parameters I have seen use them
>> at the start of the query as a standalone component. I haven't seen
>> examples where a query string contains several of them together and
>> uses different query parsers. The only example I do remember seeing
>> multiple query parsers used together was when each one of them was
>> done separately in 'fq' clauses.
>> 
>> Additionally, even now I don't know how the end of the content after
>> the local parameter closing brace is determined. I used line breaks
>> for my example, also (brackets) seem to work. But I don't remember
>> seeing the exact rules.
>> 
>> So, I still think the world could benefit from a very visible example
>> showing multi-clause query with different sub-clauses using different
>> query parsers. Perhaps even on that same linked page on Wiki. And/Or a
>> presentation on "Did you know this about Solr?" at the next big
>> conference.
>> 
>> Regards,
>>  Alex.
>> 
>> Personal website: http://www.outerthoughts.com/
>> Current project: http://www.solr-start.com/ - Accelerating your Solr
>> proficiency
>> 
>> 
>> On Thu, Jul 10, 2014 at 7:53 AM, Chris Hostetter
>> <ho...@fucit.org> wrote:
>>> 
>>> :
>>> : Somebody (with more knowledge) should write up an in-depth article on
>>> : this issue and whether the parent parser has to be default (lucene) or
>>> : whatever.
>>> 
>>> It's a feature of Solr's standard query parser...
>>> 
>>> https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing
>>> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser
>>> 
>>> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser
>>> 
>>> 
>>> 
>>> -Hoss
>>> http://www.lucidworks.com/
>> 
>> 


Re: Complement of {!join}

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Well, even JIRA and the release notes concentrates on a replacement of
_query_ with {!}. But not about having multiple of them. Was it
possible to have multiple _query_ segments in one 'q' query? I was not
aware of that either.

Basically, I am suggesting that somebody who knows this in depth
should write an article. I feel it is a powerful feature of Solr, but
I was even hesitant to use it in my own config because all the online
examples were for a single-use.

Regards,
   Alex.
Personal website: http://www.outerthoughts.com/
Current project: http://www.solr-start.com/ - Accelerating your Solr proficiency


On Thu, Jul 10, 2014 at 11:18 AM, Jack Krupansky
<ja...@basetechnology.com> wrote:
> From the Solr 4.1 release notes:
>
> * Solr QParsers may now be directly invoked in the lucene query syntax
>  via localParams and without the _query_ magic field hack.
>  Example: foo AND {!term f=myfield v=$qq}
>
> -- Jack Krupansky
>
> -----Original Message----- From: Jack Krupansky
> Sent: Thursday, July 10, 2014 12:14 AM
>
> To: solr-user@lucene.apache.org
> Subject: Re: Complement of {!join}
>
> I think this is the Jira that implemented that feature:
> SOLR-4093 - localParams syntax for standard query parser
> https://issues.apache.org/jira/browse/SOLR-4093
>
> Yeah, I don't think this is fully documented anywhere, other than the Jira
> and the patch itself.
>
> I think I had finished my query parser doc in my e-book before 4.1 came out.
> This was the point where the "divorce" between the Lucene and Solr query
> parsers took place, because the feature needed to be added to the query
> parser grammar, but the Lucene guys objected to this "Solr feature."
>
> -- Jack Krupansky
>
> -----Original Message----- From: Alexandre Rafalovitch
> Sent: Wednesday, July 9, 2014 9:10 PM
> To: solr-user@lucene.apache.org
> Subject: Re: Complement of {!join}
>
> Ok, so cannot be eDisMax at the top.
>
> However, the point I really am trying to make does not seem to be in
> those links. All the examples of local parameters I have seen use them
> at the start of the query as a standalone component. I haven't seen
> examples where a query string contains several of them together and
> uses different query parsers. The only example I do remember seeing
> multiple query parsers used together was when each one of them was
> done separately in 'fq' clauses.
>
> Additionally, even now I don't know how the end of the content after
> the local parameter closing brace is determined. I used line breaks
> for my example, also (brackets) seem to work. But I don't remember
> seeing the exact rules.
>
> So, I still think the world could benefit from a very visible example
> showing multi-clause query with different sub-clauses using different
> query parsers. Perhaps even on that same linked page on Wiki. And/Or a
> presentation on "Did you know this about Solr?" at the next big
> conference.
>
> Regards,
>   Alex.
>
> Personal website: http://www.outerthoughts.com/
> Current project: http://www.solr-start.com/ - Accelerating your Solr
> proficiency
>
>
> On Thu, Jul 10, 2014 at 7:53 AM, Chris Hostetter
> <ho...@fucit.org> wrote:
>>
>> :
>> : Somebody (with more knowledge) should write up an in-depth article on
>> : this issue and whether the parent parser has to be default (lucene) or
>> : whatever.
>>
>> It's a feature of Solr's standard query parser...
>>
>> https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing
>> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser
>>
>> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser
>>
>>
>>
>> -Hoss
>> http://www.lucidworks.com/
>
>

Re: Complement of {!join}

Posted by Jack Krupansky <ja...@basetechnology.com>.
>From the Solr 4.1 release notes:

* Solr QParsers may now be directly invoked in the lucene query syntax
  via localParams and without the _query_ magic field hack.
  Example: foo AND {!term f=myfield v=$qq}

-- Jack Krupansky

-----Original Message----- 
From: Jack Krupansky
Sent: Thursday, July 10, 2014 12:14 AM
To: solr-user@lucene.apache.org
Subject: Re: Complement of {!join}

I think this is the Jira that implemented that feature:
SOLR-4093 - localParams syntax for standard query parser
https://issues.apache.org/jira/browse/SOLR-4093

Yeah, I don't think this is fully documented anywhere, other than the Jira
and the patch itself.

I think I had finished my query parser doc in my e-book before 4.1 came out.
This was the point where the "divorce" between the Lucene and Solr query
parsers took place, because the feature needed to be added to the query
parser grammar, but the Lucene guys objected to this "Solr feature."

-- Jack Krupansky

-----Original Message----- 
From: Alexandre Rafalovitch
Sent: Wednesday, July 9, 2014 9:10 PM
To: solr-user@lucene.apache.org
Subject: Re: Complement of {!join}

Ok, so cannot be eDisMax at the top.

However, the point I really am trying to make does not seem to be in
those links. All the examples of local parameters I have seen use them
at the start of the query as a standalone component. I haven't seen
examples where a query string contains several of them together and
uses different query parsers. The only example I do remember seeing
multiple query parsers used together was when each one of them was
done separately in 'fq' clauses.

Additionally, even now I don't know how the end of the content after
the local parameter closing brace is determined. I used line breaks
for my example, also (brackets) seem to work. But I don't remember
seeing the exact rules.

So, I still think the world could benefit from a very visible example
showing multi-clause query with different sub-clauses using different
query parsers. Perhaps even on that same linked page on Wiki. And/Or a
presentation on "Did you know this about Solr?" at the next big
conference.

Regards,
   Alex.

Personal website: http://www.outerthoughts.com/
Current project: http://www.solr-start.com/ - Accelerating your Solr
proficiency


On Thu, Jul 10, 2014 at 7:53 AM, Chris Hostetter
<ho...@fucit.org> wrote:
> :
> : Somebody (with more knowledge) should write up an in-depth article on
> : this issue and whether the parent parser has to be default (lucene) or
> : whatever.
>
> It's a feature of Solr's standard query parser...
>
> https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing
> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser
> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser
>
>
>
> -Hoss
> http://www.lucidworks.com/ 


Re: Complement of {!join}

Posted by Jack Krupansky <ja...@basetechnology.com>.
I think this is the Jira that implemented that feature:
SOLR-4093 - localParams syntax for standard query parser
https://issues.apache.org/jira/browse/SOLR-4093

Yeah, I don't think this is fully documented anywhere, other than the Jira 
and the patch itself.

I think I had finished my query parser doc in my e-book before 4.1 came out. 
This was the point where the "divorce" between the Lucene and Solr query 
parsers took place, because the feature needed to be added to the query 
parser grammar, but the Lucene guys objected to this "Solr feature."

-- Jack Krupansky

-----Original Message----- 
From: Alexandre Rafalovitch
Sent: Wednesday, July 9, 2014 9:10 PM
To: solr-user@lucene.apache.org
Subject: Re: Complement of {!join}

Ok, so cannot be eDisMax at the top.

However, the point I really am trying to make does not seem to be in
those links. All the examples of local parameters I have seen use them
at the start of the query as a standalone component. I haven't seen
examples where a query string contains several of them together and
uses different query parsers. The only example I do remember seeing
multiple query parsers used together was when each one of them was
done separately in 'fq' clauses.

Additionally, even now I don't know how the end of the content after
the local parameter closing brace is determined. I used line breaks
for my example, also (brackets) seem to work. But I don't remember
seeing the exact rules.

So, I still think the world could benefit from a very visible example
showing multi-clause query with different sub-clauses using different
query parsers. Perhaps even on that same linked page on Wiki. And/Or a
presentation on "Did you know this about Solr?" at the next big
conference.

Regards,
   Alex.

Personal website: http://www.outerthoughts.com/
Current project: http://www.solr-start.com/ - Accelerating your Solr 
proficiency


On Thu, Jul 10, 2014 at 7:53 AM, Chris Hostetter
<ho...@fucit.org> wrote:
> :
> : Somebody (with more knowledge) should write up an in-depth article on
> : this issue and whether the parent parser has to be default (lucene) or
> : whatever.
>
> It's a feature of Solr's standard query parser...
>
> https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing
> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser
> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser
>
>
>
> -Hoss
> http://www.lucidworks.com/ 


Re: Complement of {!join}

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Ok, so cannot be eDisMax at the top.

However, the point I really am trying to make does not seem to be in
those links. All the examples of local parameters I have seen use them
at the start of the query as a standalone component. I haven't seen
examples where a query string contains several of them together and
uses different query parsers. The only example I do remember seeing
multiple query parsers used together was when each one of them was
done separately in 'fq' clauses.

Additionally, even now I don't know how the end of the content after
the local parameter closing brace is determined. I used line breaks
for my example, also (brackets) seem to work. But I don't remember
seeing the exact rules.

So, I still think the world could benefit from a very visible example
showing multi-clause query with different sub-clauses using different
query parsers. Perhaps even on that same linked page on Wiki. And/Or a
presentation on "Did you know this about Solr?" at the next big
conference.

Regards,
   Alex.

Personal website: http://www.outerthoughts.com/
Current project: http://www.solr-start.com/ - Accelerating your Solr proficiency


On Thu, Jul 10, 2014 at 7:53 AM, Chris Hostetter
<ho...@fucit.org> wrote:
> :
> : Somebody (with more knowledge) should write up an in-depth article on
> : this issue and whether the parent parser has to be default (lucene) or
> : whatever.
>
> It's a feature of Solr's standard query parser...
>
> https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing
> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser
> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser
>
>
>
> -Hoss
> http://www.lucidworks.com/

Re: Complement of {!join}

Posted by Chris Hostetter <ho...@fucit.org>.
: 
: Somebody (with more knowledge) should write up an in-depth article on
: this issue and whether the parent parser has to be default (lucene) or
: whatever.

It's a feature of Solr's standard query parser...

https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing
https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser
https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser



-Hoss
http://www.lucidworks.com/

Re: Complement of {!join}

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
I think any sub-clause can use a local syntax and branch off into
different query parsers. I could not find any examples of it either
but really need to do an advanced search and came up with this:

<str name="q">
   {!switch case='*:*' default=$q_lastName v=$lastName}
   AND {!switch case='*:*' default=$q_firstName v=$firstName}
   AND {!switch case='*:*' default=$q_organizationalUnit v=$organizationalUnit}
   ...
</str>
Full example: https://gist.github.com/arafalov/5e04884e5aefaf46678c

Somebody (with more knowledge) should write up an in-depth article on
this issue and whether the parent parser has to be default (lucene) or
whatever.

Regards,
   Alex.
Personal website: http://www.outerthoughts.com/
Current project: http://www.solr-start.com/ - Accelerating your Solr proficiency


On Wed, Jul 9, 2014 at 11:26 PM, Bruce Johnson <hb...@gmail.com> wrote:
> Thank you so much for the quick reply, Erik. And wow: I didn't realize you
> could use join that fluidly. Very nice.
>
> Is there some trove of Solr doc that I'm missing where this natural syntax
> is explained? I wouldn't have asked such a basic question except that I
> found no evidence that this was possible.
>
>
>
>
> On Wed, Jul 9, 2014 at 12:07 PM, Erik Hatcher <er...@gmail.com>
> wrote:
>
>> Maybe something like q=*:* AND NOT {!join … } would do the trick?  (it’ll
>> depend on your version of Solr for support of the {!…} more natural nested
>> queries)
>>
>>         Erik
>>
>> On Jul 9, 2014, at 11:24 AM, Bruce Johnson <hb...@gmail.com>
>> wrote:
>>
>> > === Short-version ===
>> > Is there a way to join on the complement of a query? I want the only the
>> > Solr documents for which the nested join query does not match.
>> >
>> > === Longer-version ===
>> > Query-time joins with {!join} are great at modeling the SQL equivalent of
>> > patterns like this:
>> >
>> > SELECT book_name FROM books WHERE id
>> > IN (SELECT book_id FROM chapters WHERE chapter_title = "Foo")
>> >
>> > This would find the name of books having chapters entitled "Foo".
>> (Assuming
>> > the chapters table have the column 'book_id' that point back to the book
>> > record containing them.)
>> >
>> > That's great.
>> >
>> > Is there a way in Solr to query for the complement of that? In SQL terms,
>> > this:
>> >
>> > SELECT book_name FROM books WHERE id
>> > NOT IN (SELECT book_id FROM chapters WHERE chapter_title = "Foo")
>> >
>> > This would find books that do not have chapters entitled "Foo".
>> >
>> > It isn't the same as querying (in Solr terms) for something like
>> >
>> > {!join to=id from=book_id}-chapter_title:"Foo" // note the negation
>> >
>> > because it would still match other chapters in the same book that are not
>> > entitled "Foo", causing the join to still identify the book based on its
>> > other non-Foo chapters.
>> >
>> > Any advice would be greatly appreciated. I'm also open to other ways of
>> > thinking about the problem. Perhaps there are alternative indexing
>> patterns
>> > that could accomplish the same goal.
>> >
>> > Many thanks,
>> > Bruce
>>
>>

Re: Complement of {!join}

Posted by Bruce Johnson <hb...@gmail.com>.
Thank you so much for the quick reply, Erik. And wow: I didn't realize you
could use join that fluidly. Very nice.

Is there some trove of Solr doc that I'm missing where this natural syntax
is explained? I wouldn't have asked such a basic question except that I
found no evidence that this was possible.




On Wed, Jul 9, 2014 at 12:07 PM, Erik Hatcher <er...@gmail.com>
wrote:

> Maybe something like q=*:* AND NOT {!join … } would do the trick?  (it’ll
> depend on your version of Solr for support of the {!…} more natural nested
> queries)
>
>         Erik
>
> On Jul 9, 2014, at 11:24 AM, Bruce Johnson <hb...@gmail.com>
> wrote:
>
> > === Short-version ===
> > Is there a way to join on the complement of a query? I want the only the
> > Solr documents for which the nested join query does not match.
> >
> > === Longer-version ===
> > Query-time joins with {!join} are great at modeling the SQL equivalent of
> > patterns like this:
> >
> > SELECT book_name FROM books WHERE id
> > IN (SELECT book_id FROM chapters WHERE chapter_title = "Foo")
> >
> > This would find the name of books having chapters entitled "Foo".
> (Assuming
> > the chapters table have the column 'book_id' that point back to the book
> > record containing them.)
> >
> > That's great.
> >
> > Is there a way in Solr to query for the complement of that? In SQL terms,
> > this:
> >
> > SELECT book_name FROM books WHERE id
> > NOT IN (SELECT book_id FROM chapters WHERE chapter_title = "Foo")
> >
> > This would find books that do not have chapters entitled "Foo".
> >
> > It isn't the same as querying (in Solr terms) for something like
> >
> > {!join to=id from=book_id}-chapter_title:"Foo" // note the negation
> >
> > because it would still match other chapters in the same book that are not
> > entitled "Foo", causing the join to still identify the book based on its
> > other non-Foo chapters.
> >
> > Any advice would be greatly appreciated. I'm also open to other ways of
> > thinking about the problem. Perhaps there are alternative indexing
> patterns
> > that could accomplish the same goal.
> >
> > Many thanks,
> > Bruce
>
>

Re: Complement of {!join}

Posted by Erik Hatcher <er...@gmail.com>.
Maybe something like q=*:* AND NOT {!join … } would do the trick?  (it’ll depend on your version of Solr for support of the {!…} more natural nested queries)

	Erik

On Jul 9, 2014, at 11:24 AM, Bruce Johnson <hb...@gmail.com> wrote:

> === Short-version ===
> Is there a way to join on the complement of a query? I want the only the
> Solr documents for which the nested join query does not match.
> 
> === Longer-version ===
> Query-time joins with {!join} are great at modeling the SQL equivalent of
> patterns like this:
> 
> SELECT book_name FROM books WHERE id
> IN (SELECT book_id FROM chapters WHERE chapter_title = "Foo")
> 
> This would find the name of books having chapters entitled "Foo". (Assuming
> the chapters table have the column 'book_id' that point back to the book
> record containing them.)
> 
> That's great.
> 
> Is there a way in Solr to query for the complement of that? In SQL terms,
> this:
> 
> SELECT book_name FROM books WHERE id
> NOT IN (SELECT book_id FROM chapters WHERE chapter_title = "Foo")
> 
> This would find books that do not have chapters entitled "Foo".
> 
> It isn't the same as querying (in Solr terms) for something like
> 
> {!join to=id from=book_id}-chapter_title:"Foo" // note the negation
> 
> because it would still match other chapters in the same book that are not
> entitled "Foo", causing the join to still identify the book based on its
> other non-Foo chapters.
> 
> Any advice would be greatly appreciated. I'm also open to other ways of
> thinking about the problem. Perhaps there are alternative indexing patterns
> that could accomplish the same goal.
> 
> Many thanks,
> Bruce