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
            /// <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);
            }
		/// <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. 4
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;
			}