| diff --git a/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java |
| index a78cef3..0099404 100644 |
| --- a/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java |
| +++ b/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java |
| @@ -227,6 +227,9 @@ public class CommonTermsQuery extends Query { |
| return lowFreq; |
| } else { |
| query.add(highFreq, Occur.SHOULD); |
| + if (highFreqOccur == Occur.MUST) { |
| + query.setMinimumNumberShouldMatch(1); |
| + } |
| query.add(lowFreq, Occur.MUST); |
| query.setBoost(getBoost()); |
| return query; |
| diff --git a/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java b/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java |
| index 3cb8deb..de07ac6 100644 |
| --- a/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java |
| +++ b/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java |
| @@ -61,9 +61,9 @@ public class CommonTermsQueryTest extends LuceneTestCase { |
| Directory dir = newDirectory(); |
| MockAnalyzer analyzer = new MockAnalyzer(random()); |
| RandomIndexWriter w = new RandomIndexWriter(random(), dir, analyzer); |
| - String[] docs = new String[] {"this is the end of the world right", |
| + String[] docs = new String[] {"this is not the end of the world right", |
| "is this it or maybe not", |
| - "this is the end of the universe as we know it", |
| + "this is not the end of the universe as we know it", |
| "there is the famous restaurant at the end of the universe",}; |
| for (int i = 0; i < docs.length; i++) { |
| Document doc = new Document(); |
| @@ -124,8 +124,21 @@ public class CommonTermsQueryTest extends LuceneTestCase { |
| TopDocs search = s.search(query, 10); |
| assertEquals(search.totalHits, 1); |
| assertEquals("3", r.document(search.scoreDocs[0].doc).get("id")); |
| - |
| } |
| + |
| + { // low and high freq are mandatory |
| + CommonTermsQuery query = new CommonTermsQuery(Occur.MUST, Occur.MUST, |
| + random().nextBoolean() ? 2.0f : 0.5f); |
| + query.add(new Term("field", "is")); |
| + query.add(new Term("field", "this")); |
| + query.add(new Term("field", "not")); |
| + query.add(new Term("field", "universe")); |
| + |
| + TopDocs search = s.search(query, 10); |
| + assertEquals(search.totalHits, 1); |
| + assertEquals("2", r.document(search.scoreDocs[0].doc).get("id")); |
| + } |
| + |
| r.close(); |
| w.shutdown(); |
| dir.close(); |