Class CheckHits


  • public class CheckHits
    extends Object
    Utility class for asserting expected hits in tests.
    • Field Detail

      • EXPLAIN_SCORE_TOLERANCE_DELTA

        public static float EXPLAIN_SCORE_TOLERANCE_DELTA
        Some explains methods calculate their values though a slightly different order of operations from the actual scoring method ... this allows for a small amount of relative variation
      • EXPLAIN_SCORE_TOLERANCE_MINIMUM

        public static float EXPLAIN_SCORE_TOLERANCE_MINIMUM
        In general we use a relative epsilon, but some tests do crazy things like boost documents with 0, creating tiny tiny scores where the relative difference is large but the absolute difference is tiny. we ensure the the epsilon is always at least this big.
    • Constructor Detail

      • CheckHits

        public CheckHits()
    • Method Detail

      • 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
      • checkDocIds

        public static void checkDocIds​(String mes,
                                       int[] results,
                                       ScoreDoc[] hits)
        Tests that a Hits has an expected order of documents
      • checkHitsQuery

        public static void checkHitsQuery​(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.
      • topdocsString

        public static String topdocsString​(TopDocs docs,
                                           int start,
                                           int end)
      • 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 test
        searcher - the searcher to test the query against
        defaultFieldName - used for displaing the query in assertion messages
        deep - indicates whether a deep comparison of sub-Explanation details should be executed
        Throws:
        IOException
        See Also:
        CheckHits.ExplanationAsserter
      • explainToleranceDelta

        public static float explainToleranceDelta​(float f1,
                                                  float f2)
        returns a reasonable epsilon for comparing two floats, where minor differences are acceptable such as score vs. explain
      • 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 messages
        doc - Document ID for assertion messages
        score - Real score value of doc with query q
        deep - indicates whether a deep comparison of sub-Explanation details should be executed
        expl - The Explanation to match against score