Ejemplo n.º 1
0
        internal ExactPhraseScorer(Weight weight, PhraseQuery.PostingsAndFreq[] postings, Similarity.SimScorer docScorer)
            : base(weight)
        {
            this.docScorer = docScorer;

            chunkStates = new ChunkState[postings.Length];

            endMinus1 = postings.Length - 1;

            // min(cost)
            cost = postings[0].postings.GetCost();

            for (int i = 0; i < postings.Length; i++)
            {
                // Coarse optimization: advance(target) is fairly
                // costly, so, if the relative freq of the 2nd
                // rarest term is not that much (> 1/5th) rarer than
                // the first term, then we just use .nextDoc() when
                // ANDing.  this buys ~15% gain for phrases where
                // freq of rarest 2 terms is close:
                bool useAdvance = postings[i].docFreq > 5 * postings[0].docFreq;
                chunkStates[i] = new ChunkState(postings[i].postings, -postings[i].position, useAdvance);
                if (i > 0 && postings[i].postings.NextDoc() == DocIdSetIterator.NO_MORE_DOCS)
                {
                    noDocs = true;
                    return;
                }
            }
        }
Ejemplo n.º 2
0
 internal SloppyPhraseScorer(Weight weight, PhraseQuery.PostingsAndFreq[] postings, int slop, Similarity.SimScorer docScorer)
     : base(weight)
 {
     this.docScorer   = docScorer;
     this.slop        = slop;
     this.numPostings = postings == null ? 0 : postings.Length;
     pq = new PhraseQueue(postings.Length);
     // min(cost)
     cost = postings[0].postings.GetCost();
     // convert tps to a list of phrase positions.
     // note: phrase-position differs from term-position in that its position
     // reflects the phrase offset: pp.pos = tp.pos - offset.
     // this allows to easily identify a matching (exact) phrase
     // when all PhrasePositions have exactly the same position.
     if (postings.Length > 0)
     {
         min     = new PhrasePositions(postings[0].postings, postings[0].position, 0, postings[0].terms);
         max     = min;
         max.doc = -1;
         for (int i = 1; i < postings.Length; i++)
         {
             PhrasePositions pp = new PhrasePositions(postings[i].postings, postings[i].position, i, postings[i].terms);
             max.next = pp;
             max      = pp;
             max.doc  = -1;
         }
         max.next = min; // make it cyclic for easier manipulation
     }
 }
Ejemplo n.º 3
0
            public override Explanation Explain(AtomicReaderContext context, int doc)
            {
                PayloadNearSpanScorer scorer = (PayloadNearSpanScorer)GetScorer(context, (context.AtomicReader).LiveDocs);

                if (scorer != null)
                {
                    int newDoc = scorer.Advance(doc);
                    if (newDoc == doc)
                    {
                        float freq = scorer.Freq;
                        Similarity.SimScorer docScorer = m_similarity.GetSimScorer(m_stats, context);
                        Explanation          expl      = new Explanation();
                        expl.Description = "weight(" + Query + " in " + doc + ") [" + m_similarity.GetType().Name + "], result of:";
                        Explanation scoreExplanation = docScorer.Explain(doc, new Explanation(freq, "phraseFreq=" + freq));
                        expl.AddDetail(scoreExplanation);
                        expl.Value = scoreExplanation.Value;
                        string field = ((SpanQuery)Query).Field;
                        // now the payloads part
                        Explanation payloadExpl = outerInstance.m_function.Explain(doc, field, scorer.payloadsSeen, scorer.m_payloadScore);
                        // combined
                        ComplexExplanation result = new ComplexExplanation();
                        result.AddDetail(expl);
                        result.AddDetail(payloadExpl);
                        result.Value       = expl.Value * payloadExpl.Value;
                        result.Description = "PayloadNearQuery, product of:";
                        return(result);
                    }
                }

                return(new ComplexExplanation(false, 0.0f, "no matching term"));
            }
Ejemplo n.º 4
0
        protected internal SpanScorer(Spans spans, Weight weight, Similarity.SimScorer docScorer)
            : base(weight)
        {
            this.m_docScorer = docScorer;
            this.m_spans     = spans;

            m_doc  = -1;
            m_more = spans.Next();
        }
