Skip to content
Open
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 @@ -20,7 +20,9 @@
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;
import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.not;

import java.io.IOException;
import java.util.HashSet;
Expand Down Expand Up @@ -915,8 +917,9 @@ public void testTimeLimitingKnnCollectorManager() throws IOException {
noTimeoutManager.newCollector(Integer.MAX_VALUE, null, searcher.leafContexts.get(0));

// Check that a normal collector is created without timeout
assertFalse(
noTimeoutCollector instanceof TimeLimitingKnnCollectorManager.TimeLimitingKnnCollector);
assertThat(
noTimeoutCollector,
not(instanceOf(TimeLimitingKnnCollectorManager.TimeLimitingKnnCollector.class)));
noTimeoutCollector.collect(0, 0);
assertFalse(noTimeoutCollector.earlyTerminated());

Expand All @@ -932,7 +935,7 @@ public void testTimeLimitingKnnCollectorManager() throws IOException {
timeoutManager.newCollector(Integer.MAX_VALUE, null, searcher.leafContexts.get(0));

// Check that a time limiting collector is created, which returns partial results
assertFalse(timeoutCollector instanceof TopKnnCollector);
assertThat(timeoutCollector, not(instanceOf(TopKnnCollector.class)));
timeoutCollector.collect(0, 0);
assertTrue(timeoutCollector.earlyTerminated());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN;
import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -317,7 +320,7 @@ public void testSomeDeletes() throws IOException {
int id = getId(searcher, scoreDoc.doc);

// Check that returned document is not deleted
assertFalse(id >= startIndex && id <= endIndex);
assertThat(id, either(lessThan(startIndex)).or(greaterThan(endIndex)));
}
// Check that all live docs are returned
assertEquals(numDocs - endIndex + startIndex - 1, scoreDocs.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package org.apache.lucene.search;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.everyItem;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -249,17 +253,17 @@ public void testGetChildrenMinShouldMatchSumScorer() throws IOException {
ScoreSummary scoreSummary =
searcher.search(query.build(), new ScorerSummarizingCollectorManager());
assertEquals(1, scoreSummary.numHits.get());
assertFalse(scoreSummary.summaries.isEmpty());
for (String summary : scoreSummary.summaries) {
assertEquals(
"ConjunctionScorer\n"
+ " MUST ConstantScoreScorer\n"
+ " MUST WANDScorer\n"
+ " SHOULD TermScorer\n"
+ " SHOULD TermScorer\n"
+ " SHOULD TermScorer",
summary);
}
assertThat(
scoreSummary.summaries,
everyItem(
equalTo(
"""
ConjunctionScorer
MUST ConstantScoreScorer
MUST WANDScorer
SHOULD TermScorer
SHOULD TermScorer
SHOULD TermScorer""")));
}

public void testGetChildrenBoosterScorer() throws IOException {
Expand All @@ -269,10 +273,7 @@ public void testGetChildrenBoosterScorer() throws IOException {
ScoreSummary scoreSummary =
scorerSearcher.search(query.build(), new ScorerSummarizingCollectorManager());
assertEquals(1, scoreSummary.numHits.get());
assertFalse(scoreSummary.summaries.isEmpty());
for (String summary : scoreSummary.summaries) {
assertEquals("TermScorer", summary);
}
assertThat(scoreSummary.summaries, contains("TermScorer"));
}

private static class ScoreSummary {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testEquals() {
}
BoostQuery q3 = new BoostQuery(new MatchAllDocsQuery(), boost2);
assertFalse(q1.equals(q3));
assertFalse(q1.hashCode() == q3.hashCode());
assertNotEquals(q3.hashCode(), q1.hashCode());
}

public void testToString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,12 @@ public void testSetEquals() {
assertEquals(
NumericDocValuesField.newSlowSetQuery("field", 17L, 42L, 32416190071L),
NumericDocValuesField.newSlowSetQuery("field", 17L, 32416190071L, 42L));
assertFalse(
NumericDocValuesField.newSlowSetQuery("field", 42L)
.equals(NumericDocValuesField.newSlowSetQuery("field2", 42L)));
assertFalse(
NumericDocValuesField.newSlowSetQuery("field", 17L, 42L)
.equals(NumericDocValuesField.newSlowSetQuery("field", 17L, 32416190071L)));
assertNotEquals(
NumericDocValuesField.newSlowSetQuery("field", 42L),
NumericDocValuesField.newSlowSetQuery("field2", 42L));
assertNotEquals(
NumericDocValuesField.newSlowSetQuery("field", 17L, 42L),
NumericDocValuesField.newSlowSetQuery("field", 17L, 32416190071L));
}

public void testDuelSetVsTermsQuery() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
*/
package org.apache.lucene.search;

import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.not;

import java.io.IOException;
import org.apache.lucene.document.BinaryPoint;
import org.apache.lucene.document.Document;
Expand Down Expand Up @@ -62,8 +67,9 @@ public void testDocValuesRewriteWithTermsPresent() throws IOException {
final IndexReader reader = iw.getReader();
iw.close();

assertTrue(
(new FieldExistsQuery("f")).rewrite(newSearcher(reader)) instanceof MatchAllDocsQuery);
assertThat(
new FieldExistsQuery("f").rewrite(newSearcher(reader)),
instanceOf(MatchAllDocsQuery.class));
reader.close();
dir.close();
}
Expand All @@ -82,8 +88,9 @@ public void testDocValuesRewriteWithPointValuesPresent() throws IOException {
final IndexReader reader = iw.getReader();
iw.close();

assertTrue(
new FieldExistsQuery("dim").rewrite(newSearcher(reader)) instanceof MatchAllDocsQuery);
assertThat(
new FieldExistsQuery("dim").rewrite(newSearcher(reader)),
instanceOf(MatchAllDocsQuery.class));
reader.close();
dir.close();
}
Expand Down Expand Up @@ -127,8 +134,10 @@ public void testDocValuesNoRewrite() throws IOException {
iw.close();
final IndexSearcher searcher = newSearcher(reader);

assertFalse((new FieldExistsQuery("dim")).rewrite(searcher) instanceof MatchAllDocsQuery);
assertFalse((new FieldExistsQuery("f")).rewrite(searcher) instanceof MatchAllDocsQuery);
assertThat(
new FieldExistsQuery("dim").rewrite(searcher), not(instanceOf(MatchAllDocsQuery.class)));
assertThat(
new FieldExistsQuery("f").rewrite(searcher), not(instanceOf(MatchAllDocsQuery.class)));
reader.close();
dir.close();
}
Expand All @@ -149,9 +158,12 @@ public void testDocValuesNoRewriteWithDocValues() throws IOException {
iw.close();
final IndexSearcher searcher = newSearcher(reader);

assertFalse((new FieldExistsQuery("dv1")).rewrite(searcher) instanceof MatchAllDocsQuery);
assertFalse((new FieldExistsQuery("dv2")).rewrite(searcher) instanceof MatchAllDocsQuery);
assertFalse((new FieldExistsQuery("dv3")).rewrite(searcher) instanceof MatchAllDocsQuery);
assertThat(
new FieldExistsQuery("dv1").rewrite(searcher), not(instanceOf(MatchAllDocsQuery.class)));
assertThat(
new FieldExistsQuery("dv2").rewrite(searcher), not(instanceOf(MatchAllDocsQuery.class)));
assertThat(
new FieldExistsQuery("dv3").rewrite(searcher), not(instanceOf(MatchAllDocsQuery.class)));
reader.close();
dir.close();
}
Expand Down Expand Up @@ -368,7 +380,7 @@ public void testDocValuesQueryMatchesCount() throws IOException {
final IndexSearcher searcher2 = new IndexSearcher(reader2);
final Query testQuery = new FieldExistsQuery("long");
final Weight weight2 = searcher2.createWeight(testQuery, ScoreMode.COMPLETE, 1);
assertEquals(weight2.count(reader2.leaves().get(0)), -1);
assertEquals(-1, weight2.count(reader2.leaves().get(0)));

IOUtils.close(reader, reader2, w, dir);
}
Expand Down Expand Up @@ -660,7 +672,7 @@ public void testKnnVectorAllDocsHaveField() throws IOException {
try (IndexReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader);
Query query = new FieldExistsQuery("vector");
assertTrue(searcher.rewrite(query) instanceof MatchAllDocsQuery);
assertThat(searcher.rewrite(query), instanceOf(MatchAllDocsQuery.class));
assertEquals(100, searcher.count(query));
}
}
Expand Down Expand Up @@ -725,7 +737,7 @@ public void testKnnVectorConjunction() throws IOException {
.build();

int count = searcher.count(booleanQuery);
assertTrue(count <= numVectors);
assertThat(count, lessThanOrEqualTo(numVectors));
if (allDocsHaveVector) {
assertEquals(numDocs / 2, count);
}
Expand Down Expand Up @@ -816,7 +828,8 @@ public void testDeleteAllPointDocs() throws Exception {
iw.forceMerge(1);

try (IndexReader reader = iw.getReader()) {
assertTrue(reader.leaves().size() == 1 && reader.hasDeletions() == false);
assertThat(reader.leaves(), hasSize(1));
assertFalse(reader.hasDeletions());
IndexSearcher searcher = newSearcher(reader);
assertEquals(0, searcher.count(new FieldExistsQuery("long")));
}
Expand Down Expand Up @@ -845,7 +858,8 @@ public void testDeleteAllTermDocs() throws Exception {
iw.forceMerge(1);

try (IndexReader reader = iw.getReader()) {
assertTrue(reader.leaves().size() == 1 && reader.hasDeletions() == false);
assertThat(reader.leaves(), hasSize(1));
assertFalse(reader.hasDeletions());
IndexSearcher searcher = newSearcher(reader);
assertEquals(0, searcher.count(new FieldExistsQuery("str")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.apache.lucene.search;

import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;

import java.io.IOException;
import java.util.Arrays;
import org.apache.lucene.index.MultiReader;
Expand Down Expand Up @@ -57,9 +60,10 @@ public void testFlattenInnerDisjunctionsWithMoreThan1024Terms() throws IOExcepti
() -> {
searcher.rewrite(query);
});
assertFalse(
assertThat(
"Should have been caught during flattening and not required full nested walk",
e instanceof IndexSearcher.TooManyNestedClauses);
e,
not(instanceOf(IndexSearcher.TooManyNestedClauses.class)));
}

public void testLargeTermsNestedFirst() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public void testHashCodeAndEquals() {
query1builder.add(term2);
query1 = query1builder.build();

assertFalse(query1.hashCode() == query2.hashCode());
assertNotEquals(query1.hashCode(), query2.hashCode());
assertFalse(query1.equals(query2));

query2builder.add(term2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ public void testRangeOptimizesIfAllPointsMatch() throws IOException {
searcher.setQueryCache(null);
weight = searcher.createWeight(query, ScoreMode.COMPLETE_NO_SCORES, 1);
scorer = weight.scorer(searcher.getIndexReader().leaves().get(0));
assertFalse(DocIdSetIterator.all(1).getClass().equals(scorer.iterator().getClass()));
assertNotEquals(DocIdSetIterator.all(1).getClass(), scorer.iterator().getClass());

reader.close();
w.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.apache.lucene.search;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

import com.carrotsearch.randomizedtesting.generators.RandomPicks;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -333,20 +336,20 @@ protected float combine(
int docID = hits2.scoreDocs[0].doc;
Explanation explain = rescorer.explain(searcher, searcher.explain(bq.build(), docID), docID);
String s = explain.toString();
assertTrue(s.contains("TestQueryRescorer$"));
assertTrue(s.contains("combined first and second pass score"));
assertTrue(s.contains("first pass score"));
assertTrue(s.contains("= second pass score"));
assertThat(s, containsString("TestQueryRescorer$"));
assertThat(s, containsString("combined first and second pass score"));
assertThat(s, containsString("first pass score"));
assertThat(s, containsString("= second pass score"));
assertEquals(hits2.scoreDocs[0].score, explain.getValue().doubleValue(), 0.0f);

docID = hits2.scoreDocs[1].doc;
explain = rescorer.explain(searcher, searcher.explain(bq.build(), docID), docID);
s = explain.toString();
assertTrue(s.contains("TestQueryRescorer$"));
assertTrue(s.contains("combined first and second pass score"));
assertTrue(s.contains("first pass score"));
assertTrue(s.contains("no second pass score"));
assertFalse(s.contains("= second pass score"));
assertThat(s, containsString("TestQueryRescorer$"));
assertThat(s, containsString("combined first and second pass score"));
assertThat(s, containsString("first pass score"));
assertThat(s, containsString("no second pass score"));
assertThat(s, not(containsString("= second pass score")));
assertEquals(hits2.scoreDocs[1].score, explain.getValue().doubleValue(), 0.0f);

r.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.lucene.search;

import static org.hamcrest.Matchers.lessThan;

import java.io.IOException;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.FeatureField;
Expand Down Expand Up @@ -109,11 +111,11 @@ public void testMinRequiredScore() {
} else {
// The value before minRequiredScore must not be able to produce a score >=
// minCompetitiveScore.
assertFalse(
assertThat(
(float)
MathUtil.sumUpperBound(
Math.nextDown(minRequiredScore) + maxRemainingScore, numScorers)
>= minCompetitiveScore);
MathUtil.sumUpperBound(
Math.nextDown(minRequiredScore) + maxRemainingScore, numScorers),
lessThan(minCompetitiveScore));
}

// NOTE: we need to assert the internal while loop ends within an acceptable iterations. But
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.lucene.search;

import static org.hamcrest.Matchers.instanceOf;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -531,9 +533,9 @@ public void testCustomDirectoryReader() throws Exception {
mgr.maybeRefresh();
IndexSearcher s = mgr.acquire();
try {
assertTrue(s.getIndexReader() instanceof MyFilterDirectoryReader);
assertThat(s.getIndexReader(), instanceOf(MyFilterDirectoryReader.class));
for (LeafReaderContext ctx : s.getIndexReader().leaves()) {
assertTrue(ctx.reader() instanceof MyFilterLeafReader);
assertThat(ctx.reader(), instanceOf(MyFilterLeafReader.class));
}
} finally {
mgr.release(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void testBasics() throws Exception {
for (int i = 0; i < reader.maxDoc(); i++) {
assertEquals(i, fooNorms.nextDoc());
assertEquals(i, barNorms.nextDoc());
assertFalse(fooNorms.longValue() == barNorms.longValue());
assertNotEquals(fooNorms.longValue(), barNorms.longValue());
}

// sanity check of searching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.stream.Stream;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
Expand Down Expand Up @@ -213,11 +214,8 @@ public int compare(Integer a, Integer b) {
}
});

boolean fail = false;
for (int i = 0; i < numHits; i++) {
fail |= expected[i].intValue() != hits2.scoreDocs[i].doc;
}
assertFalse(fail);
Integer[] rescored = Stream.of(hits2.scoreDocs).map(d -> d.doc).toArray(Integer[]::new);
assertArrayEquals(expected, rescored);

r.close();
dir.close();
Expand Down
Loading