示例#1
0
        private float CheckPhraseQuery(Document doc, PhraseQuery query, int slop, int expectedNumResults)
        {
            query.Slop = slop;

            Directory         ramDir = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random, ramDir, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false), Similarity, TimeZone);

            writer.AddDocument(doc);

            IndexReader reader = writer.GetReader();

            IndexSearcher    searcher = NewSearcher(reader);
            MaxFreqCollector c        = new MaxFreqCollector();

            searcher.Search(query, c);
            Assert.AreEqual(expectedNumResults, c.TotalHits, "slop: " + slop + "  query: " + query + "  doc: " + doc + "  Wrong number of hits");

            //QueryUtils.Check(query,searcher);
            writer.Dispose();
            reader.Dispose();
            ramDir.Dispose();

            // returns the max Scorer.Freq() found, because even though norms are omitted, many index stats are different
            // with these different tokens/distributions/lengths.. otherwise this test is very fragile.
            return(c.Max);
        }
        private float CheckPhraseQuery(Document doc, PhraseQuery query, int slop, int expectedNumResults)
        {
            query.Slop = slop;

            Directory ramDir = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), ramDir, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false));
            writer.AddDocument(doc);

            IndexReader reader = writer.Reader;

            IndexSearcher searcher = NewSearcher(reader);
            MaxFreqCollector c = new MaxFreqCollector();
            searcher.Search(query, c);
            Assert.AreEqual(expectedNumResults, c.TotalHits, "slop: " + slop + "  query: " + query + "  doc: " + doc + "  Wrong number of hits");

            //QueryUtils.Check(query,searcher);
            writer.Dispose();
            reader.Dispose();
            ramDir.Dispose();

            // returns the max Scorer.Freq() found, because even though norms are omitted, many index stats are different
            // with these different tokens/distributions/lengths.. otherwise this test is very fragile.
            return c.Max;
        }