Пример #1
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();
        }
Пример #2
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());
         }
     }
 }
Пример #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.

            Similarity sim = Similarity.GetDefault();

            Scorer[]      scorers = new Scorer[] { new AnonymousClassScorer(this, sim) };
            BooleanScorer bs      = new BooleanScorer(sim, 1, new System.Collections.ArrayList(scorers), null);

            Assert.AreEqual(3000, bs.NextDoc(), "should have received 3000");
            Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, bs.NextDoc(), "should have received NO_MORE_DOCS");
        }
Пример #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(
#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();
        }
Пример #5
0
 public BucketTable(BooleanScorer scorer)
 {
     InitBlock();
     this.scorer = scorer;
 }
Пример #6
0
            /// <returns> A good old 1.4 Scorer
            /// </returns>
            public virtual Scorer Scorer(IndexReader reader)
            {
                // First see if the (faster) ConjunctionScorer will work.  This can be
                // used when all clauses are required.  Also, at this point a
                // BooleanScorer cannot be embedded in a ConjunctionScorer, as the hits
                // from a BooleanScorer are not always sorted by document number (sigh)
                // and hence BooleanScorer cannot implement skipTo() correctly, which is
                // required by ConjunctionScorer.
                bool allRequired = true;
                bool noneBoolean = true;

                for (int i = 0; i < weights.Count; i++)
                {
                    BooleanClause c = (BooleanClause)Enclosing_Instance.clauses[i];
                    if (!c.IsRequired())
                    {
                        allRequired = false;
                    }
                    if (c.GetQuery() is BooleanQuery)
                    {
                        noneBoolean = false;
                    }
                }

                if (allRequired && noneBoolean)
                {
                    // ConjunctionScorer is okay
                    ConjunctionScorer result = new ConjunctionScorer(similarity);
                    for (int i = 0; i < weights.Count; i++)
                    {
                        Weight w         = (Weight)weights[i];
                        Scorer subScorer = w.Scorer(reader);
                        if (subScorer == null)
                        {
                            return(null);
                        }
                        result.Add(subScorer);
                    }
                    return(result);
                }

                // Use good-old BooleanScorer instead.
                BooleanScorer result2 = new BooleanScorer(similarity);

                for (int i = 0; i < weights.Count; i++)
                {
                    BooleanClause c         = (BooleanClause)Enclosing_Instance.clauses[i];
                    Weight        w         = (Weight)weights[i];
                    Scorer        subScorer = w.Scorer(reader);
                    if (subScorer != null)
                    {
                        result2.Add(subScorer, c.IsRequired(), c.IsProhibited());
                    }
                    else if (c.IsRequired())
                    {
                        return(null);
                    }
                }

                return(result2);
            }
Пример #7
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();
        }
Пример #8
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());
				}
			}
		}
Пример #9
0
			/// <returns> A good old 1.4 Scorer 
			/// </returns>
			public virtual Scorer Scorer(IndexReader reader)
			{
				// First see if the (faster) ConjunctionScorer will work.  This can be
				// used when all clauses are required.  Also, at this point a
				// BooleanScorer cannot be embedded in a ConjunctionScorer, as the hits
				// from a BooleanScorer are not always sorted by document number (sigh)
				// and hence BooleanScorer cannot implement skipTo() correctly, which is
				// required by ConjunctionScorer.
				bool allRequired = true;
				bool noneBoolean = true;
				for (int i = 0; i < weights.Count; i++)
				{
					BooleanClause c = (BooleanClause) Enclosing_Instance.clauses[i];
					if (!c.IsRequired())
						allRequired = false;
					if (c.GetQuery() is BooleanQuery)
						noneBoolean = false;
				}
				
				if (allRequired && noneBoolean)
				{
					// ConjunctionScorer is okay
					ConjunctionScorer result = new ConjunctionScorer(similarity);
					for (int i = 0; i < weights.Count; i++)
					{
						Weight w = (Weight) weights[i];
						Scorer subScorer = w.Scorer(reader);
						if (subScorer == null)
							return null;
						result.Add(subScorer);
					}
					return result;
				}
				
				// Use good-old BooleanScorer instead.
				BooleanScorer result2 = new BooleanScorer(similarity);
				
				for (int i = 0; i < weights.Count; i++)
				{
					BooleanClause c = (BooleanClause) Enclosing_Instance.clauses[i];
					Weight w = (Weight) weights[i];
					Scorer subScorer = w.Scorer(reader);
					if (subScorer != null)
						result2.Add(subScorer, c.IsRequired(), c.IsProhibited());
					else if (c.IsRequired())
						return null;
				}
				
				return result2;
			}
Пример #10
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.
			
			Similarity sim = Similarity.GetDefault();
			Scorer[] scorers = new Scorer[]{new AnonymousClassScorer(this, sim)};
			BooleanScorer bs = new BooleanScorer(sim, 1, new System.Collections.ArrayList(scorers), null);
			
			Assert.AreEqual(3000, bs.NextDoc(), "should have received 3000");
			Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, bs.NextDoc(), "should have received NO_MORE_DOCS");
		}
Пример #11
0
			public BucketTable(BooleanScorer scorer)
			{
                InitBlock();
				this.scorer = scorer;
			}