Beispiel #1
0
        /// <summary>
        /// Test that queries based on reverse/ordFieldScore returns docs with expected score.
        /// </summary>
        /// <param name="field"></param>
        /// <param name="inOrder"></param>
        private void DoTestExactScore(string field, bool inOrder)
        {
            IndexReader   r = DirectoryReader.Open(dir);
            IndexSearcher s = NewSearcher(r);
            ValueSource   vs;

            if (inOrder)
            {
                vs = new OrdFieldSource(field);
            }
            else
            {
                vs = new ReverseOrdFieldSource(field);
            }
            Query   q  = new FunctionQuery(vs);
            TopDocs td = s.Search(q, null, 1000);

            assertEquals("All docs should be matched!", N_DOCS, td.TotalHits);
            ScoreDoc[] sd = td.ScoreDocs;
            for (int i = 0; i < sd.Length; i++)
            {
                float  score = sd[i].Score;
                string id    = s.IndexReader.Document(sd[i].Doc).Get(ID_FIELD);
                Log("-------- " + i + ". Explain doc " + id);
                Log(s.Explain(q, sd[i].Doc));
                float expectedScore = N_DOCS - i - 1;
                assertEquals("score of result " + i + " shuould be " + expectedScore + " != " + score, expectedScore, score, TEST_SCORE_TOLERANCE_DELTA);
                string expectedId = inOrder ? Id2String(N_DOCS - i) : Id2String(i + 1); // reverse  ==> smaller values first -  in-order ==> larger  values first
                assertTrue("id of result " + i + " shuould be " + expectedId + " != " + score, expectedId.Equals(id, StringComparison.Ordinal));
            }
            r.Dispose();
        }
Beispiel #2
0
        public void TestEqualsNull()
        {
            OrdFieldSource ofs = new OrdFieldSource("f");

            assertFalse(ofs.Equals(null));

            ReverseOrdFieldSource rofs = new ReverseOrdFieldSource("f");

            assertFalse(rofs.Equals(null));
        }
Beispiel #3
0
        /// <summary>
        /// Test that queries based on reverse/ordFieldScore scores correctly
        /// </summary>
        /// <param name="field"></param>
        /// <param name="inOrder"></param>
        private void DoTestRank(string field, bool inOrder)
        {
            IndexReader   r = DirectoryReader.Open(dir);
            IndexSearcher s = NewSearcher(r);
            ValueSource   vs;

            if (inOrder)
            {
                vs = new OrdFieldSource(field);
            }
            else
            {
                vs = new ReverseOrdFieldSource(field);
            }

            Query q = new FunctionQuery(vs);

            Log("test: " + q);
            QueryUtils.Check(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                this,
#endif
                Random, q, s);
            ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;
            assertEquals("All docs should be matched!", N_DOCS, h.Length);
            string prevID = inOrder
                ? "IE"  // greater than all ids of docs in this test ("ID0001", etc.)
                : "IC"; // smaller than all ids of docs in this test ("ID0001", etc.)

            for (int i = 0; i < h.Length; i++)
            {
                string resID = s.Doc(h[i].Doc).Get(ID_FIELD);
                Log(i + ".   score=" + h[i].Score + "  -  " + resID);
                Log(s.Explain(q, h[i].Doc));
                if (inOrder)
                {
                    assertTrue("res id " + resID + " should be < prev res id " + prevID, resID.CompareToOrdinal(prevID) < 0);
                }
                else
                {
                    assertTrue("res id " + resID + " should be > prev res id " + prevID, resID.CompareToOrdinal(prevID) > 0);
                }
                prevID = resID;
            }
            r.Dispose();
        }