You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Christoph Kaser <lu...@iconparc.de> on 2012/05/23 18:22:18 UTC

ToParentBlockJoinQuery and grand-children

Hello,

I would like to use the ToParentBlockJoinQuery and its collector to 
query a document with children and grand children, but I can't figure 
out how to get the document ids that represent grand children.

I know how to build the query and get the parent and child documents:


/****Example code start*****/
Query grandChildQuery=new TermQuery(new Term("color", "red"));
Filter childFilter = new CachingWrapperFilter(new RawTermFilter(new 
Term("type","child")), DeletesMode.IGNORE);
ToParentBlockJoinQuery grandchildJoinQuery = new 
ToParentBlockJoinQuery(grandChildQuery, childFilter, ScoreMode.Max);

BooleanQuery childQuery= new BooleanQuery();
childQuery.add(grandchildJoinQuery, Occur.MUST);
childQuery.add(new TermQuery(new Term("shape", "round")), Occur.MUST);

Filter parentFilter = new CachingWrapperFilter(new RawTermFilter(new 
Term("type","parent")), DeletesMode.IGNORE);
ToParentBlockJoinQuery childJoinQuery = new 
ToParentBlockJoinQuery(childQuery, parentFilter, ScoreMode.Max);

parentQuery=new BooleanQuery();
parentQuery.add(childJoinQuery, Occur.MUST);
parentQuery.add(new TermQuery(new Term("name", "test")), Occur.MUST);

ToParentBlockJoinCollector parentCollector= new 
ToParentBlockJoinCollector(Sort.RELEVANCE, 30, true, true);
searcher.search(parentQuery, null, parentCollector);
TopGroups<Integer> topGroups = 
parentCollector.getTopGroups(childJoinQuery, null, 0, 20, 0, false);

/****Example code end*****/

Now topGroups contains the parents document ids, and the child document 
ids. But how can I get the grandchild document ids for a given child 
document id? Do I have to call

TopGroups<Integer> childTopGroups = 
parentCollector.getTopGroups(grandchildJoinQuery , null, 0, 20, 0, false);

and match the document ids by hand? If so, is there a guarantee that 
they will be in the same order as I get them in the topgroups, or will I 
have to iterate over all childTopGroups until I find the right document id?

Does anyone have example code for nested joins?

Thanks in advance,
Christoph





---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: ToParentBlockJoinQuery and grand-children

Posted by Christoph Kaser <lu...@iconparc.de>.
Hi Mike,

unfortunately, you were right about only getting the last child's 
grandchildren. Furthermore, the groups have wrong groupValues: They are 
the document id of the previous parent, not the child. I have opened an 
issue:

https://issues.apache.org/jira/browse/LUCENE-4076

I also created the issue for the missing access to the computed scores:

https://issues.apache.org/jira/browse/LUCENE-4077

Regards,
Christoph



Am 24.05.2012 18:32, schrieb Michael McCandless:
> On Thu, May 24, 2012 at 11:48 AM, Christoph Kaser
> <lu...@iconparc.de>  wrote:
>
>> thank you for your response. Unfortunately, I won't be able to try this
>> today, but I should be able to try it in the next few days. If I find the
>> bug you described, I will open an issue.
> Thanks!
>
>> On a somewhat related note, is there a way to get the scores for the parent
>> documents from the ToParentBlockJoinCollector? I can tell the collector to
>> track the scores and the max score, but I did not find a way to retrieve
>> either the parent scores nor the max score (of the parent documents).
> Hmmm... so ToParentBlockJoinCollector does track the maxScore and
> score of each parent hit, but it looks like it never makes those
> available in the TopGroups it returns!  Silly.  Can you open a
> separate issue for that?  Thanks.
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: ToParentBlockJoinQuery and grand-children

Posted by Michael McCandless <lu...@mikemccandless.com>.
On Thu, May 24, 2012 at 11:48 AM, Christoph Kaser
<lu...@iconparc.de> wrote:

> thank you for your response. Unfortunately, I won't be able to try this
> today, but I should be able to try it in the next few days. If I find the
> bug you described, I will open an issue.

Thanks!

> On a somewhat related note, is there a way to get the scores for the parent
> documents from the ToParentBlockJoinCollector? I can tell the collector to
> track the scores and the max score, but I did not find a way to retrieve
> either the parent scores nor the max score (of the parent documents).

Hmmm... so ToParentBlockJoinCollector does track the maxScore and
score of each parent hit, but it looks like it never makes those
available in the TopGroups it returns!  Silly.  Can you open a
separate issue for that?  Thanks.

Mike McCandless

http://blog.mikemccandless.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: ToParentBlockJoinQuery and grand-children

Posted by Christoph Kaser <lu...@iconparc.de>.
Hello Mike,

thank you for your response. Unfortunately, I won't be able to try this 
today, but I should be able to try it in the next few days. If I find 
the bug you described, I will open an issue.

On a somewhat related note, is there a way to get the scores for the 
parent documents from the ToParentBlockJoinCollector? I can tell the 
collector to track the scores and the max score, but I did not find a 
way to retrieve either the parent scores nor the max score (of the 
parent documents).

Christoph Kaser

