Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: Java-User

ToParentBlockJoinQuery and grand-children

 

 

Lucene java-user RSS feed   Index | Next | Previous | View Threaded


lucene_list at iconparc

May 23, 2012, 9:22 AM

Post #1 of 5 (234 views)
Permalink
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 [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


lucene at mikemccandless

May 23, 2012, 11:10 AM

Post #2 of 5 (225 views)
Permalink
Re: ToParentBlockJoinQuery and grand-children [In reply to]

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
<lucene_list [at] iconparc> 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 [at] lucene
> For additional commands, e-mail: java-user-help [at] lucene
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


lucene_list at iconparc

May 24, 2012, 8:48 AM

Post #3 of 5 (223 views)
Permalink
Re: ToParentBlockJoinQuery and grand-children [In reply to]

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
> <lucene_list [at] iconparc> 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 [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


lucene at mikemccandless

May 24, 2012, 9:32 AM

Post #4 of 5 (226 views)
Permalink
Re: ToParentBlockJoinQuery and grand-children [In reply to]

On Thu, May 24, 2012 at 11:48 AM, Christoph Kaser
<lucene_list [at] iconparc> 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 [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


lucene_list at iconparc

May 25, 2012, 2:51 AM

Post #5 of 5 (218 views)
Permalink
Re: ToParentBlockJoinQuery and grand-children [In reply to]

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
> <lucene_list [at] iconparc> 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 [at] lucene
For additional commands, e-mail: java-user-help [at] lucene

Lucene java-user RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.