Ejemplo n.º 5
0
            public override Explanation Explain(AtomicReaderContext context, int doc)
            {
                PayloadTermSpanScorer scorer = (PayloadTermSpanScorer)Scorer(context, (context.AtomicReader).LiveDocs);

                if (scorer != null)
                {
                    int newDoc = scorer.Advance(doc);
                    if (newDoc == doc)
                    {
                        float freq = scorer.SloppyFreq();
                        Similarity.SimScorer docScorer = Similarity.DoSimScorer(Stats, context);
                        Explanation          expl      = new Explanation();
                        expl.Description = "weight(" + Query + " in " + doc + ") [" + Similarity.GetType().Name + "], result of:";
                        Explanation scoreExplanation = docScorer.Explain(doc, new Explanation(freq, "phraseFreq=" + freq));
                        expl.AddDetail(scoreExplanation);
                        expl.Value = scoreExplanation.Value;
                        // now the payloads part
                        // QUESTION: Is there a way to avoid this skipTo call? We need to know
                        // whether to load the payload or not
                        // GSI: I suppose we could toString the payload, but I don't think that
                        // would be a good idea
                        string      field       = ((SpanQuery)Query).Field;
                        Explanation payloadExpl = OuterInstance.Function.Explain(doc, field, scorer.PayloadsSeen, scorer.PayloadScore_Renamed);
                        payloadExpl.Value = scorer.PayloadScore;
                        // combined
                        ComplexExplanation result = new ComplexExplanation();
                        if (OuterInstance.IncludeSpanScore)
                        {
                            result.AddDetail(expl);
                            result.AddDetail(payloadExpl);
                            result.Value       = expl.Value * payloadExpl.Value;
                            result.Description = "btq, product of:";
                        }
                        else
                        {
                            result.AddDetail(payloadExpl);
                            result.Value       = payloadExpl.Value;
                            result.Description = "btq(includeSpanScore=false), result of:";
                        }
                        result.Match = true; // LUCENE-1303
                        return(result);
                    }
                }

                return(new ComplexExplanation(false, 0.0f, "no matching term"));
            }
Ejemplo n.º 6
0
        public override Explanation Explain(AtomicReaderContext context, int doc)
        {
            SpanScorer scorer = (SpanScorer)GetScorer(context, context.AtomicReader.LiveDocs);

            if (scorer != null)
            {
                int newDoc = scorer.Advance(doc);
                if (newDoc == doc)
                {
                    float freq = scorer.SloppyFreq;
                    Similarity.SimScorer docScorer = m_similarity.GetSimScorer(m_stats, context);
                    ComplexExplanation   result    = new ComplexExplanation();
                    result.Description = "weight(" + Query + " in " + doc + ") [" + m_similarity.GetType().Name + "], result of:";
                    Explanation scoreExplanation = docScorer.Explain(doc, new Explanation(freq, "phraseFreq=" + freq));
                    result.AddDetail(scoreExplanation);
                    result.Value = scoreExplanation.Value;
                    result.Match = true;
                    return(result);
                }
            }

            return(new ComplexExplanation(false, 0.0f, "no matching term"));
        }
Ejemplo n.º 7
0
 public PayloadTermSpanScorer(PayloadTermQuery.PayloadTermWeight outerInstance, TermSpans spans, Weight weight, Similarity.SimScorer docScorer)
     : base(spans, weight, docScorer)
 {
     this.OuterInstance = outerInstance;
     TermSpans          = spans;
 }
Ejemplo n.º 8
0
 protected internal PayloadNearSpanScorer(PayloadNearQuery outerInstance, Spans spans, Weight weight, Similarity similarity, Similarity.SimScorer docScorer)
     : base(spans, weight, docScorer)
 {
     this.outerInstance = outerInstance;
     this.spans         = spans;
 }
Ejemplo n.º 9
0
#pragma warning disable IDE0060 // Remove unused parameter
            protected internal PayloadNearSpanScorer(PayloadNearQuery outerInstance, Spans spans, Weight weight, Similarity similarity, Similarity.SimScorer docScorer)
#pragma warning restore IDE0060 // Remove unused parameter
                : base(spans, weight, docScorer)
            {
                this.outerInstance = outerInstance;
                this.spans         = spans;
            }
Ejemplo n.º 10
0
 internal JustCompileSpanScorer(Spans spans, Weight weight, Similarity.SimScorer docScorer)
     : base(spans, weight, docScorer)
 {
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Construct a <see cref="TermScorer"/>.
 /// </summary>
 /// <param name="weight">
 ///          The weight of the <see cref="Index.Term"/> in the query. </param>
 /// <param name="td">
 ///          An iterator over the documents matching the <see cref="Index.Term"/>. </param>
 /// <param name="docScorer">
 ///          The <see cref="Similarity.SimScorer"/> implementation
 ///          to be used for score computations. </param>
 internal TermScorer(Weight weight, DocsEnum td, Similarity.SimScorer docScorer)
     : base(weight)
 {
     this.docScorer = docScorer;
     this.docsEnum  = td;
 }