public override void  SetScorer(Scorer scorer)
		{
			// Set a ScoreCachingWrappingScorer in case the wrapped Collector will call
			// score() also.
			this.scorer = new ScoreCachingWrappingScorer(scorer);
			c.SetScorer(this.scorer);
		}
Beispiel #2
0
		public ConjunctionScorer(Similarity similarity, Scorer[] scorers):base(similarity)
		{
			this.scorers = scorers;
			coord = similarity.Coord(scorers.Length, scorers.Length);
			
			for (int i = 0; i < scorers.Length; i++)
			{
				if (scorers[i].NextDoc() == NO_MORE_DOCS)
				{
					// If even one of the sub-scorers does not have any documents, this
					// scorer should not attempt to do any more work.
					lastDoc = NO_MORE_DOCS;
					return ;
				}
			}
			
			// Sort the array the first time...
			// We don't need to sort the array in any future calls because we know
			// it will already start off sorted (all scorers on same doc).
			
			// note that this comparator is not consistent with equals!
			System.Array.Sort(scorers, new AnonymousClassComparator(this));
			
			// NOTE: doNext() must be called before the re-sorting of the array later on.
			// The reason is this: assume there are 5 scorers, whose first docs are 1,
			// 2, 3, 5, 5 respectively. Sorting (above) leaves the array as is. Calling
			// doNext() here advances all the first scorers to 5 (or a larger doc ID
			// they all agree on). 
			// However, if we re-sort before doNext() is called, the order will be 5, 3,
			// 2, 1, 5 and then doNext() will stop immediately, since the first scorer's
			// docs equals the last one. So the invariant that after calling doNext() 
			// all scorers are on the same doc ID is broken.
			if (DoNext() == NO_MORE_DOCS)
			{
				// The scorers did not agree on any document.
				lastDoc = NO_MORE_DOCS;
				return ;
			}
			
			// If first-time skip distance is any predictor of
			// scorer sparseness, then we should always try to skip first on
			// those scorers.
			// Keep last scorer in it's last place (it will be the first
			// to be skipped on), but reverse all of the others so that
			// they will be skipped on in order of original high skip.
			int end = scorers.Length - 1;
			int max = end >> 1;
			for (int i = 0; i < max; i++)
			{
				Scorer tmp = scorers[i];
				int idx = end - i - 1;
				scorers[i] = scorers[idx];
				scorers[idx] = tmp;
			}
		}
Beispiel #3
0
		/// <summary> Creates a new instance of DisjunctionMaxScorer
		/// 
		/// </summary>
		/// <param name="tieBreakerMultiplier">Multiplier applied to non-maximum-scoring subqueries for a
		/// document as they are summed into the result.
		/// </param>
		/// <param name="similarity">-- not used since our definition involves neither coord nor terms
		/// directly
		/// </param>
		/// <param name="subScorers">The sub scorers this Scorer should iterate on
		/// </param>
		/// <param name="numScorers">The actual number of scorers to iterate on. Note that the array's
		/// length may be larger than the actual number of scorers.
		/// </param>
		public DisjunctionMaxScorer(float tieBreakerMultiplier, Similarity similarity, Scorer[] subScorers, int numScorers):base(similarity)
		{
			
			this.tieBreakerMultiplier = tieBreakerMultiplier;
			// The passed subScorers array includes only scorers which have documents
			// (DisjunctionMaxQuery takes care of that), and their nextDoc() was already
			// called.
			this.subScorers = subScorers;
			this.numScorers = numScorers;
			
			Heapify();
		}
Beispiel #4
0
			public override void  SetScorer(Scorer scorer)
			{
				// wrap with a ScoreCachingWrappingScorer so that successive calls to
				// score() will not incur score computation over and over again.
				this.scorer = new ScoreCachingWrappingScorer(scorer);
			}
Beispiel #5
0
			public override void  SetScorer(Scorer scorer)
			{
				this.scorer = scorer;
			}
Beispiel #6
0
			public override void  SetScorer(Scorer scorer)
			{
				collector.SetScorer(scorer);
			}
Beispiel #7
0
		/// <summary> Called before successive calls to {@link #Collect(int)}. Implementations
		/// that need the score of the current document (passed-in to
		/// {@link #Collect(int)}), should save the passed-in Scorer and call
		/// scorer.score() when needed.
		/// </summary>
		public abstract void  SetScorer(Scorer scorer);
Beispiel #8
0
			public override void  SetScorer(Scorer scorer)
			{
				// set the scorer on all comparators
				for (int i = 0; i < comparators.Length; i++)
				{
					comparators[i].SetScorer(scorer);
				}
			}