Am 23.05.2012 20:10, schrieb Michael McCandless:
> You do have to call getTopGroups for each grandchild query, and the
> order should match the TopGroups you got for the children
>
> However .... looking at the code, I suspect there's a bug... by the
> time the collector collects the parent hit, some of the grand children
> will have been discarded.  I suspect you'll only get back
> grandchildren for the last child docID under each parent docID's
> group.  Are you seeing that?
>
> Tricky... can you open an issue?
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
> On Wed, May 23, 2012 at 12:22 PM, Christoph Kaser
> <lu...@iconparc.de>  wrote:
>> Hello,
>>
>> I would like to use the ToParentBlockJoinQuery and its collector to query a
>> document with children and grand children, but I can't figure out how to get
>> the document ids that represent grand children.
>>
>> I know how to build the query and get the parent and child documents:
>>
>>
>> /****Example code start*****/
>> Query grandChildQuery=new TermQuery(new Term("color", "red"));
>> Filter childFilter = new CachingWrapperFilter(new RawTermFilter(new
>> Term("type","child")), DeletesMode.IGNORE);
>> ToParentBlockJoinQuery grandchildJoinQuery = new
>> ToParentBlockJoinQuery(grandChildQuery, childFilter, ScoreMode.Max);
>>
>> BooleanQuery childQuery= new BooleanQuery();
>> childQuery.add(grandchildJoinQuery, Occur.MUST);
>> childQuery.add(new TermQuery(new Term("shape", "round")), Occur.MUST);
>>
>> Filter parentFilter = new CachingWrapperFilter(new RawTermFilter(new
>> Term("type","parent")), DeletesMode.IGNORE);
>> ToParentBlockJoinQuery childJoinQuery = new
>> ToParentBlockJoinQuery(childQuery, parentFilter, ScoreMode.Max);
>>
>> parentQuery=new BooleanQuery();
>> parentQuery.add(childJoinQuery, Occur.MUST);
>> parentQuery.add(new TermQuery(new Term("name", "test")), Occur.MUST);
>>
>> ToParentBlockJoinCollector parentCollector= new
>> ToParentBlockJoinCollector(Sort.RELEVANCE, 30, true, true);
>> searcher.search(parentQuery, null, parentCollector);
>> TopGroups<Integer>  topGroups = parentCollector.getTopGroups(childJoinQuery,
>> null, 0, 20, 0, false);
>>
>> /****Example code end*****/
>>
>> Now topGroups contains the parents document ids, and the child document ids.
>> But how can I get the grandchild document ids for a given child document id?
>> Do I have to call
>>
>> TopGroups<Integer>  childTopGroups =
>> parentCollector.getTopGroups(grandchildJoinQuery , null, 0, 20, 0, false);
>>
>> and match the document ids by hand? If so, is there a guarantee that they
>> will be in the same order as I get them in the topgroups, or will I have to
>> iterate over all childTopGroups until I find the right document id?
>>
>> Does anyone have example code for nested joins?
>>
>> Thanks in advance,
>> Christoph
>>
>>
>>
>>






---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: ToParentBlockJoinQuery and grand-children

Posted by Michael McCandless <lu...@mikemccandless.com>.
You do have to call getTopGroups for each grandchild query, and the
order should match the TopGroups you got for the children

However .... looking at the code, I suspect there's a bug... by the
time the collector collects the parent hit, some of the grand children
will have been discarded.  I suspect you'll only get back
grandchildren for the last child docID under each parent docID's
group.  Are you seeing that?

Tricky... can you open an issue?

Mike McCandless

http://blog.mikemccandless.com

On Wed, May 23, 2012 at 12:22 PM, Christoph Kaser
<lu...@iconparc.de> wrote:
> Hello,
>
> I would like to use the ToParentBlockJoinQuery and its collector to query a
> document with children and grand children, but I can't figure out how to get
> the document ids that represent grand children.
>
> I know how to build the query and get the parent and child documents:
>
>
> /****Example code start*****/
> Query grandChildQuery=new TermQuery(new Term("color", "red"));
> Filter childFilter = new CachingWrapperFilter(new RawTermFilter(new
> Term("type","child")), DeletesMode.IGNORE);
> ToParentBlockJoinQuery grandchildJoinQuery = new
> ToParentBlockJoinQuery(grandChildQuery, childFilter, ScoreMode.Max);
>
> BooleanQuery childQuery= new BooleanQuery();
> childQuery.add(grandchildJoinQuery, Occur.MUST);
> childQuery.add(new TermQuery(new Term("shape", "round")), Occur.MUST);
>
> Filter parentFilter = new CachingWrapperFilter(new RawTermFilter(new
> Term("type","parent")), DeletesMode.IGNORE);
> ToParentBlockJoinQuery childJoinQuery = new
> ToParentBlockJoinQuery(childQuery, parentFilter, ScoreMode.Max);
>
> parentQuery=new BooleanQuery();
> parentQuery.add(childJoinQuery, Occur.MUST);
> parentQuery.add(new TermQuery(new Term("name", "test")), Occur.MUST);
>
> ToParentBlockJoinCollector parentCollector= new
> ToParentBlockJoinCollector(Sort.RELEVANCE, 30, true, true);
> searcher.search(parentQuery, null, parentCollector);
> TopGroups<Integer> topGroups = parentCollector.getTopGroups(childJoinQuery,
> null, 0, 20, 0, false);
>
> /****Example code end*****/
>
> Now topGroups contains the parents document ids, and the child document ids.
> But how can I get the grandchild document ids for a given child document id?
> Do I have to call
>
> TopGroups<Integer> childTopGroups =
> parentCollector.getTopGroups(grandchildJoinQuery , null, 0, 20, 0, false);
>
> and match the document ids by hand? If so, is there a guarantee that they
> will be in the same order as I get them in the topgroups, or will I have to
> iterate over all childTopGroups until I find the right document id?
>
> Does anyone have example code for nested joins?
>
> Thanks in advance,
> Christoph
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org