public virtual void  TestCustomSimilarity()
        {
            RAMDirectory dir = new RAMDirectory();

            InitIndex(dir, 10, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...
            IndexSearcher srchr  = new IndexSearcher(dir, true);
            MultiSearcher msrchr = GetMultiSearcherInstance(new Searcher[] { srchr });

            Similarity customSimilarity = new AnonymousClassDefaultSimilarity(this);

            srchr.Similarity  = customSimilarity;
            msrchr.Similarity = customSimilarity;

            Query query = new TermQuery(new Term("contents", "doc0"));

            // Get a score from IndexSearcher
            TopDocs topDocs = srchr.Search(query, null, 1);
            float   score1  = topDocs.MaxScore;

            // Get the score from MultiSearcher
            topDocs = msrchr.Search(query, null, 1);
            float scoreN = topDocs.MaxScore;

            // The scores from the IndexSearcher and Multisearcher should be the same
            // if the same similarity is used.
            Assert.AreEqual(score1, scoreN, 1e-6, "MultiSearcher score must be equal to single searcher score!");
        }
Exemplo n.º 2
0
        public virtual void  TestSpanScorerZeroSloppyFreq()
        {
            bool ordered = true;
            int  slop    = 1;

            Similarity sim = new AnonymousClassDefaultSimilarity(this);

            SpanNearQuery snq = new AnonymousClassSpanNearQuery(sim, this, new SpanQuery[] { MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2") }, slop, ordered);

            Scorer spanScorer = snq.Weight(searcher).Scorer(searcher.GetIndexReader(), true, false);

            Assert.IsTrue(spanScorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "first doc");
            Assert.AreEqual(spanScorer.DocID(), 11, "first doc number");
            float score = spanScorer.Score();

            Assert.IsTrue(score == 0.0f, "first doc score should be zero, " + score);
            Assert.IsTrue(spanScorer.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "no second doc");
        }
Exemplo n.º 3
0
		public virtual void  TestSpanScorerZeroSloppyFreq()
		{
			bool ordered = true;
			int slop = 1;
			
			Similarity sim = new AnonymousClassDefaultSimilarity(this);
			
			SpanNearQuery snq = new AnonymousClassSpanNearQuery(sim, this, new SpanQuery[]{MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2")}, slop, ordered);
			
			Scorer spanScorer = snq.Weight(searcher).Scorer(searcher.GetIndexReader(), true, false);
			
			Assert.IsTrue(spanScorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "first doc");
			Assert.AreEqual(spanScorer.DocID(), 11, "first doc number");
			float score = spanScorer.Score();
			Assert.IsTrue(score == 0.0f, "first doc score should be zero, " + score);
			Assert.IsTrue(spanScorer.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "no second doc");
		}
Exemplo n.º 4
0
		public virtual void  TestCustomSimilarity()
		{
			RAMDirectory dir = new RAMDirectory();
			InitIndex(dir, 10, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...
			IndexSearcher srchr = new IndexSearcher(dir);
			MultiSearcher msrchr = GetMultiSearcherInstance(new Searcher[]{srchr});
			
			Similarity customSimilarity = new AnonymousClassDefaultSimilarity(this);
			
			srchr.SetSimilarity(customSimilarity);
			msrchr.SetSimilarity(customSimilarity);
			
			Query query = new TermQuery(new Term("contents", "doc0"));
			
			// Get a score from IndexSearcher
			TopDocs topDocs = srchr.Search(query, null, 1);
			float score1 = topDocs.GetMaxScore();
			
			// Get the score from MultiSearcher
			topDocs = msrchr.Search(query, null, 1);
			float scoreN = topDocs.GetMaxScore();
			
			// The scores from the IndexSearcher and Multisearcher should be the same
			// if the same similarity is used.
			Assert.AreEqual(score1, scoreN, 1e-6, "MultiSearcher score must be equal to single esrcher score!");
		}