Beispiel #9
0
		private Scorer DualConjunctionSumScorer(Scorer req1, Scorer req2)
		{
			// non counting.
			return new ConjunctionScorer(defaultSimilarity, new Scorer[]{req1, req2});
			// All scorers match, so defaultSimilarity always has 1 as
			// the coordination factor.
			// Therefore the sum of the scores of two scorers
			// is used as score.
		}
Beispiel #10
0
			internal SingleMatchScorer(BooleanScorer2 enclosingInstance, Scorer scorer):base(scorer.GetSimilarity())
			{
				InitBlock(enclosingInstance);
				this.scorer = scorer;
			}
Beispiel #11
0
		/// <summary> Creates a {@link Scorer} with the given similarity and lists of required,
		/// prohibited and optional scorers. In no required scorers are added, at least
		/// one of the optional scorers will have to match during the search.
		/// 
		/// </summary>
		/// <param name="similarity">The similarity to be used.
		/// </param>
		/// <param name="minNrShouldMatch">The minimum number of optional added scorers that should match
		/// during the search. In case no required scorers are added, at least
		/// one of the optional scorers will have to match during the search.
		/// </param>
		/// <param name="required">the list of required scorers.
		/// </param>
		/// <param name="prohibited">the list of prohibited scorers.
		/// </param>
		/// <param name="optional">the list of optional scorers.
		/// </param>
		public BooleanScorer2(Similarity similarity, int minNrShouldMatch, System.Collections.IList required, System.Collections.IList prohibited, System.Collections.IList optional):base(similarity)
		{
			if (minNrShouldMatch < 0)
			{
				throw new System.ArgumentException("Minimum number of optional scorers should not be negative");
			}
			coordinator = new Coordinator(this);
			this.minNrShouldMatch = minNrShouldMatch;
			
			optionalScorers = optional;
			coordinator.maxCoord += optional.Count;
			
			requiredScorers = required;
			coordinator.maxCoord += required.Count;
			
			prohibitedScorers = prohibited;
			
			coordinator.Init();
			countingSumScorer = MakeCountingSumScorer();
		}
Beispiel #12
0
		/// <summary>Returns the score of the current document matching the query.
		/// Initially invalid, until {@link #Next()} is called the first time.
		/// </summary>
		/// <returns> The score of the required scorer, eventually increased by the score
		/// of the optional scorer when it also matches the current document.
		/// </returns>
		public override float Score()
		{
			int curDoc = reqScorer.DocID();
			float reqScore = reqScorer.Score();
			if (optScorer == null)
			{
				return reqScore;
			}
			
			int optScorerDoc = optScorer.DocID();
			if (optScorerDoc < curDoc && (optScorerDoc = optScorer.Advance(curDoc)) == NO_MORE_DOCS)
			{
				optScorer = null;
				return reqScore;
			}
			
			return optScorerDoc == curDoc?reqScore + optScorer.Score():reqScore;
		}
Beispiel #13
0
		/// <summary>Construct a <code>ReqOptScorer</code>.</summary>
		/// <param name="reqScorer">The required scorer. This must match.
		/// </param>
		/// <param name="optScorer">The optional scorer. This is used for scoring only.
		/// </param>
		public ReqOptSumScorer(Scorer reqScorer, Scorer optScorer):base(null)
		{ // No similarity used.
			this.reqScorer = reqScorer;
			this.optScorer = optScorer;
		}
Beispiel #14
0
 /// <summary> Called before successive calls to {@link #Collect(int)}. Implementations
 /// that need the score of the current document (passed-in to
 /// {@link #Collect(int)}), should save the passed-in Scorer and call
 /// scorer.score() when needed.
 /// </summary>
 public abstract void  SetScorer(Scorer scorer);
Beispiel #15
0
			public override void  SetScorer(Scorer scorer)
			{
				comparator.SetScorer(scorer);
			}
Beispiel #16
0
			public override void  SetScorer(Scorer scorer)
			{
				this.scorer = scorer;
				comparator.SetScorer(scorer);
			}
Beispiel #17
0
		/// <summary>Returns the scorer to be used for match counting and score summing.
		/// Uses the given required scorer and the prohibitedScorers.
		/// </summary>
		/// <param name="requiredCountingSumScorer">A required scorer already built.
		/// </param>
		private Scorer AddProhibitedScorers(Scorer requiredCountingSumScorer)
		{
			return (prohibitedScorers.Count == 0)?requiredCountingSumScorer:new ReqExclScorer(requiredCountingSumScorer, ((prohibitedScorers.Count == 1)?(Scorer) prohibitedScorers[0]:new DisjunctionSumScorer(prohibitedScorers)));
		}
