public virtual void  Test()
        {
            BoostingTermQuery query = new BoostingTermQuery(new Term("field", "seventy"));
            TopDocs           hits  = searcher.Search(query, null, 100);

            Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
            Assert.IsTrue(hits.TotalHits == 100, "hits Size: " + hits.TotalHits + " is not: " + 100);

            //they should all have the exact same score, because they all contain seventy once, and we set
            //all the other similarity factors to be 1

            Assert.IsTrue(hits.GetMaxScore() == 1, hits.GetMaxScore() + " does not equal: " + 1);
            for (int i = 0; i < hits.ScoreDocs.Length; i++)
            {
                ScoreDoc doc = hits.ScoreDocs[i];
                Assert.IsTrue(doc.score == 1, doc.score + " does not equal: " + 1);
            }
            CheckHits.CheckExplanations(query, PayloadHelper.FIELD, searcher, true);
            Lucene.Net.Search.Spans.Spans spans = query.GetSpans(searcher.GetIndexReader());
            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
            Assert.IsTrue(spans is TermSpans, "spans is not an instanceof " + typeof(TermSpans));

            /*float score = hits.score(0);
             * for (int i =1; i < hits.length(); i++)
             * {
             * Assert.IsTrue(score == hits.score(i), "scores are not equal and they should be");
             * }*/
        }
        public virtual void  TestNoMatch()
        {
            BoostingTermQuery query = new BoostingTermQuery(new Term(PayloadHelper.FIELD, "junk"));
            TopDocs           hits  = searcher.Search(query, null, 100);

            Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
            Assert.IsTrue(hits.TotalHits == 0, "hits Size: " + hits.TotalHits + " is not: " + 0);
        }
