You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kr...@apache.org on 2016/10/20 19:31:40 UTC
[31/50] [abbrv] lucene-solr:jira/solr-8593: LUCENE-7497: add test case
LUCENE-7497: add test case
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b78f2219
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b78f2219
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b78f2219
Branch: refs/heads/jira/solr-8593
Commit: b78f2219f45ca64c6a4b7261a87fae89477ec26f
Parents: 3be6701
Author: Mike McCandless <mi...@apache.org>
Authored: Tue Oct 18 14:02:02 2016 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Tue Oct 18 14:02:40 2016 -0400
----------------------------------------------------------------------
.../search/join/ToParentBlockJoinQuery.java | 2 +-
.../lucene/search/join/TestBlockJoin.java | 66 ++++++++++++++++++++
2 files changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b78f2219/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
index 3abdeeb..432ebcc 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
@@ -203,7 +203,7 @@ public class ToParentBlockJoinQuery extends Query {
public abstract int[] swapChildDocs(int[] other);
}
- static class BlockJoinScorer extends ChildrenMatchesScorer{
+ static class BlockJoinScorer extends ChildrenMatchesScorer {
private final Scorer childScorer;
private final BitSet parentBits;
private final ScoreMode scoreMode;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b78f2219/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
index af9ff5c..cf21fa4 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
@@ -187,7 +187,73 @@ public class TestBlockJoin extends LuceneTestCase {
dir.close();
}
+ // You must use ToParentBlockJoinSearcher if you want to do BQ SHOULD queries:
+ public void testBQShouldJoinedChild() throws Exception {
+ final Directory dir = newDirectory();
+ final RandomIndexWriter w = new RandomIndexWriter(random(), dir);
+
+ final List<Document> docs = new ArrayList<>();
+
+ docs.add(makeJob("java", 2007));
+ docs.add(makeJob("python", 2010));
+ docs.add(makeResume("Lisa", "United Kingdom"));
+ w.addDocuments(docs);
+
+ docs.clear();
+ docs.add(makeJob("ruby", 2005));
+ docs.add(makeJob("java", 2006));
+ docs.add(makeResume("Frank", "United States"));
+ w.addDocuments(docs);
+
+ IndexReader r = w.getReader();
+ w.close();
+ IndexSearcher s = new ToParentBlockJoinIndexSearcher(r);
+ //IndexSearcher s = newSearcher(r, false);
+ //IndexSearcher s = new IndexSearcher(r);
+
+ // Create a filter that defines "parent" documents in the index - in this case resumes
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
+ CheckJoinIndex.check(r, parentsFilter);
+
+ // Define child document criteria (finds an example of relevant work experience)
+ BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
+ childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
+ childQuery.add(new BooleanClause(IntPoint.newRangeQuery("year", 2006, 2011), Occur.MUST));
+
+ // Define parent document criteria (find a resident in the UK)
+ Query parentQuery = new TermQuery(new Term("country", "United Kingdom"));
+
+ // Wrap the child document query to 'join' any matches
+ // up to corresponding parent:
+ ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery.build(), parentsFilter, ScoreMode.Avg);
+
+ // Combine the parent and nested child queries into a single query for a candidate
+ BooleanQuery.Builder fullQuery = new BooleanQuery.Builder();
+ fullQuery.add(new BooleanClause(parentQuery, Occur.SHOULD));
+ fullQuery.add(new BooleanClause(childJoinQuery, Occur.SHOULD));
+
+ ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(Sort.RELEVANCE, 1, true, true);
+ s.search(fullQuery.build(), c);
+ TopGroups<Integer> results = c.getTopGroups(childJoinQuery, null, 0, 10, 0, true);
+ assertEquals(1, results.totalGroupedHitCount);
+ assertEquals(1, results.groups.length);
+ final GroupDocs<Integer> group = results.groups[0];
+ assertEquals(1, group.totalHits);
+ assertFalse(Float.isNaN(group.score));
+
+ Document childDoc = s.doc(group.scoreDocs[0].doc);
+ //System.out.println(" doc=" + group.scoreDocs[0].doc);
+ assertEquals("java", childDoc.get("skill"));
+ assertNotNull(group.groupValue);
+ Document parentDoc = s.doc(group.groupValue);
+ assertEquals("Lisa", parentDoc.get("name"));
+
+
+ r.close();
+ dir.close();
+ }
+
public void testSimple() throws Exception {
final Directory dir = newDirectory();