lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gregory Dearing <>
Subject Re: Question about JoinUtil
Date Wed, 17 Dec 2014 00:49:35 GMT

Lucene isn't relational at heart and may not be the right tool for
what you're trying to accomplish. Note that JoinQuery doesn't join
'left' and 'right' answers; rather it transforms a 'left' answerset
into a 'right' answerset.

JoinQuery is able to perform this transformation with a single extra
search, which wouldn't be possible if it accepted a 'toQuery'

That being said, here are some suggestions...

1. If all you really need is data from the 'right' set of answers (the
joined TO set), then you can just add more queries to perform
right-hand filtering.

   createJoinQuery(...) AND TermQuery("country", "CA*")

Note that '' in your SQL example is no longer available.

2. If you really need to filter both sides, and you need to return
data from both sides, it probably requires some programming.  In

  leftAnswerSet =

  foreach leftAnswer in leftAnswerSet {
    rightAnswers = AND TermQuery("country", "CA*"))
    results.add([leftAnswer, rightAnswers])

This is obviously not very efficient, but I think it probably
represents what JoinQuery would look like if it allowed a 'toQuery'
capability and returned data from both sides of the join.

3. If you can denormalize your data into hierarchies, then you could
use index-time joining (BlockJoin) for better performance and easier
collecting of your grouped data.  This is really limiting if your
relationships are truly many to many.

Hope that helps,

On Tue, Dec 16, 2014 at 10:46 AM, Glen Newton <> wrote:
> Anyone?
> On Thu, Dec 11, 2014 at 2:53 PM, Glen Newton <> wrote:
>> Is there any reason JoinUtil (below) does not have a 'Query toQuery'
>> available? I was wanting to filter on the 'to' side as well. I feel I
>> am missing something here.
>> To make sure this is not an XY problem, here is my use case:
>> I have a many-to-many relationship. The left, join, and right 'table'
>> objects are all indexed in the same lucene index, with a field 'type'
>> to distinguish them.
>> I need to do something like this:
>> select, from left, join, right where
>> left.type="fooType" and right.type="barType" and
>> and and"Fred*" and
>> Is JoinUtil the way to go?
>> Or should I roll my own?
>>    Or am I indexing/using-Lucene incorrectly, thinking relational when
>> a different way to index or query would be better in an idiomatic
>> Lucene manner?  :-)
>> Thanks,
>> Glen
>> public static Query createJoinQuery(String fromField,
>>                     boolean multipleValuesPerDocument,
>>                     String toField,
>>                     Query fromQuery,
>>                     IndexSearcher fromSearcher,
>>                     ScoreMode scoreMode)
>>                              throws IOException
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message