Example #3
0
        public override bool Equals(object o)
        {
            if (!(o is BoostingTermQuery))
            {
                return(false);
            }
            BoostingTermQuery other = (BoostingTermQuery)o;

            return((this.GetBoost() == other.GetBoost()) && this.term.Equals(other.term));
        }
        public virtual void  TestMultipleMatchesPerDoc()
        {
            BoostingTermQuery query = new BoostingTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"));
            TopDocs           hits  = searcher.Search(query, null, 100);

            Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
            Assert.IsTrue(hits.TotalHits == 100, "hits Size: " + hits.TotalHits + " is not: " + 100);

            //they should all have the exact same score, because they all contain seventy once, and we set
            //all the other similarity factors to be 1

            //System.out.println("Hash: " + seventyHash + " Twice Hash: " + 2*seventyHash);
            Assert.IsTrue(hits.GetMaxScore() == 3, hits.GetMaxScore() + " does not equal: " + 3);
            //there should be exactly 10 items that score a 3, all the rest should score a 2
            //The 10 items are: 70 + i*100 where i in [0-9]
            int numTens = 0;

            for (int i = 0; i < hits.ScoreDocs.Length; i++)
            {
                ScoreDoc doc = hits.ScoreDocs[i];
                if (doc.doc % 10 == 0)
                {
                    numTens++;
                    Assert.IsTrue(doc.score == 3, doc.score + " does not equal: " + 3);
                }
                else
                {
                    Assert.IsTrue(doc.score == 2, doc.score + " does not equal: " + 2);
                }
            }
            Assert.IsTrue(numTens == 10, numTens + " does not equal: " + 10);
            CheckHits.CheckExplanations(query, "field", searcher, true);
            Lucene.Net.Search.Spans.Spans spans = query.GetSpans(searcher.GetIndexReader());
            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
            Assert.IsTrue(spans is TermSpans, "spans is not an instanceof " + typeof(TermSpans));
            //should be two matches per document
            int count = 0;

            //100 hits times 2 matches per hit, we should have 200 in count
            while (spans.Next())
            {
                count++;
            }
            Assert.IsTrue(count == 200, count + " does not equal: " + 200);
        }
        public virtual void  TestNoPayload()
        {
            BoostingTermQuery q1    = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "zero"));
            BoostingTermQuery q2    = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "foo"));
            BooleanClause     c1    = new BooleanClause(q1, BooleanClause.Occur.MUST);
            BooleanClause     c2    = new BooleanClause(q2, BooleanClause.Occur.MUST_NOT);
            BooleanQuery      query = new BooleanQuery();

            query.Add(c1);
            query.Add(c2);
            TopDocs hits = searcher.Search(query, null, 100);

            Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
            Assert.IsTrue(hits.TotalHits == 1, "hits Size: " + hits.TotalHits + " is not: " + 1);
            int[] results = new int[1];
            results[0] = 0;             //hits.scoreDocs[0].doc;
            CheckHits.CheckHitCollector(query, PayloadHelper.NO_PAYLOAD_FIELD, searcher, results);
        }
		public virtual void  TestNoPayload()
		{
			BoostingTermQuery q1 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "zero"));
			BoostingTermQuery q2 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "foo"));
			BooleanClause c1 = new BooleanClause(q1, BooleanClause.Occur.MUST);
			BooleanClause c2 = new BooleanClause(q2, BooleanClause.Occur.MUST_NOT);
			BooleanQuery query = new BooleanQuery();
			query.Add(c1);
			query.Add(c2);
			TopDocs hits = searcher.Search(query, null, 100);
			Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
			Assert.IsTrue(hits.totalHits == 1, "hits Size: " + hits.totalHits + " is not: " + 1);
			int[] results = new int[1];
			results[0] = 0; //hits.scoreDocs[0].doc;
			CheckHits.CheckHitCollector(query, PayloadHelper.NO_PAYLOAD_FIELD, searcher, results);
		}
		public virtual void  TestNoMatch()
		{
			BoostingTermQuery query = new BoostingTermQuery(new Term(PayloadHelper.FIELD, "junk"));
			TopDocs hits = searcher.Search(query, null, 100);
			Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
			Assert.IsTrue(hits.totalHits == 0, "hits Size: " + hits.totalHits + " is not: " + 0);
		}
		public virtual void  TestMultipleMatchesPerDoc()
		{
			BoostingTermQuery query = new BoostingTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"));
			TopDocs hits = searcher.Search(query, null, 100);
			Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
			Assert.IsTrue(hits.totalHits == 100, "hits Size: " + hits.totalHits + " is not: " + 100);
			
			//they should all have the exact same score, because they all contain seventy once, and we set
			//all the other similarity factors to be 1
			
			//System.out.println("Hash: " + seventyHash + " Twice Hash: " + 2*seventyHash);
			Assert.IsTrue(hits.GetMaxScore() == 3, hits.GetMaxScore() + " does not equal: " + 3);
			//there should be exactly 10 items that score a 3, all the rest should score a 2
			//The 10 items are: 70 + i*100 where i in [0-9]
			int numTens = 0;
			for (int i = 0; i < hits.scoreDocs.Length; i++)
			{
				ScoreDoc doc = hits.scoreDocs[i];
				if (doc.doc % 10 == 0)
				{
					numTens++;
					Assert.IsTrue(doc.score == 3, doc.score + " does not equal: " + 3);
				}
				else
				{
					Assert.IsTrue(doc.score == 2, doc.score + " does not equal: " + 2);
				}
			}
			Assert.IsTrue(numTens == 10, numTens + " does not equal: " + 10);
			CheckHits.CheckExplanations(query, "field", searcher, true);
			Lucene.Net.Search.Spans.Spans spans = query.GetSpans(searcher.GetIndexReader());
			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
			Assert.IsTrue(spans is TermSpans, "spans is not an instanceof " + typeof(TermSpans));
			//should be two matches per document
			int count = 0;
			//100 hits times 2 matches per hit, we should have 200 in count
			while (spans.Next())
			{
				count++;
			}
			Assert.IsTrue(count == 200, count + " does not equal: " + 200);
		}
		public virtual void  Test()
		{
			BoostingTermQuery query = new BoostingTermQuery(new Term("field", "seventy"));
			TopDocs hits = searcher.Search(query, null, 100);
			Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
			Assert.IsTrue(hits.totalHits == 100, "hits Size: " + hits.totalHits + " is not: " + 100);
			
			//they should all have the exact same score, because they all contain seventy once, and we set
			//all the other similarity factors to be 1
			
			Assert.IsTrue(hits.GetMaxScore() == 1, hits.GetMaxScore() + " does not equal: " + 1);
			for (int i = 0; i < hits.scoreDocs.Length; i++)
			{
				ScoreDoc doc = hits.scoreDocs[i];
				Assert.IsTrue(doc.score == 1, doc.score + " does not equal: " + 1);
			}
			CheckHits.CheckExplanations(query, PayloadHelper.FIELD, searcher, true);
			Lucene.Net.Search.Spans.Spans spans = query.GetSpans(searcher.GetIndexReader());
			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
			Assert.IsTrue(spans is TermSpans, "spans is not an instanceof " + typeof(TermSpans));
            /*float score = hits.score(0);
            for (int i =1; i < hits.length(); i++)
            {
            Assert.IsTrue(score == hits.score(i), "scores are not equal and they should be");
            }*/
        }
Example #10
0
 public BoostingTermWeight(BoostingTermQuery enclosingInstance, BoostingTermQuery query, Searcher searcher) : base(query, searcher)
 {
     InitBlock(enclosingInstance);
 }
Example #11
0
 private void  InitBlock(BoostingTermQuery enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
Example #12
0
			public BoostingTermWeight(BoostingTermQuery enclosingInstance, BoostingTermQuery query, Searcher searcher):base(enclosingInstance, query, searcher)
			{
				InitBlock(enclosingInstance);
			}
Example #13
0
			private void  InitBlock(BoostingTermQuery enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}