mirror of
https://github.com/apache/lucene.git
synced 2025-02-08 02:58:58 +00:00
LUCENE-4571: fix rare test bug and beef up matching tests some more
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1459819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0e830fbae4
commit
786e3ddf22
@ -18,6 +18,7 @@ package org.apache.lucene.search;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -118,6 +119,7 @@ public class TestMinShouldMatch2 extends LuceneTestCase {
|
|||||||
private void assertNext(Scorer expected, Scorer actual) throws Exception {
|
private void assertNext(Scorer expected, Scorer actual) throws Exception {
|
||||||
if (actual == null) {
|
if (actual == null) {
|
||||||
assertEquals(DocIdSetIterator.NO_MORE_DOCS, expected.nextDoc());
|
assertEquals(DocIdSetIterator.NO_MORE_DOCS, expected.nextDoc());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
int doc;
|
int doc;
|
||||||
while ((doc = expected.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
|
while ((doc = expected.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
|
||||||
@ -129,6 +131,7 @@ public class TestMinShouldMatch2 extends LuceneTestCase {
|
|||||||
private void assertAdvance(Scorer expected, Scorer actual, int amount) throws Exception {
|
private void assertAdvance(Scorer expected, Scorer actual, int amount) throws Exception {
|
||||||
if (actual == null) {
|
if (actual == null) {
|
||||||
assertEquals(DocIdSetIterator.NO_MORE_DOCS, expected.nextDoc());
|
assertEquals(DocIdSetIterator.NO_MORE_DOCS, expected.nextDoc());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
int prevDoc = 0;
|
int prevDoc = 0;
|
||||||
int doc;
|
int doc;
|
||||||
@ -139,18 +142,101 @@ public class TestMinShouldMatch2 extends LuceneTestCase {
|
|||||||
assertEquals(DocIdSetIterator.NO_MORE_DOCS, actual.advance(prevDoc+amount));
|
assertEquals(DocIdSetIterator.NO_MORE_DOCS, actual.advance(prevDoc+amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** simple test for next() */
|
/** simple test for next(): minShouldMatch=2 on 3 terms (one common, one medium, one rare) */
|
||||||
public void testNext() throws Exception {
|
public void testNextCMR2() throws Exception {
|
||||||
Scorer expected = scorer(new String[] { "b", "f", "j" }, 2, true);
|
for (int common = 0; common < commonTerms.length; common++) {
|
||||||
Scorer actual = scorer(new String[] { "b", "f", "j" }, 2, false);
|
for (int medium = 0; medium < mediumTerms.length; medium++) {
|
||||||
|
for (int rare = 0; rare < rareTerms.length; rare++) {
|
||||||
|
Scorer expected = scorer(new String[] { commonTerms[common], mediumTerms[medium], rareTerms[rare] }, 2, true);
|
||||||
|
Scorer actual = scorer(new String[] { commonTerms[common], mediumTerms[medium], rareTerms[rare] }, 2, false);
|
||||||
assertNext(expected, actual);
|
assertNext(expected, actual);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** simple test for advance() */
|
/** simple test for advance(): minShouldMatch=2 on 3 terms (one common, one medium, one rare) */
|
||||||
public void testAdvance() throws Exception {
|
public void testAdvanceCMR2() throws Exception {
|
||||||
Scorer expected = scorer(new String[] { "b", "f", "j" }, 2, true);
|
for (int amount = 25; amount < 200; amount += 25) {
|
||||||
Scorer actual = scorer(new String[] { "b", "f", "j" }, 2, false);
|
for (int common = 0; common < commonTerms.length; common++) {
|
||||||
assertAdvance(expected, actual, 25);
|
for (int medium = 0; medium < mediumTerms.length; medium++) {
|
||||||
|
for (int rare = 0; rare < rareTerms.length; rare++) {
|
||||||
|
Scorer expected = scorer(new String[] { commonTerms[common], mediumTerms[medium], rareTerms[rare] }, 2, true);
|
||||||
|
Scorer actual = scorer(new String[] { commonTerms[common], mediumTerms[medium], rareTerms[rare] }, 2, false);
|
||||||
|
assertAdvance(expected, actual, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** test next with giant bq of all terms with varying minShouldMatch */
|
||||||
|
public void testNextAllTerms() throws Exception {
|
||||||
|
List<String> termsList = new ArrayList<String>();
|
||||||
|
termsList.addAll(Arrays.asList(commonTerms));
|
||||||
|
termsList.addAll(Arrays.asList(mediumTerms));
|
||||||
|
termsList.addAll(Arrays.asList(rareTerms));
|
||||||
|
String terms[] = termsList.toArray(new String[0]);
|
||||||
|
|
||||||
|
for (int minNrShouldMatch = 1; minNrShouldMatch <= terms.length; minNrShouldMatch++) {
|
||||||
|
Scorer expected = scorer(terms, minNrShouldMatch, true);
|
||||||
|
Scorer actual = scorer(terms, minNrShouldMatch, false);
|
||||||
|
assertNext(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** test advance with giant bq of all terms with varying minShouldMatch */
|
||||||
|
public void testAdvanceAllTerms() throws Exception {
|
||||||
|
List<String> termsList = new ArrayList<String>();
|
||||||
|
termsList.addAll(Arrays.asList(commonTerms));
|
||||||
|
termsList.addAll(Arrays.asList(mediumTerms));
|
||||||
|
termsList.addAll(Arrays.asList(rareTerms));
|
||||||
|
String terms[] = termsList.toArray(new String[0]);
|
||||||
|
|
||||||
|
for (int amount = 25; amount < 200; amount += 25) {
|
||||||
|
for (int minNrShouldMatch = 1; minNrShouldMatch <= terms.length; minNrShouldMatch++) {
|
||||||
|
Scorer expected = scorer(terms, minNrShouldMatch, true);
|
||||||
|
Scorer actual = scorer(terms, minNrShouldMatch, false);
|
||||||
|
assertAdvance(expected, actual, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** test next with varying numbers of terms with varying minShouldMatch */
|
||||||
|
public void testNextVaryingNumberOfTerms() throws Exception {
|
||||||
|
List<String> termsList = new ArrayList<String>();
|
||||||
|
termsList.addAll(Arrays.asList(commonTerms));
|
||||||
|
termsList.addAll(Arrays.asList(mediumTerms));
|
||||||
|
termsList.addAll(Arrays.asList(rareTerms));
|
||||||
|
Collections.shuffle(termsList, random());
|
||||||
|
for (int numTerms = 2; numTerms <= termsList.size(); numTerms++) {
|
||||||
|
String terms[] = termsList.subList(0, numTerms).toArray(new String[0]);
|
||||||
|
for (int minNrShouldMatch = 1; minNrShouldMatch <= terms.length; minNrShouldMatch++) {
|
||||||
|
Scorer expected = scorer(terms, minNrShouldMatch, true);
|
||||||
|
Scorer actual = scorer(terms, minNrShouldMatch, false);
|
||||||
|
assertNext(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** test advance with varying numbers of terms with varying minShouldMatch */
|
||||||
|
public void testAdvanceVaryingNumberOfTerms() throws Exception {
|
||||||
|
List<String> termsList = new ArrayList<String>();
|
||||||
|
termsList.addAll(Arrays.asList(commonTerms));
|
||||||
|
termsList.addAll(Arrays.asList(mediumTerms));
|
||||||
|
termsList.addAll(Arrays.asList(rareTerms));
|
||||||
|
Collections.shuffle(termsList, random());
|
||||||
|
|
||||||
|
for (int amount = 25; amount < 200; amount += 25) {
|
||||||
|
for (int numTerms = 2; numTerms <= termsList.size(); numTerms++) {
|
||||||
|
String terms[] = termsList.subList(0, numTerms).toArray(new String[0]);
|
||||||
|
for (int minNrShouldMatch = 1; minNrShouldMatch <= terms.length; minNrShouldMatch++) {
|
||||||
|
Scorer expected = scorer(terms, minNrShouldMatch, true);
|
||||||
|
Scorer actual = scorer(terms, minNrShouldMatch, false);
|
||||||
|
assertAdvance(expected, actual, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: more tests
|
// TODO: more tests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user