Skip to content

Correctly handle MSM for nested disjunctions #50669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public String toString() {
Result getResult() {
List<Result> partialResults = new ArrayList<>();
if (terms.size() > 0) {
partialResults.add(conjunction ? handleConjunction(terms) : handleDisjunction(terms, minimumShouldMatch));
partialResults.addAll(terms);
}
if (children.isEmpty() == false) {
List<Result> childResults = children.stream().map(ResultBuilder::getResult).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,43 @@ public void testIntervalQueries() {
assertTermsEqual(result.extractions, new Term("field", "a"));
}

public void testRangeAndTermWithNestedMSM() {

Query q1 = new BooleanQuery.Builder()
.add(new TermQuery(new Term("f", "v3")), Occur.SHOULD)
.add(new BooleanQuery.Builder()
.add(new TermQuery(new Term("f", "n1")), Occur.SHOULD)
.build(), Occur.SHOULD)
.add(new TermQuery(new Term("f", "v4")), Occur.SHOULD)
.setMinimumNumberShouldMatch(2)
.build();

Result r1 = analyze(q1, Version.CURRENT);
assertEquals(2, r1.minimumShouldMatch);
assertThat(r1.extractions, hasSize(3));
assertFalse(r1.matchAllDocs);
assertTrue(r1.verified);

Query q = new BooleanQuery.Builder()
.add(IntPoint.newRangeQuery("i", 0, 10), Occur.FILTER)
.add(new TermQuery(new Term("f", "v1")), Occur.MUST)
.add(new TermQuery(new Term("f", "v2")), Occur.MUST)
.add(IntPoint.newRangeQuery("i", 2, 20), Occur.FILTER)
.add(new TermQuery(new Term("f", "v3")), Occur.SHOULD)
.add(new BooleanQuery.Builder()
.add(new TermQuery(new Term("f", "n1")), Occur.SHOULD)
.build(), Occur.SHOULD)
.add(new TermQuery(new Term("f", "v4")), Occur.SHOULD)
.setMinimumNumberShouldMatch(2)
.build();

Result r = analyze(q, Version.CURRENT);
assertThat(r.minimumShouldMatch, equalTo(5));
assertThat(r.extractions, hasSize(7));
assertFalse(r.matchAllDocs);
assertFalse(r.verified);
}

public void testCombinedRangeAndTermWithMinimumShouldMatch() {

Query disj = new BooleanQuery.Builder()
Expand Down