コード例 #1
0
            public override Query Rewrite(IndexReader reader, MultiTermQuery query)
            {
                FilteredTermEnum enumerator = query.GetEnum(reader);
                BooleanQuery     result     = new BooleanQuery(true);
                int count = 0;

                try
                {
                    do
                    {
                        Term t = enumerator.Term();
                        if (t != null)
                        {
                            TermQuery tq = new TermQuery(t);                             // found a match
                            tq.SetBoost(query.GetBoost() * enumerator.Difference());     // set the boost
                            result.Add(tq, BooleanClause.Occur.SHOULD);                  // add to query
                            count++;
                        }
                    }while (enumerator.Next());
                }
                finally
                {
                    enumerator.Close();
                }
                query.IncTotalNumberOfTerms(count);
                return(result);
            }
コード例 #2
0
        public override Query Rewrite(IndexReader reader)
        {
            FilteredTermEnum enumerator   = GetEnum(reader);
            int            maxClauseCount = BooleanQuery.GetMaxClauseCount();
            ScoreTermQueue stQueue        = new ScoreTermQueue(maxClauseCount);
            ScoreTerm      reusableST     = null;

            try
            {
                do
                {
                    float score = 0.0f;
                    Term  t     = enumerator.Term();
                    if (t != null)
                    {
                        score = enumerator.Difference();
                        if (reusableST == null)
                        {
                            reusableST = new ScoreTerm(t, score);
                        }
                        else if (score >= reusableST.score)
                        {
                            // reusableST holds the last "rejected" entry, so, if
                            // this new score is not better than that, there's no
                            // need to try inserting it
                            reusableST.score = score;
                            reusableST.term  = t;
                        }
                        else
                        {
                            continue;
                        }

                        reusableST = (ScoreTerm)stQueue.InsertWithOverflow(reusableST);
                    }
                }while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }

            BooleanQuery query = new BooleanQuery(true);
            int          size  = stQueue.Size();

            for (int i = 0; i < size; i++)
            {
                ScoreTerm st = (ScoreTerm)stQueue.Pop();
                TermQuery tq = new TermQuery(st.term);              // found a match
                tq.SetBoost(GetBoost() * st.score);                 // set the boost
                query.Add(tq, BooleanClause.Occur.SHOULD);          // add to query
            }

            return(query);
        }
コード例 #3
0
        public override Query Rewrite(IndexReader reader)
        {
            FilteredTermEnum enumerator   = GetEnum(reader);
            int            maxClauseCount = BooleanQuery.GetMaxClauseCount();
            ScoreTermQueue stQueue        = new ScoreTermQueue(maxClauseCount);

            try
            {
                do
                {
                    float minScore = 0.0f;
                    float score    = 0.0f;
                    Term  t        = enumerator.Term();
                    if (t != null)
                    {
                        score = enumerator.Difference();
                        // terms come in alphabetical order, therefore if queue is full and score
                        // not bigger than minScore, we can skip
                        if (stQueue.Size() < maxClauseCount || score > minScore)
                        {
                            stQueue.Insert(new ScoreTerm(t, score));
                            minScore = ((ScoreTerm)stQueue.Top()).score;                              // maintain minScore
                        }
                    }
                }while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }

            BooleanQuery query = new BooleanQuery(true);
            int          size  = stQueue.Size();

            for (int i = 0; i < size; i++)
            {
                ScoreTerm st = (ScoreTerm)stQueue.Pop();
                TermQuery tq = new TermQuery(st.term);              // found a match
                tq.SetBoost(GetBoost() * st.score);                 // set the boost
                query.Add(tq, BooleanClause.Occur.SHOULD);          // add to query
            }

            return(query);
        }
コード例 #4
0
        public override Query Rewrite(IndexReader reader)
        {
            FilteredTermEnum enumerator = GetEnum(reader);
            BooleanQuery     query      = new BooleanQuery(true);

            try
            {
                do
                {
                    Term t = enumerator.Term();
                    if (t != null)
                    {
                        TermQuery tq = new TermQuery(t);                         // found a match
                        tq.SetBoost(GetBoost() * enumerator.Difference());       // set the boost
                        query.Add(tq, BooleanClause.Occur.SHOULD);               // add to query
                    }
                }while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }
            return(query);
        }
コード例 #5
0
ファイル: FuzzyQuery.cs プロジェクト: ravendb/lucenenet
        public override Query Rewrite(IndexReader reader, IState state)
        {
            if (!termLongEnough)
            {
                // can only match if it's exact
                return(new TermQuery(Term));
            }

            int maxSize = BooleanQuery.MaxClauseCount;

            // TODO: Java uses a PriorityQueue.  Using Linq, we can emulate it,
            //       however it's considerable slower than the java counterpart.
            //       this should be a temporary thing, fixed before release
            SortedList <ScoreTerm, ScoreTerm> stQueue = new SortedList <ScoreTerm, ScoreTerm>();
            FilteredTermEnum enumerator = GetEnum(reader, state);

            try
            {
                ScoreTerm st = new ScoreTerm();
                do
                {
                    Term t = enumerator.Term;
                    if (t == null)
                    {
                        break;
                    }
                    float score = enumerator.Difference();
                    //ignore uncompetetive hits
                    if (stQueue.Count >= maxSize && score <= stQueue.Keys.First().score)
                    {
                        continue;
                    }
                    // add new entry in PQ
                    st.term  = t;
                    st.score = score;
                    stQueue.Add(st, st);
                    // possibly drop entries from queue
                    if (stQueue.Count > maxSize)
                    {
                        st = stQueue.Keys.First();
                        stQueue.Remove(st);
                    }
                    else
                    {
                        st = new ScoreTerm();
                    }
                }while (enumerator.Next(state));
            }
            finally
            {
                enumerator.Close();
            }

            BooleanQuery query = new BooleanQuery(true);

            foreach (ScoreTerm st in stQueue.Keys)
            {
                TermQuery tq = new TermQuery(st.term);       // found a match
                tq.Boost = Boost * st.score;                 // set the boost
                query.Add(tq, Occur.SHOULD);                 // add to query
            }

            return(query);
        }