Package org.apache.lucene.search
Class CheckHits
- java.lang.Object
-
- org.apache.lucene.search.CheckHits
-
public class CheckHits extends Object
Utility class for asserting expected hits in tests.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCheckHits.ExplanationAsserterAsserts that the score explanation for every document matching a query corresponds with the true score.static classCheckHits.ExplanationAssertingSearcheran IndexSearcher that implicitly checks hte explanation of every match whenever it executes a search.static classCheckHits.SetCollectorJust collects document ids into a set.
-
Field Summary
Fields Modifier and Type Field Description static floatEXPLAIN_SCORE_TOLERANCE_DELTASome explains methods calculate their values though a slightly different order of operations from the actual scoring method ...
-
Constructor Summary
Constructors Constructor Description CheckHits()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckDocIds(String mes, int[] results, org.apache.lucene.search.ScoreDoc[] hits)Tests that a Hits has an expected order of documentsstatic voidcheckEqual(org.apache.lucene.search.Query query, org.apache.lucene.search.ScoreDoc[] hits1, org.apache.lucene.search.ScoreDoc[] hits2)static voidcheckExplanations(org.apache.lucene.search.Query query, String defaultFieldName, org.apache.lucene.search.Searcher searcher)Asserts that the explanation value for every document matching a query corresponds with the true score.static voidcheckExplanations(org.apache.lucene.search.Query query, String defaultFieldName, org.apache.lucene.search.Searcher searcher, boolean deep)Asserts that the explanation value for every document matching a query corresponds with the true score.static voidcheckHitCollector(Random random, org.apache.lucene.search.Query query, String defaultFieldName, org.apache.lucene.search.Searcher searcher, int[] results)Tests that a query matches the an expected set of documents using a HitCollector.static voidcheckHits(Random random, org.apache.lucene.search.Query query, String defaultFieldName, org.apache.lucene.search.Searcher searcher, int[] results)Tests that a query matches the an expected set of documents using Hits.static voidcheckHitsQuery(org.apache.lucene.search.Query query, org.apache.lucene.search.ScoreDoc[] hits1, org.apache.lucene.search.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 voidcheckNoMatchExplanations(org.apache.lucene.search.Query q, String defaultFieldName, org.apache.lucene.search.Searcher 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 Stringhits2str(org.apache.lucene.search.ScoreDoc[] hits1, org.apache.lucene.search.ScoreDoc[] hits2, int start, int end)static StringtopdocsString(org.apache.lucene.search.TopDocs docs, int start, int end)static voidverifyExplanation(String q, int doc, float score, boolean deep, org.apache.lucene.search.Explanation expl)Assert that an explanation has the expected score, and optionally that its sub-details max/sum/factor match to that score.
-
-
-
Method Detail
-
checkNoMatchExplanations
public static void checkNoMatchExplanations(org.apache.lucene.search.Query q, String defaultFieldName, org.apache.lucene.search.Searcher searcher, int[] results) throws IOExceptionTests 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, org.apache.lucene.search.Query query, String defaultFieldName, org.apache.lucene.search.Searcher 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 testsearcher- the searcher to test the query againstdefaultFieldName- used for displaying the query in assertion messagesresults- a list of documentIds that must match the query- Throws:
IOException- See Also:
checkHits(java.util.Random, org.apache.lucene.search.Query, java.lang.String, org.apache.lucene.search.Searcher, int[])
-
checkHits
public static void checkHits(Random random, org.apache.lucene.search.Query query, String defaultFieldName, org.apache.lucene.search.Searcher searcher, int[] results) throws IOException
Tests that a query matches the an 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 testsearcher- the searcher to test the query againstdefaultFieldName- used for displaing the query in assertion messagesresults- a list of documentIds that must match the query- Throws:
IOException- See Also:
checkHitCollector(java.util.Random, org.apache.lucene.search.Query, java.lang.String, org.apache.lucene.search.Searcher, int[])
-
checkDocIds
public static void checkDocIds(String mes, int[] results, org.apache.lucene.search.ScoreDoc[] hits) throws IOException
Tests that a Hits has an expected order of documents- Throws:
IOException
-
checkHitsQuery
public static void checkHitsQuery(org.apache.lucene.search.Query query, org.apache.lucene.search.ScoreDoc[] hits1, org.apache.lucene.search.ScoreDoc[] hits2, int[] results) throws IOExceptionTests that two queries have an expected order of documents, and that the two queries have the same score values.- Throws:
IOException
-
checkEqual
public static void checkEqual(org.apache.lucene.search.Query query, org.apache.lucene.search.ScoreDoc[] hits1, org.apache.lucene.search.ScoreDoc[] hits2) throws IOException- Throws:
IOException
-
hits2str
public static String hits2str(org.apache.lucene.search.ScoreDoc[] hits1, org.apache.lucene.search.ScoreDoc[] hits2, int start, int end) throws IOException
- Throws:
IOException
-
topdocsString
public static String topdocsString(org.apache.lucene.search.TopDocs docs, int start, int end)
-
checkExplanations
public static void checkExplanations(org.apache.lucene.search.Query query, String defaultFieldName, org.apache.lucene.search.Searcher searcher) throws IOExceptionAsserts that the explanation value for every document matching a query corresponds with the true score.- Parameters:
query- the query to testsearcher- the searcher to test the query againstdefaultFieldName- used for displaing the query in assertion messages- Throws:
IOException- See Also:
CheckHits.ExplanationAsserter,for a "deep" testing of the explanation details.
-
checkExplanations
public static void checkExplanations(org.apache.lucene.search.Query query, String defaultFieldName, org.apache.lucene.search.Searcher searcher, boolean deep) throws IOExceptionAsserts 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 testsearcher- the searcher to test the query againstdefaultFieldName- used for displaing the query in assertion messagesdeep- indicates whether a deep comparison of sub-Explanation details should be executed- Throws:
IOException- See Also:
CheckHits.ExplanationAsserter
-
verifyExplanation
public static void verifyExplanation(String q, int doc, float score, boolean deep, org.apache.lucene.search.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
-
-