Coord() public abstract method

Computes a score factor based on the fraction of all query terms that a document contains. This value is multiplied into scores.

The presence of a large portion of the query terms indicates a better match with the query, so implementations of this method usually return larger values when the ratio between these parameters is large and smaller values when the ratio between them is small.

public abstract Coord ( int overlap, int maxOverlap ) : float
overlap int the number of query terms matched in the document ///
maxOverlap int the total number of terms in the query ///
return float
コード例 #1
0
 public virtual float Coord(int overlap, int maxOverlap)
 {
     // LUCENE-4300: in most cases of maxOverlap=1, BQ rewrites itself away,
     // so coord() is not applied. But when BQ cannot optimize itself away
     // for a single clause (minNrShouldMatch, prohibited clauses, etc), its
     // important not to apply coord(1,1) for consistency, it might not be 1.0F
     return(maxOverlap == 1 ? 1F : similarity.Coord(overlap, maxOverlap));
 }
コード例 #2
0
        public ConjunctionScorer(Similarity similarity, params 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!
            Array.Sort <Scorer>(scorers, (x, y) => x.DocID() - y.DocID());

            // 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;
            }
        }
コード例 #3
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;
            }
        }
コード例 #4
0
            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);
                }
            }
コード例 #5
0
ファイル: BooleanScorer.cs プロジェクト: stgwilli/ravendb
        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);
            }
        }
コード例 #6
0
        public /*internal*/ BooleanScorer(Similarity similarity, int minNrShouldMatch,
                                          System.Collections.Generic.List <Scorer> optionalScorers, System.Collections.Generic.List <Scorer> prohibitedScorers)
            : base(similarity)
        {
            InitBlock();
            this.minNrShouldMatch = minNrShouldMatch;

            if (optionalScorers != null && optionalScorers.Count > 0)
            {
                foreach (Scorer scorer in optionalScorers)
                {
                    maxCoord++;
                    if (scorer.NextDoc() != NO_MORE_DOCS)
                    {
                        scorers = new SubScorer(scorer, false, false, bucketTable.NewCollector(0), scorers);
                    }
                }
            }

            if (prohibitedScorers != null && prohibitedScorers.Count > 0)
            {
                foreach (Scorer scorer in prohibitedScorers)
                {
                    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 = Similarity;

            for (int i = 0; i < maxCoord; i++)
            {
                coordFactors[i] = sim.Coord(i, maxCoord - 1);
            }
        }
コード例 #7
0
ファイル: BooleanQuery.cs プロジェクト: sainabob/teamlab.v7.5
            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);
                }
            }
コード例 #8
0
 public override float Coord(int overlap, int maxOverlap)
 {
     return(@base.Coord(overlap, maxOverlap));
 }
コード例 #9
0
            public virtual Explanation Explain(IndexReader reader, int doc)
            {
                Explanation sumExpl = new Explanation();

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

                for (int i = 0; i < weights.Count; i++)
                {
                    BooleanClause c = (BooleanClause)Enclosing_Instance.clauses[i];
                    Weight        w = (Weight)weights[i];
                    Explanation   e = w.Explain(reader, doc);
                    if (!c.IsProhibited())
                    {
                        maxCoord++;
                    }
                    if (e.GetValue() > 0)
                    {
                        if (!c.IsProhibited())
                        {
                            sumExpl.AddDetail(e);
                            sum += e.GetValue();
                            coord++;
                        }
                        else
                        {
                            return(new Explanation(0.0f, "match prohibited"));
                        }
                    }
                    else if (c.IsRequired())
                    {
                        return(new Explanation(0.0f, "match required"));
                    }
                }
                sumExpl.SetValue(sum);

                if (coord == 1)
                {
                    // only one clause matched
                    sumExpl = sumExpl.GetDetails()[0];                     // eliminate wrapper
                }
                float coordFactor = similarity.Coord(coord, maxCoord);

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