コード例 #1
0
        // Test that queries based on reverse/ordFieldScore scores correctly
        private void  DoTestRank(System.String field, bool inOrder)
        {
            IndexSearcher s = new IndexSearcher(dir, true);
            ValueSource   vs;

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

            Query q = new ValueSourceQuery(vs);

            Log("test: " + q);
            QueryUtils.Check(q, s);
            ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;
            Assert.AreEqual(N_DOCS, h.Length, "All docs should be matched!");
            System.String prevID = inOrder?"IE":"IC"; // smaller than all ids of docs in this test ("ID0001", etc.)

            for (int i = 0; i < h.Length; i++)
            {
                System.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)
                {
                    Assert.IsTrue(String.CompareOrdinal(resID, prevID) < 0, "res id " + resID + " should be < prev res id " + prevID);
                }
                else
                {
                    Assert.IsTrue(String.CompareOrdinal(resID, prevID) > 0, "res id " + resID + " should be > prev res id " + prevID);
                }
                prevID = resID;
            }
        }