Package org.apache.lucene.tests.search
Class CheckHits
java.lang.Object
org.apache.lucene.tests.search.CheckHits
Utility class for asserting expected hits in tests.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAsserts that the score explanation for every document matching a query corresponds with the true score.static classan IndexSearcher that implicitly checks hte explanation of every match whenever it executes a search.static classAsserts that theMatchesfrom a query is non-null whenever the document its created for is a hit.static classJust collects document ids into a set. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckDocIds(String mes, int[] results, ScoreDoc[] hits) Tests that a Hits has an expected order of documentsstatic voidcheckEqual(Query query, ScoreDoc[] hits1, ScoreDoc[] hits2) static voidcheckExplanations(Query query, String defaultFieldName, IndexSearcher searcher) Asserts that the explanation value for every document matching a query corresponds with the true score.static voidcheckExplanations(Query query, String defaultFieldName, IndexSearcher searcher, boolean deep) Asserts that the explanation value for every document matching a query corresponds with the true score.static voidcheckHitCollector(Random random, Query query, String defaultFieldName, IndexSearcher searcher, int[] results) Tests that a query matches the an expected set of documents using a HitCollector.static voidcheckHits(Random random, Query query, String defaultFieldName, IndexSearcher searcher, int[] results) Tests that a query matches the expected set of documents using Hits.static voidcheckHitsQuery(Query query, ScoreDoc[] hits1, ScoreDoc[] hits2, int[] results) Tests that two queries have an expected order of documents, and that the two queries have the same score values.static voidcheckMatches(Query query, IndexSearcher searcher) Asserts that the result of callingWeight.matches(LeafReaderContext, int)for every document matching a query returns a non-nullMatchesstatic voidcheckNoMatchExplanations(Query q, String defaultFieldName, IndexSearcher searcher, int[] results) Tests that all documents up to maxDoc which are *not* in the expected result set, have an explanation which indicates that the document does not matchstatic voidcheckTopScores(Random random, Query query, IndexSearcher searcher) static Stringstatic StringtopdocsString(TopDocs docs, int start, int end) static voidverifyExplanation(String q, int doc, float score, boolean deep, Explanation expl) Assert that an explanation has the expected score, and optionally that its sub-details max/sum/factor match to that score.
-
Constructor Details
-
CheckHits
public CheckHits()
-
-
Method Details
-
checkNoMatchExplanations
public static void checkNoMatchExplanations(Query q, String defaultFieldName, IndexSearcher searcher, int[] results) throws IOException Tests that all documents up to maxDoc which are *not* in the expected result set, have an explanation which indicates that the document does not match- Throws:
IOException
-
checkHitCollector
public static void checkHitCollector(Random random, Query query, String defaultFieldName, IndexSearcher searcher, int[] results) throws IOException Tests that a query matches the an expected set of documents using a HitCollector.Note that when using the HitCollector API, documents will be collected if they "match" regardless of what their score is.
- Parameters:
query- the query to testdefaultFieldName- used for displaying the query in assertion messagessearcher- the searcher to test the query againstresults- a list of documentIds that must match the query- Throws:
IOException- See Also:
-
checkHits
public static void checkHits(Random random, Query query, String defaultFieldName, IndexSearcher searcher, int[] results) throws IOException Tests that a query matches the expected set of documents using Hits.Note that when using the Hits API, documents will only be returned if they have a positive normalized score.
- Parameters:
query- the query to testdefaultFieldName- used for displaing the query in assertion messagessearcher- the searcher to test the query againstresults- a list of documentIds that must match the query- Throws:
IOException- See Also:
-
checkDocIds
Tests that a Hits has an expected order of documents -
checkHitsQuery
Tests that two queries have an expected order of documents, and that the two queries have the same score values. -
checkEqual
-
hits2str
-
topdocsString
-
checkExplanations
public static void checkExplanations(Query query, String defaultFieldName, IndexSearcher searcher) throws IOException Asserts that the explanation value for every document matching a query corresponds with the true score.- Parameters:
query- the query to testdefaultFieldName- used for displaing the query in assertion messagessearcher- the searcher to test the query against- Throws:
IOException- See Also:
-
checkExplanations
public static void checkExplanations(Query query, String defaultFieldName, IndexSearcher searcher, boolean deep) throws IOException Asserts that the explanation value for every document matching a query corresponds with the true score. Optionally does "deep" testing of the explanation details.- Parameters:
query- the query to testdefaultFieldName- used for displaing the query in assertion messagessearcher- the searcher to test the query againstdeep- indicates whether a deep comparison of sub-Explanation details should be executed- Throws:
IOException- See Also:
-
checkMatches
Asserts that the result of callingWeight.matches(LeafReaderContext, int)for every document matching a query returns a non-nullMatches- Parameters:
query- the query to testsearcher- the search to test against- Throws:
IOException
-
verifyExplanation
public static void verifyExplanation(String q, int doc, float score, boolean deep, Explanation expl) Assert that an explanation has the expected score, and optionally that its sub-details max/sum/factor match to that score.- Parameters:
q- String representation of the query for assertion messagesdoc- Document ID for assertion messagesscore- Real score value of doc with query qdeep- indicates whether a deep comparison of sub-Explanation details should be executedexpl- The Explanation to match against score
-
checkTopScores
public static void checkTopScores(Random random, Query query, IndexSearcher searcher) throws IOException - Throws:
IOException
-