Esempio n. 1
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;
            }
        }
Esempio n. 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;
			}
		}
Esempio n. 3
0
            internal int nrMatchers;             // to be increased by score() of match counting scorers.

            internal virtual void  Init()
            {
                // use after all scorers have been added.
                coordFactors = new float[maxCoord + 1];
                Similarity sim = Enclosing_Instance.GetSimilarity();

                for (int i = 0; i <= maxCoord; i++)
                {
                    coordFactors[i] = sim.Coord(i, maxCoord);
                }
            }
Esempio n. 4
0
        public /*internal*/ BooleanScorer(Similarity similarity, int minNrShouldMatch, System.Collections.IList optionalScorers, System.Collections.IList prohibitedScorers) : base(similarity)
        {
            InitBlock();
            this.minNrShouldMatch = minNrShouldMatch;

            if (optionalScorers != null && optionalScorers.Count > 0)
            {
                for (System.Collections.IEnumerator si = optionalScorers.GetEnumerator(); si.MoveNext();)
                {
                    Scorer scorer = (Scorer)si.Current;
                    maxCoord++;
                    if (scorer.NextDoc() != NO_MORE_DOCS)
                    {
                        scorers = new SubScorer(scorer, false, false, bucketTable.NewCollector(0), scorers);
                    }
                }
            }

            if (prohibitedScorers != null && prohibitedScorers.Count > 0)
            {
                for (System.Collections.IEnumerator si = prohibitedScorers.GetEnumerator(); si.MoveNext();)
                {
                    Scorer scorer = (Scorer)si.Current;
                    int    mask   = nextMask;
                    nextMask        = nextMask << 1;
                    prohibitedMask |= mask;                     // update prohibited mask
                    if (scorer.NextDoc() != NO_MORE_DOCS)
                    {
                        scorers = new SubScorer(scorer, false, true, bucketTable.NewCollector(mask), scorers);
                    }
                }
            }

            coordFactors = new float[maxCoord];
            Similarity sim = GetSimilarity();

            for (int i = 0; i < maxCoord; i++)
            {
                coordFactors[i] = sim.Coord(i, maxCoord - 1);
            }
        }
Esempio n. 5
0
 public override float Coord(int overlap, int maxOverlap)
 {
     return(delegee.Coord(overlap, maxOverlap));
 }
Esempio n. 6
0
            public override Explanation Explain(IndexReader reader, int doc)
            {
                int minShouldMatch         = Enclosing_Instance.GetMinimumNumberShouldMatch();
                ComplexExplanation sumExpl = new ComplexExplanation();

                sumExpl.SetDescription("sum of:");
                int   coord            = 0;
                int   maxCoord         = 0;
                float sum              = 0.0f;
                bool  fail             = false;
                int   shouldMatchCount = 0;

                for (System.Collections.IEnumerator wIter = weights.GetEnumerator(), cIter = Enclosing_Instance.clauses.GetEnumerator(); wIter.MoveNext();)
                {
                    cIter.MoveNext();

                    Weight        w = (Weight)wIter.Current;
                    BooleanClause c = (BooleanClause)cIter.Current;
                    if (w.Scorer(reader, true, true) == null)
                    {
                        continue;
                    }
                    Explanation e = w.Explain(reader, doc);
                    if (!c.IsProhibited())
                    {
                        maxCoord++;
                    }
                    if (e.IsMatch())
                    {
                        if (!c.IsProhibited())
                        {
                            sumExpl.AddDetail(e);
                            sum += e.GetValue();
                            coord++;
                        }
                        else
                        {
                            Explanation r = new Explanation(0.0f, "match on prohibited clause (" + c.GetQuery().ToString() + ")");
                            r.AddDetail(e);
                            sumExpl.AddDetail(r);
                            fail = true;
                        }
                        if (c.GetOccur() == Occur.SHOULD)
                        {
                            shouldMatchCount++;
                        }
                    }
                    else if (c.IsRequired())
                    {
                        Explanation r = new Explanation(0.0f, "no match on required clause (" + c.GetQuery().ToString() + ")");
                        r.AddDetail(e);
                        sumExpl.AddDetail(r);
                        fail = true;
                    }
                }
                if (fail)
                {
                    System.Boolean tempAux = false;
                    sumExpl.SetMatch(tempAux);
                    sumExpl.SetValue(0.0f);
                    sumExpl.SetDescription("Failure to meet condition(s) of required/prohibited clause(s)");
                    return(sumExpl);
                }
                else if (shouldMatchCount < minShouldMatch)
                {
                    System.Boolean tempAux2 = false;
                    sumExpl.SetMatch(tempAux2);
                    sumExpl.SetValue(0.0f);
                    sumExpl.SetDescription("Failure to match minimum number " + "of optional clauses: " + minShouldMatch);
                    return(sumExpl);
                }

                sumExpl.SetMatch(0 < coord?true:false);
                sumExpl.SetValue(sum);

                float coordFactor = similarity.Coord(coord, maxCoord);

                if (coordFactor == 1.0f)
                {
                    // coord is no-op
                    return(sumExpl);
                }
                // eliminate wrapper
                else
                {
                    ComplexExplanation result = new ComplexExplanation(sumExpl.IsMatch(), sum * coordFactor, "product of:");
                    result.AddDetail(sumExpl);
                    result.AddDetail(new Explanation(coordFactor, "coord(" + coord + "/" + maxCoord + ")"));
                    return(result);
                }
            }