Example #1
0
        public virtual void  TestNext()
        {
            Term      allTerm   = new Term(FIELD, "all");
            TermQuery termQuery = new TermQuery(allTerm);

            Weight weight = termQuery.Weight(indexSearcher);

            TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));

            Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc");
            Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
            Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc");
            Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
            Assert.IsTrue(ts.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "next returned a doc and it should not have");
        }
Example #2
0
        public virtual void  Test()
        {
            Term      allTerm   = new Term(FIELD, "all");
            TermQuery termQuery = new TermQuery(allTerm);

            Weight weight = termQuery.Weight(indexSearcher);

            TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));

            //we have 2 documents with the term all in them, one document for all the other values
            System.Collections.IList docs = new System.Collections.ArrayList();
            //must call next first


            ts.Score(new AnonymousClassCollector(docs, this));
            Assert.IsTrue(docs.Count == 2, "docs Size: " + docs.Count + " is not: " + 2);
            TestHit doc0 = (TestHit)docs[0];
            TestHit doc5 = (TestHit)docs[1];

            //The scores should be the same
            Assert.IsTrue(doc0.score == doc5.score, doc0.score + " does not equal: " + doc5.score);

            /*
             * Score should be (based on Default Sim.:
             * All floats are approximate
             * tf = 1
             * numDocs = 6
             * docFreq(all) = 2
             * idf = ln(6/3) + 1 = 1.693147
             * idf ^ 2 = 2.8667
             * boost = 1
             * lengthNorm = 1 //there is 1 term in every document
             * coord = 1
             * sumOfSquaredWeights = (idf * boost) ^ 2 = 1.693147 ^ 2 = 2.8667
             * queryNorm = 1 / (sumOfSquaredWeights)^0.5 = 1 /(1.693147) = 0.590
             *
             * score = 1 * 2.8667 * 1 * 1 * 0.590 = 1.69
             *
             */
            Assert.IsTrue(doc0.score == 1.6931472f, doc0.score + " does not equal: " + 1.6931472f);
        }
Example #3
0
		public virtual void  Test()
		{
			
			Term allTerm = new Term(FIELD, "all");
			TermQuery termQuery = new TermQuery(allTerm);
			
			Weight weight = termQuery.Weight(indexSearcher);
			
			TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			//we have 2 documents with the term all in them, one document for all the other values
			System.Collections.IList docs = new System.Collections.ArrayList();
			//must call next first
			
			
			ts.Score(new AnonymousClassCollector(docs, this));
			Assert.IsTrue(docs.Count == 2, "docs Size: " + docs.Count + " is not: " + 2);
			TestHit doc0 = (TestHit) docs[0];
			TestHit doc5 = (TestHit) docs[1];
			//The scores should be the same
			Assert.IsTrue(doc0.score == doc5.score, doc0.score + " does not equal: " + doc5.score);
			/*
			Score should be (based on Default Sim.:
			All floats are approximate
			tf = 1
			numDocs = 6
			docFreq(all) = 2
			idf = ln(6/3) + 1 = 1.693147
			idf ^ 2 = 2.8667
			boost = 1
			lengthNorm = 1 //there is 1 term in every document
			coord = 1
			sumOfSquaredWeights = (idf * boost) ^ 2 = 1.693147 ^ 2 = 2.8667
			queryNorm = 1 / (sumOfSquaredWeights)^0.5 = 1 /(1.693147) = 0.590
			
			score = 1 * 2.8667 * 1 * 1 * 0.590 = 1.69
			
			*/
			Assert.IsTrue(doc0.score == 1.6931472f, doc0.score + " does not equal: " + 1.6931472f);
		}
Example #4
0
		public virtual void  TestNext()
		{
			
			Term allTerm = new Term(FIELD, "all");
			TermQuery termQuery = new TermQuery(allTerm);
			
			Weight weight = termQuery.Weight(indexSearcher);
			
			TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc");
			Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
			Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc");
			Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
			Assert.IsTrue(ts.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "next returned a doc and it should not have");
		}
		public virtual void  TestNext()
		{
			
			Term allTerm = new Term(FIELD, "all");
			TermQuery termQuery = new TermQuery(allTerm);
			
			Weight weight = termQuery.Weight(indexSearcher);
			
			TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			Assert.IsTrue(ts != null, "ts is null and it shouldn't be");
			Assert.IsTrue(ts.Next() == true, "next did not return a doc");
			Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
			Assert.IsTrue(ts.Next() == true, "next did not return a doc");
			Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
			Assert.IsTrue(ts.Next() == false, "next returned a doc and it should not have");
		}