Beispiel #18
0
			public override void  SetScorer(Scorer scorer)
			{
				this.scorer = scorer;
				base.SetScorer(scorer);
			}
 /// <summary>Creates a new instance by wrapping the given scorer. </summary>
 public ScoreCachingWrappingScorer(Scorer scorer) : base(scorer.GetSimilarity())
 {
     this.scorer = scorer;
 }
Beispiel #20
0
            public override Explanation Explain(IndexReader reader, int doc)
            {
                ComplexExplanation result = new ComplexExplanation();

                result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");

                Explanation idfExpl = new Explanation(idf, "idf(" + GetQuery() + ")");

                // explain query weight
                Explanation queryExpl = new Explanation();

                queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");

                Explanation boostExpl = new Explanation(Enclosing_Instance.GetBoost(), "boost");

                if (Enclosing_Instance.GetBoost() != 1.0f)
                {
                    queryExpl.AddDetail(boostExpl);
                }

                queryExpl.AddDetail(idfExpl);

                Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");

                queryExpl.AddDetail(queryNormExpl);

                queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

                result.AddDetail(queryExpl);

                // explain field weight
                ComplexExplanation fieldExpl = new ComplexExplanation();

                fieldExpl.SetDescription("fieldWeight(" + GetQuery() + " in " + doc + "), product of:");

                Scorer scorer = Scorer(reader, true, false);

                if (scorer == null)
                {
                    return(new Explanation(0.0f, "no matching docs"));
                }
                Explanation tfExpl = scorer.Explain(doc);

                fieldExpl.AddDetail(tfExpl);
                fieldExpl.AddDetail(idfExpl);

                Explanation fieldNormExpl = new Explanation();

                byte[] fieldNorms = reader.Norms(Enclosing_Instance.field);
                float  fieldNorm  = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]) : 1.0f;

                fieldNormExpl.SetValue(fieldNorm);
                fieldNormExpl.SetDescription("fieldNorm(field=" + Enclosing_Instance.field + ", doc=" + doc + ")");
                fieldExpl.AddDetail(fieldNormExpl);

                fieldExpl.SetMatch(tfExpl.IsMatch());
                fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

                result.AddDetail(fieldExpl);
                System.Boolean?tempAux = fieldExpl.GetMatch();
                result.SetMatch(tempAux);

                // combine them
                result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

                if (queryExpl.GetValue() == 1.0f)
                {
                    return(fieldExpl);
                }

                return(result);
            }
		/// <summary>Creates a new instance by wrapping the given scorer. </summary>
		public ScoreCachingWrappingScorer(Scorer scorer):base(scorer.GetSimilarity())
		{
			this.scorer = scorer;
		}
Beispiel #22
0
			/* Create the scorer used to score our associated DisjunctionMaxQuery */
			public override Scorer Scorer(IndexReader reader, bool scoreDocsInOrder, bool topScorer)
			{
				Scorer[] scorers = new Scorer[weights.Count];
				int idx = 0;
				for (System.Collections.IEnumerator iter = weights.GetEnumerator(); iter.MoveNext(); )
				{
					Weight w = (Weight) iter.Current;
					Scorer subScorer = w.Scorer(reader, true, false);
					if (subScorer != null && subScorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
					{
						scorers[idx++] = subScorer;
					}
				}
				if (idx == 0)
					return null; // all scorers did not have documents
				DisjunctionMaxScorer result = new DisjunctionMaxScorer(Enclosing_Instance.tieBreakerMultiplier, similarity, scorers, idx);
				return result;
			}
Beispiel #23
0
			public override void  SetScorer(Scorer scorer)
			{
				// score is not needed by this collector 
			}
Beispiel #24
0
			public SubScorer(Scorer scorer, bool required, bool prohibited, Collector collector, SubScorer next)
			{
				this.scorer = scorer;
				this.required = required;
				this.prohibited = prohibited;
				this.collector = collector;
				this.next = next;
			}
Beispiel #25
0
		/// <summary>Sets the Scorer to use in case a document's score is
		/// needed.
		/// 
		/// </summary>
		/// <param name="scorer">Scorer instance that you should use to
		/// obtain the current hit's score, if necessary. 
		/// </param>
		public virtual void  SetScorer(Scorer scorer)
		{
			// Empty implementation since most comparators don't need the score. This
			// can be overridden by those that need it.
		}