Ejemplo n.º 1
0
        protected internal override bool Score(HitCollector c, int end)
        {
            Similarity similarity = GetSimilarity();             // cache sim in local

            float[] normDecoder = Similarity.GetNormDecoder();
            while (doc < end)
            {
                // for docs in window
                int   f     = freqs[pointer];
                float score = f < SCORE_CACHE_SIZE?scoreCache[f]:similarity.Tf(f) * weightValue; // cache miss

                score *= normDecoder[norms[doc] & 0xFF];                                         // normalize for field

                c.Collect(doc, score);                                                           // collect score

                if (++pointer >= pointerMax)
                {
                    pointerMax = termDocs.Read(docs, freqs);                     // refill buffers
                    if (pointerMax != 0)
                    {
                        pointer = 0;
                    }
                    else
                    {
                        termDocs.Close();                         // close stream
                        doc = System.Int32.MaxValue;              // set to sentinel value
                        return(false);
                    }
                }
                doc = docs[pointer];
            }
            return(true);
        }
Ejemplo n.º 2
0
        // firstDocID is ignored since nextDoc() sets 'doc'
        public /*protected internal*/ override bool Score(Collector c, int end, int firstDocID, IState state)
        {
            c.SetScorer(this);
            while (doc < end)
            {
                // for docs in window
                c.Collect(doc, state);                 // collect score

                if (++pointer >= pointerMax)
                {
                    pointerMax = termDocs.Read(docs, freqs, state);                     // refill buffers
                    if (pointerMax != 0)
                    {
                        pointer = 0;
                    }
                    else
                    {
                        termDocs.Close();                         // close stream
                        doc = System.Int32.MaxValue;              // set to sentinel value
                        return(false);
                    }
                }
                doc = docs[pointer];
            }
            return(true);
        }
        public override DocIdSet GetDocIdSet(IndexReader reader)
        {
            TermEnum enumerator = query.GetEnum(reader);

            try
            {
                // if current term in enum is null, the enum is empty -> shortcut
                if (enumerator.Term == null)
                {
                    return(DocIdSet.EMPTY_DOCIDSET);
                }
                // else fill into an OpenBitSet
                OpenBitSet bitSet   = new OpenBitSet(reader.MaxDoc);
                int[]      docs     = new int[32];
                int[]      freqs    = new int[32];
                TermDocs   termDocs = reader.TermDocs();
                try
                {
                    int termCount = 0;
                    do
                    {
                        Term term = enumerator.Term;
                        if (term == null)
                        {
                            break;
                        }
                        termCount++;
                        termDocs.Seek(term);
                        while (true)
                        {
                            int count = termDocs.Read(docs, freqs);
                            if (count != 0)
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    bitSet.Set(docs[i]);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    } while (enumerator.Next());

                    query.IncTotalNumberOfTerms(termCount); // {{Aroush-2.9}} is the use of 'temp' as is right?
                }
                finally
                {
                    termDocs.Close();
                }

                return(bitSet);
            }
            finally
            {
                enumerator.Close();
            }
        }
            public virtual void Generate(MultiTermQuery query, IndexReader reader, TermEnum enumerator)
            {
                int[]    docs     = new int[32];
                int[]    freqs    = new int[32];
                TermDocs termDocs = reader.TermDocs();

                try
                {
                    int termCount = 0;
                    do
                    {
                        Term term = enumerator.Term();
                        if (term == null)
                        {
                            break;
                        }
                        termCount++;
                        termDocs.Seek(term);
                        while (true)
                        {
                            int count = termDocs.Read(docs, freqs);
                            if (count != 0)
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    HandleDoc(docs[i]);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }while (enumerator.Next());

                    query.IncTotalNumberOfTerms(termCount);                     // {{Aroush-2.9}} is the use of 'temp' as is right?
                }
                finally
                {
                    termDocs.Close();
                }
            }