When doing nested (index-time) joins, ToParentBlockJoinCollector delivers incomplete information on the grand-children [LUCENE-4076]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
ToParentBlockJoinCollector.getTopGroups does not provide the correct answer when a query with nested ToParentBlockJoinCollectors is performed.
Given the following example query:
```Java
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);
```
This produces the correct results:
```Java
TopGroups childGroups = parentCollector.getTopGroups(childJoinQuery, null, 0, 20, 0, false);
```
However, this does not:
```Java
TopGroups grandChildGroups = parentCollector.getTopGroups(grandchildJoinQuery, null, 0, 20, 0, false);
```
The content of grandChildGroups is broken in the following ways:
- The groupValue is not the document id of the child document (which is the parent of a grandchild document), but the document id of the _previous_ matching parent document
- There are only as much GroupDocs as there are parent documents (not child documents), and they only contain the children of the last child document (but, as mentioned before, with the wrong groupValue).
---
Migrated from [LUCENE-4076](https://issues.apache.org/jira/browse/LUCENE-4076) by Christoph Kaser, updated Apr 08 2014
Contributor guide
Research direction
Start by reproducing the nested query in the issue with ToParentBlockJoinCollector.getTopGroups, comparing results for childJoinQuery and grandchildJoinQuery. Trace how the collector handles nested joins and verify that grandChildGroups uses each child document ID as groupValue and returns the correct GroupDocs for every child document.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100