mirror of https://github.com/apache/lucene.git
LUCENE-8060: Remove usage of TopDocs#totalHits that should really be IndexSearcher#count.
Many tests were written before we introduced IndexSearcher#count and used `searcher.search(query, 1).totalHits` to get the number of matches of a query rather than `searcher.count(query)`.
This commit is contained in:
parent
705e6f76a4
commit
d730c8b214
|
@ -58,7 +58,7 @@ public class TestDemo extends LuceneTestCase {
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = newSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -70,7 +70,7 @@ public class TestDemo extends LuceneTestCase {
|
|||
|
||||
// Test simple phrase query
|
||||
PhraseQuery phraseQuery = new PhraseQuery("fieldname", "to", "be");
|
||||
assertEquals(1, isearcher.search(phraseQuery, 1).totalHits);
|
||||
assertEquals(1, isearcher.count(phraseQuery));
|
||||
|
||||
ireader.close();
|
||||
directory.close();
|
||||
|
|
|
@ -97,8 +97,8 @@ public class TestExternalCodecs extends LuceneTestCase {
|
|||
|
||||
assertEquals(NUM_DOCS-1, r.numDocs());
|
||||
IndexSearcher s = newSearcher(r);
|
||||
assertEquals(NUM_DOCS-1, s.search(new TermQuery(new Term("field1", "standard")), 1).totalHits);
|
||||
assertEquals(NUM_DOCS-1, s.search(new TermQuery(new Term("field2", "memory")), 1).totalHits);
|
||||
assertEquals(NUM_DOCS-1, s.count(new TermQuery(new Term("field1", "standard"))));
|
||||
assertEquals(NUM_DOCS-1, s.count(new TermQuery(new Term("field2", "memory"))));
|
||||
r.close();
|
||||
|
||||
if (VERBOSE) {
|
||||
|
@ -117,11 +117,11 @@ public class TestExternalCodecs extends LuceneTestCase {
|
|||
assertEquals(NUM_DOCS-2, r.maxDoc());
|
||||
assertEquals(NUM_DOCS-2, r.numDocs());
|
||||
s = newSearcher(r);
|
||||
assertEquals(NUM_DOCS-2, s.search(new TermQuery(new Term("field1", "standard")), 1).totalHits);
|
||||
assertEquals(NUM_DOCS-2, s.search(new TermQuery(new Term("field2", "memory")), 1).totalHits);
|
||||
assertEquals(1, s.search(new TermQuery(new Term("id", "76")), 1).totalHits);
|
||||
assertEquals(0, s.search(new TermQuery(new Term("id", "77")), 1).totalHits);
|
||||
assertEquals(0, s.search(new TermQuery(new Term("id", "44")), 1).totalHits);
|
||||
assertEquals(NUM_DOCS-2, s.count(new TermQuery(new Term("field1", "standard"))));
|
||||
assertEquals(NUM_DOCS-2, s.count(new TermQuery(new Term("field2", "memory"))));
|
||||
assertEquals(1, s.count(new TermQuery(new Term("id", "76"))));
|
||||
assertEquals(0, s.count(new TermQuery(new Term("id", "77"))));
|
||||
assertEquals(0, s.count(new TermQuery(new Term("id", "44"))));
|
||||
|
||||
if (VERBOSE) {
|
||||
System.out.println("\nTEST: now close NRT reader");
|
||||
|
|
|
@ -114,7 +114,7 @@ public class TestPerFieldDocValuesFormat extends BaseDocValuesFormatTestCase {
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = newSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
|
|
@ -261,7 +261,7 @@ public class Test2BTerms extends LuceneTestCase {
|
|||
final BytesRef term = terms.get(random().nextInt(terms.size()));
|
||||
System.out.println("TEST: search " + term);
|
||||
final long t0 = System.currentTimeMillis();
|
||||
final long count = s.search(new TermQuery(new Term("field", term)), 1).totalHits;
|
||||
final long count = s.count(new TermQuery(new Term("field", term)));
|
||||
if (count <= 0) {
|
||||
System.out.println(" FAILED: count=" + count);
|
||||
failed = true;
|
||||
|
|
|
@ -680,7 +680,7 @@ public class TestDirectoryReaderReopen extends LuceneTestCase {
|
|||
});
|
||||
|
||||
IndexSearcher s = newSearcher(r);
|
||||
assertEquals(1, s.search(new TermQuery(new Term("id", "id")), 1).totalHits);
|
||||
assertEquals(1, s.count(new TermQuery(new Term("id", "id"))));
|
||||
|
||||
r.close();
|
||||
w.close();
|
||||
|
|
|
@ -1441,10 +1441,10 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
|||
|
||||
final IndexSearcher s = newSearcher(r);
|
||||
PhraseQuery pq = new PhraseQuery("content", "silly", "good");
|
||||
assertEquals(0, s.search(pq, 1).totalHits);
|
||||
assertEquals(0, s.count(pq));
|
||||
|
||||
pq = new PhraseQuery("content", "good", "content");
|
||||
assertEquals(numDocs1+numDocs2, s.search(pq, 1).totalHits);
|
||||
assertEquals(numDocs1+numDocs2, s.count(pq));
|
||||
r.close();
|
||||
dir.close();
|
||||
}
|
||||
|
@ -1514,10 +1514,10 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
|||
|
||||
final IndexSearcher s = newSearcher(r);
|
||||
PhraseQuery pq = new PhraseQuery("content", "silly", "content");
|
||||
assertEquals(numDocs2, s.search(pq, 1).totalHits);
|
||||
assertEquals(numDocs2, s.count(pq));
|
||||
|
||||
pq = new PhraseQuery("content", "good", "content");
|
||||
assertEquals(numDocs1+numDocs3+numDocs4, s.search(pq, 1).totalHits);
|
||||
assertEquals(numDocs1+numDocs3+numDocs4, s.count(pq));
|
||||
r.close();
|
||||
dir.close();
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public class TestManyFields extends LuceneTestCase {
|
|||
|
||||
IndexReader reader = DirectoryReader.open(dir);
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
long totalHits = searcher.search(new TermQuery(new Term("field", "aaa")), 1).totalHits;
|
||||
long totalHits = searcher.count(new TermQuery(new Term("field", "aaa")));
|
||||
assertEquals(n*100, totalHits);
|
||||
reader.close();
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ public class TestReadOnlyIndex extends LuceneTestCase {
|
|||
|
||||
// borrows from TestDemo, but not important to keep in sync with demo
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -95,7 +95,7 @@ public class TestReadOnlyIndex extends LuceneTestCase {
|
|||
|
||||
// Test simple phrase query
|
||||
PhraseQuery phraseQuery = new PhraseQuery("fieldname", "to", "be");
|
||||
assertEquals(1, isearcher.search(phraseQuery, 1).totalHits);
|
||||
assertEquals(1, isearcher.count(phraseQuery));
|
||||
|
||||
ireader.close();
|
||||
return null; // void
|
||||
|
|
|
@ -134,7 +134,7 @@ public class TestSoftDeletesDirectoryReaderWrapper extends LuceneTestCase {
|
|||
assertEquals(uniqueDocs.size(), reader.numDocs());
|
||||
IndexSearcher searcher = new IndexSearcher(reader);
|
||||
for (Integer docId : uniqueDocs) {
|
||||
assertEquals(1, searcher.search(new TermQuery(new Term("id", docId.toString())), 1).totalHits);
|
||||
assertEquals(1, searcher.count(new TermQuery(new Term("id", docId.toString()))));
|
||||
}
|
||||
|
||||
IOUtils.close(reader, dir);
|
||||
|
|
|
@ -171,7 +171,7 @@ public class TestConstantScoreQuery extends LuceneTestCase {
|
|||
.add(query, Occur.MUST)
|
||||
.add(filterB, Occur.FILTER)
|
||||
.build();
|
||||
assertEquals(1, s.search(filtered, 1).totalHits); // Query for field:b, Filter field:b
|
||||
assertEquals(1, s.count(filtered)); // Query for field:b, Filter field:b
|
||||
|
||||
Query filterA = new QueryWrapper(new TermQuery(new Term("field", "a")));
|
||||
query = new ConstantScoreQuery(filterA);
|
||||
|
@ -180,7 +180,7 @@ public class TestConstantScoreQuery extends LuceneTestCase {
|
|||
.add(query, Occur.MUST)
|
||||
.add(filterB, Occur.FILTER)
|
||||
.build();
|
||||
assertEquals(0, s.search(filtered, 1).totalHits); // Query field:b, Filter field:a
|
||||
assertEquals(0, s.count(filtered)); // Query field:b, Filter field:a
|
||||
|
||||
r.close();
|
||||
d.close();
|
||||
|
|
|
@ -160,7 +160,7 @@ public class TestFieldValueQuery extends LuceneTestCase {
|
|||
final IndexReader reader = iw.getReader();
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
iw.close();
|
||||
assertEquals(0, searcher.search(new DocValuesFieldExistsQuery("f"), 1).totalHits);
|
||||
assertEquals(0, searcher.count(new DocValuesFieldExistsQuery("f")));
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ public class TestFieldValueQuery extends LuceneTestCase {
|
|||
final IndexReader reader = iw.getReader();
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
iw.close();
|
||||
assertEquals(1, searcher.search(new DocValuesFieldExistsQuery("f"), 1).totalHits);
|
||||
assertEquals(1, searcher.count(new DocValuesFieldExistsQuery("f")));
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ public class TestFieldValueQuery extends LuceneTestCase {
|
|||
final IndexReader reader = iw.getReader();
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
iw.close();
|
||||
assertEquals(1, searcher.search(new DocValuesFieldExistsQuery("f"), 1).totalHits);
|
||||
assertEquals(1, searcher.count(new DocValuesFieldExistsQuery("f")));
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ public class TestMultiPhraseQuery extends LuceneTestCase {
|
|||
qb.add(new Term("body", "blueberry"));
|
||||
qb.add(new Term("body", "chocolate"));
|
||||
qb.add(new Term[] {new Term("body", "pie"), new Term("body", "tart")});
|
||||
assertEquals(2, searcher.search(qb.build(), 1).totalHits);
|
||||
assertEquals(2, searcher.count(qb.build()));
|
||||
r.close();
|
||||
indexStore.close();
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ public class TestMultiPhraseQuery extends LuceneTestCase {
|
|||
qb.add(new Term[] {new Term("body", "a"), new Term("body", "b")});
|
||||
qb.add(new Term[] {new Term("body", "a")});
|
||||
qb.setSlop(6);
|
||||
assertEquals(1, searcher.search(qb.build(), 1).totalHits); // should match on "a b"
|
||||
assertEquals(1, searcher.count(qb.build())); // should match on "a b"
|
||||
|
||||
r.close();
|
||||
indexStore.close();
|
||||
|
@ -190,7 +190,7 @@ public class TestMultiPhraseQuery extends LuceneTestCase {
|
|||
MultiPhraseQuery.Builder qb = new MultiPhraseQuery.Builder();
|
||||
qb.add(new Term[] {new Term("body", "a"), new Term("body", "d")}, 0);
|
||||
qb.add(new Term[] {new Term("body", "a"), new Term("body", "f")}, 2);
|
||||
assertEquals(1, searcher.search(qb.build(), 1).totalHits); // should match on "a b"
|
||||
assertEquals(1, searcher.count(qb.build())); // should match on "a b"
|
||||
r.close();
|
||||
indexStore.close();
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ public class TestMultiPhraseQuery extends LuceneTestCase {
|
|||
qb.add(new Term[] {new Term("body", "nope"), new Term("body", "nope")});
|
||||
MultiPhraseQuery q = qb.build();
|
||||
assertEquals("Wrong number of hits", 0,
|
||||
searcher.search(q, 1).totalHits);
|
||||
searcher.count(q));
|
||||
|
||||
// just make sure no exc:
|
||||
searcher.explain(q, 0);
|
||||
|
|
|
@ -144,7 +144,7 @@ public class TestNormsFieldExistsQuery extends LuceneTestCase {
|
|||
final IndexReader reader = iw.getReader();
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
iw.close();
|
||||
assertEquals(0, searcher.search(new NormsFieldExistsQuery("f"), 1).totalHits);
|
||||
assertEquals(0, searcher.count(new NormsFieldExistsQuery("f")));
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ public class TestNormsFieldExistsQuery extends LuceneTestCase {
|
|||
final IndexReader reader = iw.getReader();
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
iw.close();
|
||||
assertEquals(1, searcher.search(new NormsFieldExistsQuery("f"), 1).totalHits);
|
||||
assertEquals(1, searcher.count(new NormsFieldExistsQuery("f")));
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public class TestNormsFieldExistsQuery extends LuceneTestCase {
|
|||
final IndexReader reader = iw.getReader();
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
iw.close();
|
||||
assertEquals(1, searcher.search(new NormsFieldExistsQuery("f"), 1).totalHits);
|
||||
assertEquals(1, searcher.count(new NormsFieldExistsQuery("f")));
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
|
|
@ -585,21 +585,21 @@ public class TestPhraseQuery extends LuceneTestCase {
|
|||
PhraseQuery.Builder pqBuilder = new PhraseQuery.Builder();
|
||||
pqBuilder.add(new Term("field", "a"), 0);
|
||||
pqBuilder.add(new Term("field", "b"), 1);
|
||||
assertEquals(1, searcher.search(pqBuilder.build(), 1).totalHits);
|
||||
assertEquals(1, searcher.count(pqBuilder.build()));
|
||||
|
||||
// Now with "a|aa b"
|
||||
pqBuilder = new PhraseQuery.Builder();
|
||||
pqBuilder.add(new Term("field", "a"), 0);
|
||||
pqBuilder.add(new Term("field", "aa"), 0);
|
||||
pqBuilder.add(new Term("field", "b"), 1);
|
||||
assertEquals(1, searcher.search(pqBuilder.build(), 1).totalHits);
|
||||
assertEquals(1, searcher.count(pqBuilder.build()));
|
||||
|
||||
// Now with "a|z b" which should not match; this isn't a MultiPhraseQuery
|
||||
pqBuilder = new PhraseQuery.Builder();
|
||||
pqBuilder.add(new Term("field", "a"), 0);
|
||||
pqBuilder.add(new Term("field", "z"), 0);
|
||||
pqBuilder.add(new Term("field", "b"), 1);
|
||||
assertEquals(0, searcher.search(pqBuilder.build(), 1).totalHits);
|
||||
assertEquals(0, searcher.count(pqBuilder.build()));
|
||||
|
||||
r.close();
|
||||
dir.close();
|
||||
|
|
|
@ -124,7 +124,7 @@ public class TestPrefixQuery extends LuceneTestCase {
|
|||
count++;
|
||||
}
|
||||
}
|
||||
assertEquals(count, s.search(q, 1).totalHits);
|
||||
assertEquals(count, s.count(q));
|
||||
}
|
||||
r.close();
|
||||
w.close();
|
||||
|
|
|
@ -74,7 +74,7 @@ public class TestSpanMultiTermQueryWrapper extends LuceneTestCase {
|
|||
SpanQuery swq = new SpanMultiTermQueryWrapper<>(wq);
|
||||
// will only match quick brown fox
|
||||
SpanFirstQuery sfq = new SpanFirstQuery(swq, 2);
|
||||
assertEquals(1, searcher.search(sfq, 10).totalHits);
|
||||
assertEquals(1, searcher.count(sfq));
|
||||
}
|
||||
|
||||
public void testPrefix() throws Exception {
|
||||
|
@ -82,7 +82,7 @@ public class TestSpanMultiTermQueryWrapper extends LuceneTestCase {
|
|||
SpanQuery swq = new SpanMultiTermQueryWrapper<>(wq);
|
||||
// will only match "jumps over extremely very lazy broxn dog"
|
||||
SpanFirstQuery sfq = new SpanFirstQuery(swq, 3);
|
||||
assertEquals(1, searcher.search(sfq, 10).totalHits);
|
||||
assertEquals(1, searcher.count(sfq));
|
||||
}
|
||||
|
||||
public void testFuzzy() throws Exception {
|
||||
|
@ -90,7 +90,7 @@ public class TestSpanMultiTermQueryWrapper extends LuceneTestCase {
|
|||
SpanQuery sfq = new SpanMultiTermQueryWrapper<>(fq);
|
||||
// will not match quick brown fox
|
||||
SpanPositionRangeQuery sprq = new SpanPositionRangeQuery(sfq, 3, 6);
|
||||
assertEquals(2, searcher.search(sprq, 10).totalHits);
|
||||
assertEquals(2, searcher.count(sprq));
|
||||
}
|
||||
|
||||
public void testFuzzy2() throws Exception {
|
||||
|
@ -99,7 +99,7 @@ public class TestSpanMultiTermQueryWrapper extends LuceneTestCase {
|
|||
SpanQuery sfq = new SpanMultiTermQueryWrapper<>(fq);
|
||||
// will only match jumps over lazy broun dog
|
||||
SpanPositionRangeQuery sprq = new SpanPositionRangeQuery(sfq, 0, 100);
|
||||
assertEquals(1, searcher.search(sprq, 10).totalHits);
|
||||
assertEquals(1, searcher.count(sprq));
|
||||
}
|
||||
public void testNoSuchMultiTermsInNear() throws Exception {
|
||||
//test to make sure non existent multiterms aren't throwing null pointer exceptions
|
||||
|
@ -107,33 +107,33 @@ public class TestSpanMultiTermQueryWrapper extends LuceneTestCase {
|
|||
SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<>(fuzzyNoSuch);
|
||||
SpanQuery term = new SpanTermQuery(new Term("field", "brown"));
|
||||
SpanQuery near = new SpanNearQuery(new SpanQuery[]{term, spanNoSuch}, 1, true);
|
||||
assertEquals(0, searcher.search(near, 10).totalHits);
|
||||
assertEquals(0, searcher.count(near));
|
||||
//flip order
|
||||
near = new SpanNearQuery(new SpanQuery[]{spanNoSuch, term}, 1, true);
|
||||
assertEquals(0, searcher.search(near, 10).totalHits);
|
||||
assertEquals(0, searcher.count(near));
|
||||
|
||||
WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
|
||||
SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<>(wcNoSuch);
|
||||
near = new SpanNearQuery(new SpanQuery[]{term, spanWCNoSuch}, 1, true);
|
||||
assertEquals(0, searcher.search(near, 10).totalHits);
|
||||
assertEquals(0, searcher.count(near));
|
||||
|
||||
RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
|
||||
SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<>(rgxNoSuch);
|
||||
near = new SpanNearQuery(new SpanQuery[]{term, spanRgxNoSuch}, 1, true);
|
||||
assertEquals(0, searcher.search(near, 10).totalHits);
|
||||
assertEquals(0, searcher.count(near));
|
||||
|
||||
PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
|
||||
SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<>(prfxNoSuch);
|
||||
near = new SpanNearQuery(new SpanQuery[]{term, spanPrfxNoSuch}, 1, true);
|
||||
assertEquals(0, searcher.search(near, 10).totalHits);
|
||||
assertEquals(0, searcher.count(near));
|
||||
|
||||
//test single noSuch
|
||||
near = new SpanNearQuery(new SpanQuery[]{spanPrfxNoSuch}, 1, true);
|
||||
assertEquals(0, searcher.search(near, 10).totalHits);
|
||||
assertEquals(0, searcher.count(near));
|
||||
|
||||
//test double noSuch
|
||||
near = new SpanNearQuery(new SpanQuery[]{spanPrfxNoSuch, spanPrfxNoSuch}, 1, true);
|
||||
assertEquals(0, searcher.search(near, 10).totalHits);
|
||||
assertEquals(0, searcher.count(near));
|
||||
|
||||
}
|
||||
|
||||
|
@ -143,30 +143,30 @@ public class TestSpanMultiTermQueryWrapper extends LuceneTestCase {
|
|||
SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<>(fuzzyNoSuch);
|
||||
SpanQuery term = new SpanTermQuery(new Term("field", "brown"));
|
||||
SpanNotQuery notNear = new SpanNotQuery(term, spanNoSuch, 0,0);
|
||||
assertEquals(1, searcher.search(notNear, 10).totalHits);
|
||||
assertEquals(1, searcher.count(notNear));
|
||||
|
||||
//flip
|
||||
notNear = new SpanNotQuery(spanNoSuch, term, 0,0);
|
||||
assertEquals(0, searcher.search(notNear, 10).totalHits);
|
||||
assertEquals(0, searcher.count(notNear));
|
||||
|
||||
//both noSuch
|
||||
notNear = new SpanNotQuery(spanNoSuch, spanNoSuch, 0,0);
|
||||
assertEquals(0, searcher.search(notNear, 10).totalHits);
|
||||
assertEquals(0, searcher.count(notNear));
|
||||
|
||||
WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
|
||||
SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<>(wcNoSuch);
|
||||
notNear = new SpanNotQuery(term, spanWCNoSuch, 0,0);
|
||||
assertEquals(1, searcher.search(notNear, 10).totalHits);
|
||||
assertEquals(1, searcher.count(notNear));
|
||||
|
||||
RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
|
||||
SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<>(rgxNoSuch);
|
||||
notNear = new SpanNotQuery(term, spanRgxNoSuch, 1, 1);
|
||||
assertEquals(1, searcher.search(notNear, 10).totalHits);
|
||||
assertEquals(1, searcher.count(notNear));
|
||||
|
||||
PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
|
||||
SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<>(prfxNoSuch);
|
||||
notNear = new SpanNotQuery(term, spanPrfxNoSuch, 1, 1);
|
||||
assertEquals(1, searcher.search(notNear, 10).totalHits);
|
||||
assertEquals(1, searcher.count(notNear));
|
||||
|
||||
}
|
||||
|
||||
|
@ -176,33 +176,33 @@ public class TestSpanMultiTermQueryWrapper extends LuceneTestCase {
|
|||
SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<>(fuzzyNoSuch);
|
||||
SpanQuery term = new SpanTermQuery(new Term("field", "brown"));
|
||||
SpanOrQuery near = new SpanOrQuery(new SpanQuery[]{term, spanNoSuch});
|
||||
assertEquals(1, searcher.search(near, 10).totalHits);
|
||||
assertEquals(1, searcher.count(near));
|
||||
|
||||
//flip
|
||||
near = new SpanOrQuery(new SpanQuery[]{spanNoSuch, term});
|
||||
assertEquals(1, searcher.search(near, 10).totalHits);
|
||||
assertEquals(1, searcher.count(near));
|
||||
|
||||
|
||||
WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
|
||||
SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<>(wcNoSuch);
|
||||
near = new SpanOrQuery(new SpanQuery[]{term, spanWCNoSuch});
|
||||
assertEquals(1, searcher.search(near, 10).totalHits);
|
||||
assertEquals(1, searcher.count(near));
|
||||
|
||||
RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
|
||||
SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<>(rgxNoSuch);
|
||||
near = new SpanOrQuery(new SpanQuery[]{term, spanRgxNoSuch});
|
||||
assertEquals(1, searcher.search(near, 10).totalHits);
|
||||
assertEquals(1, searcher.count(near));
|
||||
|
||||
PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
|
||||
SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<>(prfxNoSuch);
|
||||
near = new SpanOrQuery(new SpanQuery[]{term, spanPrfxNoSuch});
|
||||
assertEquals(1, searcher.search(near, 10).totalHits);
|
||||
assertEquals(1, searcher.count(near));
|
||||
|
||||
near = new SpanOrQuery(new SpanQuery[]{spanPrfxNoSuch});
|
||||
assertEquals(0, searcher.search(near, 10).totalHits);
|
||||
assertEquals(0, searcher.count(near));
|
||||
|
||||
near = new SpanOrQuery(new SpanQuery[]{spanPrfxNoSuch, spanPrfxNoSuch});
|
||||
assertEquals(0, searcher.search(near, 10).totalHits);
|
||||
assertEquals(0, searcher.count(near));
|
||||
|
||||
}
|
||||
|
||||
|
@ -213,22 +213,22 @@ public class TestSpanMultiTermQueryWrapper extends LuceneTestCase {
|
|||
SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<>(fuzzyNoSuch);
|
||||
SpanQuery spanFirst = new SpanFirstQuery(spanNoSuch, 10);
|
||||
|
||||
assertEquals(0, searcher.search(spanFirst, 10).totalHits);
|
||||
assertEquals(0, searcher.count(spanFirst));
|
||||
|
||||
WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
|
||||
SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<>(wcNoSuch);
|
||||
spanFirst = new SpanFirstQuery(spanWCNoSuch, 10);
|
||||
assertEquals(0, searcher.search(spanFirst, 10).totalHits);
|
||||
assertEquals(0, searcher.count(spanFirst));
|
||||
|
||||
RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
|
||||
SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<>(rgxNoSuch);
|
||||
spanFirst = new SpanFirstQuery(spanRgxNoSuch, 10);
|
||||
assertEquals(0, searcher.search(spanFirst, 10).totalHits);
|
||||
assertEquals(0, searcher.count(spanFirst));
|
||||
|
||||
PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
|
||||
SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<>(prfxNoSuch);
|
||||
spanFirst = new SpanFirstQuery(spanPrfxNoSuch, 10);
|
||||
assertEquals(0, searcher.search(spanFirst, 10).totalHits);
|
||||
assertEquals(0, searcher.count(spanFirst));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -293,7 +293,7 @@ public class TestSpans extends LuceneTestCase {
|
|||
|
||||
// LUCENE-1404
|
||||
private long hitCount(IndexSearcher searcher, String word) throws Throwable {
|
||||
return searcher.search(new TermQuery(new Term("text", word)), 10).totalHits;
|
||||
return searcher.count(new TermQuery(new Term("text", word)));
|
||||
}
|
||||
|
||||
// LUCENE-1404
|
||||
|
|
|
@ -913,7 +913,7 @@ public class TestFSTs extends LuceneTestCase {
|
|||
if (VERBOSE) {
|
||||
System.out.println("TEST: TermQuery " + (exists ? "" : "non-exist ") + " id=" + id);
|
||||
}
|
||||
assertEquals((exists ? "" : "non-exist ") + "id=" + id, exists ? 1 : 0, s.search(new TermQuery(new Term("id", id)), 1).totalHits);
|
||||
assertEquals((exists ? "" : "non-exist ") + "id=" + id, exists ? 1 : 0, s.count(new TermQuery(new Term("id", id))));
|
||||
}
|
||||
|
||||
// Verify w/ MultiTermsEnum
|
||||
|
@ -1016,7 +1016,7 @@ public class TestFSTs extends LuceneTestCase {
|
|||
if (VERBOSE) {
|
||||
System.out.println("TEST: term=" + term);
|
||||
}
|
||||
assertEquals("term=" + term, 1, s.search(new TermQuery(new Term("field", term)), 1).totalHits);
|
||||
assertEquals("term=" + term, 1, s.count(new TermQuery(new Term("field", term))));
|
||||
}
|
||||
|
||||
r.close();
|
||||
|
|
|
@ -318,7 +318,7 @@ public class TestBlockJoin extends LuceneTestCase {
|
|||
|
||||
// Test with filter on child docs:
|
||||
fullChildQuery.add(new TermQuery(new Term("skill", "foosball")), Occur.FILTER);
|
||||
assertEquals(0, s.search(fullChildQuery.build(), 1).totalHits);
|
||||
assertEquals(0, s.count(fullChildQuery.build()));
|
||||
|
||||
r.close();
|
||||
dir.close();
|
||||
|
@ -375,25 +375,25 @@ public class TestBlockJoin extends LuceneTestCase {
|
|||
// up to corresponding parent:
|
||||
ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery.build(), parentsFilter, ScoreMode.Avg);
|
||||
|
||||
assertEquals("no filter - both passed", 2, s.search(childJoinQuery, 10).totalHits);
|
||||
assertEquals("no filter - both passed", 2, s.count(childJoinQuery));
|
||||
|
||||
Query query = new BooleanQuery.Builder()
|
||||
.add(childJoinQuery, Occur.MUST)
|
||||
.add(new TermQuery(new Term("docType", "resume")), Occur.FILTER)
|
||||
.build();
|
||||
assertEquals("dummy filter passes everyone ", 2, s.search(query, 10).totalHits);
|
||||
assertEquals("dummy filter passes everyone ", 2, s.count(query));
|
||||
query = new BooleanQuery.Builder()
|
||||
.add(childJoinQuery, Occur.MUST)
|
||||
.add(new TermQuery(new Term("docType", "resume")), Occur.FILTER)
|
||||
.build();
|
||||
assertEquals("dummy filter passes everyone ", 2, s.search(query, 10).totalHits);
|
||||
assertEquals("dummy filter passes everyone ", 2, s.count(query));
|
||||
|
||||
// not found test
|
||||
query = new BooleanQuery.Builder()
|
||||
.add(childJoinQuery, Occur.MUST)
|
||||
.add(new TermQuery(new Term("country", "Oz")), Occur.FILTER)
|
||||
.build();
|
||||
assertEquals("noone live there", 0, s.search(query, 1).totalHits);
|
||||
assertEquals("noone live there", 0, s.count(query));
|
||||
|
||||
// apply the UK filter by the searcher
|
||||
query = new BooleanQuery.Builder()
|
||||
|
@ -416,14 +416,14 @@ public class TestBlockJoin extends LuceneTestCase {
|
|||
|
||||
TermQuery us = new TermQuery(new Term("country", "United States"));
|
||||
assertEquals("@ US we have java and ruby", 2,
|
||||
s.search(new ToChildBlockJoinQuery(us,
|
||||
parentsFilter), 10).totalHits );
|
||||
s.count(new ToChildBlockJoinQuery(us,
|
||||
parentsFilter)) );
|
||||
|
||||
query = new BooleanQuery.Builder()
|
||||
.add(new ToChildBlockJoinQuery(us, parentsFilter), Occur.MUST)
|
||||
.add(skill("java"), Occur.FILTER)
|
||||
.build();
|
||||
assertEquals("java skills in US", 1, s.search(query, 10).totalHits );
|
||||
assertEquals("java skills in US", 1, s.count(query));
|
||||
|
||||
BooleanQuery.Builder rubyPython = new BooleanQuery.Builder();
|
||||
rubyPython.add(new TermQuery(new Term("skill", "ruby")), Occur.SHOULD);
|
||||
|
@ -432,7 +432,7 @@ public class TestBlockJoin extends LuceneTestCase {
|
|||
.add(new ToChildBlockJoinQuery(us, parentsFilter), Occur.MUST)
|
||||
.add(rubyPython.build(), Occur.FILTER)
|
||||
.build();
|
||||
assertEquals("ruby skills in US", 1, s.search(query, 10).totalHits );
|
||||
assertEquals("ruby skills in US", 1, s.count(query) );
|
||||
|
||||
r.close();
|
||||
dir.close();
|
||||
|
|
|
@ -115,7 +115,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = new IndexSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -149,7 +149,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = new IndexSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -185,7 +185,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = new IndexSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -223,7 +223,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = new IndexSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -263,7 +263,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = new IndexSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -302,7 +302,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = new IndexSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -346,7 +346,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = new IndexSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -518,7 +518,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = new IndexSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
@ -622,7 +622,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
|
|||
IndexReader ireader = DirectoryReader.open(directory); // read-only=true
|
||||
IndexSearcher isearcher = new IndexSearcher(ireader);
|
||||
|
||||
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
|
||||
assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm))));
|
||||
Query query = new TermQuery(new Term("fieldname", "text"));
|
||||
TopDocs hits = isearcher.search(query, 1);
|
||||
assertEquals(1, hits.totalHits);
|
||||
|
|
Loading…
Reference in New Issue