Esempio n. 1
0
 /// <summary>Scores and collects all matching documents.</summary>
 /// <param name="hc">The collector to which all matching documents are passed through
 /// {@link HitCollector#Collect(int, float)}.
 /// <br>When this method is used the {@link #Explain(int)} method should not be used.
 /// </param>
 public override void  Score(HitCollector hc)
 {
     if (allowDocsOutOfOrder && requiredScorers.Count == 0 && prohibitedScorers.Count < 32)
     {
         // fall back to BooleanScorer, scores documents somewhat out of order
         BooleanScorer bs = new BooleanScorer(GetSimilarity(), minNrShouldMatch);
         System.Collections.IEnumerator si = optionalScorers.GetEnumerator();
         while (si.MoveNext())
         {
             bs.Add((Scorer)si.Current, false, false);
         }
         si = prohibitedScorers.GetEnumerator();
         while (si.MoveNext())
         {
             bs.Add((Scorer)si.Current, false, true);
         }
         bs.Score(hc);
     }
     else
     {
         if (countingSumScorer == null)
         {
             InitCountingSumScorer();
         }
         while (countingSumScorer.Next())
         {
             hc.Collect(countingSumScorer.Doc(), Score());
         }
     }
 }
Esempio n. 2
0
        public virtual void TestEmptyBucketWithMoreDocs()
        {
            // this test checks the logic of nextDoc() when all sub scorers have docs
            // beyond the first bucket (for example). Currently, the code relies on the
            // 'more' variable to work properly, and this test ensures that if the logic
            // changes, we have a test to back it up.

            Directory         directory = NewDirectory();
            RandomIndexWriter writer    = new RandomIndexWriter(Random(), directory, Similarity, TimeZone);

            writer.Commit();
            IndexReader ir = writer.Reader;

            writer.Dispose();
            IndexSearcher searcher = NewSearcher(ir);
            BooleanWeight weight   = (BooleanWeight)(new BooleanQuery()).CreateWeight(searcher);

            BulkScorer[] scorers = new BulkScorer[] {
                new BulkScorerAnonymousInnerClassHelper()
            };

            BooleanScorer bs = new BooleanScorer(weight, false, 1, Arrays.AsList(scorers), new List <BulkScorer>(), scorers.Length);

            IList <int> hits = new List <int>();

            bs.Score(new CollectorAnonymousInnerClassHelper(this, hits));

            Assert.AreEqual(1, hits.Count, "should have only 1 hit");
            Assert.AreEqual(3000, (int)hits[0], "hit should have been docID=3000");
            ir.Dispose();
            directory.Dispose();
        }
Esempio n. 3
0
        public virtual void TestEmptyBucketWithMoreDocs()
        {
            // this test checks the logic of nextDoc() when all sub scorers have docs
            // beyond the first bucket (for example). Currently, the code relies on the
            // 'more' variable to work properly, and this test ensures that if the logic
            // changes, we have a test to back it up.

            Directory         directory = NewDirectory();
            RandomIndexWriter writer    = new RandomIndexWriter(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                this,
#endif
                Random, directory);

            writer.Commit();
            IndexReader ir = writer.GetReader();

            writer.Dispose();
            IndexSearcher searcher = NewSearcher(ir);
            BooleanWeight weight   = (BooleanWeight)(new BooleanQuery()).CreateWeight(searcher);

            BulkScorer[] scorers = new BulkScorer[] {
                new BulkScorerAnonymousClass()
            };

            BooleanScorer bs = new BooleanScorer(weight, false, 1, scorers, Collections.EmptyList <BulkScorer>(), scorers.Length);

            IList <int> hits = new JCG.List <int>();

            bs.Score(new CollectorAnonymousClass(this, hits));

            Assert.AreEqual(1, hits.Count, "should have only 1 hit");
            Assert.AreEqual(3000, (int)hits[0], "hit should have been docID=3000");
            ir.Dispose();
            directory.Dispose();
        }
Esempio n. 4
0
        public virtual void TestEmptyBucketWithMoreDocs()
        {
            // this test checks the logic of nextDoc() when all sub scorers have docs
            // beyond the first bucket (for example). Currently, the code relies on the
            // 'more' variable to work properly, and this test ensures that if the logic
            // changes, we have a test to back it up.

            Directory directory = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), directory);
            writer.Commit();
            IndexReader ir = writer.Reader;
            writer.Dispose();
            IndexSearcher searcher = NewSearcher(ir);
            BooleanWeight weight = (BooleanWeight)(new BooleanQuery()).CreateWeight(searcher);

            BulkScorer[] scorers = new BulkScorer[] {
            new BulkScorerAnonymousInnerClassHelper()
            };

            BooleanScorer bs = new BooleanScorer(weight, false, 1, Arrays.AsList(scorers), new List<BulkScorer>(), scorers.Length);

            IList<int> hits = new List<int>();
            bs.Score(new CollectorAnonymousInnerClassHelper(this, hits));

            Assert.AreEqual(1, hits.Count, "should have only 1 hit");
            Assert.AreEqual(3000, (int)hits[0], "hit should have been docID=3000");
            ir.Dispose();
            directory.Dispose();
        }
		/// <summary>Scores and collects all matching documents.</summary>
		/// <param name="hc">The collector to which all matching documents are passed through
		/// {@link HitCollector#Collect(int, float)}.
		/// <br>When this method is used the {@link #Explain(int)} method should not be used.
		/// </param>
		public override void  Score(HitCollector hc)
		{
			if (allowDocsOutOfOrder && requiredScorers.Count == 0 && prohibitedScorers.Count < 32)
			{
				// fall back to BooleanScorer, scores documents somewhat out of order
				BooleanScorer bs = new BooleanScorer(GetSimilarity(), minNrShouldMatch);
				System.Collections.IEnumerator si = optionalScorers.GetEnumerator();
				while (si.MoveNext())
				{
					bs.Add((Scorer) si.Current, false, false);
				}
				si = prohibitedScorers.GetEnumerator();
				while (si.MoveNext())
				{
					bs.Add((Scorer) si.Current, false, true);
				}
				bs.Score(hc);
			}
			else
			{
				if (countingSumScorer == null)
				{
					InitCountingSumScorer();
				}
				while (countingSumScorer.Next())
				{
					hc.Collect(countingSumScorer.Doc(), Score());
				}
			}
		}