예제 #1
0
        public override int FetchSec(int targetSec)
        {
            SectionSearchQueryPlan node = _subqueries[0];

            targetSec = node.FetchSec(targetSec);
            if (targetSec == SectionSearchQueryPlan.NO_MORE_SECTIONS)
            {
                _curSec = SectionSearchQueryPlan.NO_MORE_SECTIONS;
                return(targetSec);
            }

            int i = 1;

            while (i < _subqueries.Length)
            {
                node = _subqueries[i];
                if (node.SecId < targetSec)
                {
                    _curSec = node.FetchSec(targetSec);
                    if (_curSec == SectionSearchQueryPlan.NO_MORE_SECTIONS)
                    {
                        return(_curSec);
                    }

                    if (_curSec > targetSec)
                    {
                        targetSec = _curSec;
                        i         = 0;
                        continue;
                    }
                }
                i++;
            }
            return(_curSec);
        }
        /// <summary>
        /// Gets a query plan for the given query.
        /// It is assumed that <code>query</code> is already rewritten before this call.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public virtual SectionSearchQueryPlan GetPlan(Query query)
        {
            if (query != null)
            {
                SectionSearchQueryPlan textSearchPlan = Translate(query);

                if (!(textSearchPlan is UnaryNotNode))
                {
                    return(textSearchPlan);
                }
            }
            return(null);
        }
        private SectionSearchQueryPlan[] Translate(ICollection <Query> queries)
        {
            int size = queries.Count;
            List <SectionSearchQueryPlan> result = new List <SectionSearchQueryPlan>(size);

            for (int i = 0; i < size; i++)
            {
                SectionSearchQueryPlan plan = Translate(queries.Get(i));
                if (plan != null)
                {
                    result.Add(plan);
                }
            }
            return(result.ToArray());
        }
            public SectionSearchScorer(Query query, Weight weight, float score, AtomicReader reader)
                : base(weight)
            {
                m_curScr = score;

                SectionSearchQueryPlanBuilder builer = new SectionSearchQueryPlanBuilder(reader);

                m_plan = builer.GetPlan(query);
                if (m_plan != null)
                {
                    m_curDoc = -1;
                }
                else
                {
                    m_curDoc = DocIdSetIterator.NO_MORE_DOCS;
                }
            }
예제 #5
0
            public SectionSearchScorer(Query query, Similarity similarity, float score, IndexReader reader)
                : base(similarity)
            {
                _curScr = score;

                SectionSearchQueryPlanBuilder builer = new SectionSearchQueryPlanBuilder(reader);

                _plan = builer.GetPlan(query);
                if (_plan != null)
                {
                    _curDoc = -1;
                    //_more = true; // NOT USED
                }
                else
                {
                    _curDoc = DocIdSetIterator.NO_MORE_DOCS;
                    //_more = false;  // NOT USED
                }
            }
예제 #6
0
        public override int FetchDoc(int targetDoc)
        {
            if (m_curDoc == DocIdSetIterator.NO_MORE_DOCS)
            {
                return(m_curDoc);
            }

            if (targetDoc <= m_curDoc)
            {
                targetDoc = m_curDoc + 1;
            }

            m_curSec = -1;

            SectionSearchQueryPlan node = (SectionSearchQueryPlan)m_pq.Top;

            while (true)
            {
                if (node.DocId < targetDoc)
                {
                    if (node.FetchDoc(targetDoc) < DocIdSetIterator.NO_MORE_DOCS)
                    {
                        node = (SectionSearchQueryPlan)m_pq.UpdateTop();
                    }
                    else
                    {
                        m_pq.Pop();
                        if (m_pq.Count <= 0)
                        {
                            m_curDoc = DocIdSetIterator.NO_MORE_DOCS;
                            return(m_curDoc);
                        }
                        node = (SectionSearchQueryPlan)m_pq.Top;
                    }
                }
                else
                {
                    m_curDoc = node.DocId;
                    return(m_curDoc);
                }
            }
        }
예제 #7
0
        public override int FetchDoc(int targetDoc)
        {
            if (_curDoc == DocIdSetIterator.NO_MORE_DOCS)
            {
                return(_curDoc);
            }

            SectionSearchQueryPlan node = _subqueries[0];

            _curDoc   = node.FetchDoc(targetDoc);
            targetDoc = _curDoc;

            int i = 1;

            while (i < _subqueries.Length)
            {
                node = _subqueries[i];
                if (node.DocId < targetDoc)
                {
                    _curDoc = node.FetchDoc(targetDoc);
                    if (_curDoc == DocIdSetIterator.NO_MORE_DOCS)
                    {
                        return(_curDoc);
                    }

                    if (_curDoc > targetDoc)
                    {
                        targetDoc = _curDoc;
                        i         = 0;
                        continue;
                    }
                }
                i++;
            }
            _curSec = -1;
            return(_curDoc);
        }
예제 #8
0
        public override int FetchSec(int targetSec)
        {
            if (m_curSec == SectionSearchQueryPlan.NO_MORE_SECTIONS)
            {
                return(m_curSec);
            }

            if (targetSec <= m_curSec)
            {
                targetSec = m_curSec + 1;
            }

            SectionSearchQueryPlan node = (SectionSearchQueryPlan)m_pq.Top;

            while (true)
            {
                if (node.DocId == m_curDoc && m_curSec < SectionSearchQueryPlan.NO_MORE_SECTIONS)
                {
                    if (node.SecId < targetSec)
                    {
                        node.FetchSec(targetSec);
                        node = (SectionSearchQueryPlan)m_pq.UpdateTop();
                    }
                    else
                    {
                        m_curSec = node.SecId;
                        return(m_curSec);
                    }
                }
                else
                {
                    m_curSec = SectionSearchQueryPlan.NO_MORE_SECTIONS;
                    return(m_curSec);
                }
            }
        }
        private SectionSearchQueryPlan TranslateBooleanQuery(BooleanQuery query)
        {
            List <Query> requiredClauses   = new List <Query>();
            List <Query> prohibitedClauses = new List <Query>();
            List <Query> optionalClauses   = new List <Query>();

            BooleanClause[] clauses = query.GetClauses();
            foreach (BooleanClause clause in clauses)
            {
                if (clause.IsRequired)
                {
                    requiredClauses.Add(clause.Query);
                }
                else if (clause.IsProhibited)
                {
                    prohibitedClauses.Add(clause.Query);
                }
                else
                {
                    optionalClauses.Add(clause.Query);
                }
            }

            SectionSearchQueryPlan positiveNode = null;
            SectionSearchQueryPlan negativeNode = null;

            if (requiredClauses.Count > 0)
            {
                if (requiredClauses.Count == 1)
                {
                    positiveNode = Translate(requiredClauses.Get(0));
                }
                else
                {
                    SectionSearchQueryPlan[] subqueries = Translate(requiredClauses);
                    if (subqueries != null && subqueries.Length > 0)
                    {
                        positiveNode = new AndNode(subqueries);
                    }
                }
            }
            else if (optionalClauses.Count > 0)
            {
                if (optionalClauses.Count == 1)
                {
                    positiveNode = Translate(optionalClauses.Get(0));
                }
                else
                {
                    SectionSearchQueryPlan[] subqueries = Translate(optionalClauses);
                    if (subqueries != null && subqueries.Length > 0)
                    {
                        positiveNode = new OrNode(subqueries);
                    }
                }
            }

            if (prohibitedClauses.Count > 0)
            {
                if (prohibitedClauses.Count == 1)
                {
                    negativeNode = Translate(prohibitedClauses.Get(0));
                }
                else
                {
                    negativeNode = new OrNode(Translate(prohibitedClauses));
                }
            }

            if (negativeNode == null)
            {
                return(positiveNode);
            }
            else
            {
                if (positiveNode == null)
                {
                    return(new UnaryNotNode(negativeNode));
                }
                else
                {
                    return(new AndNotNode(positiveNode, negativeNode));
                }
            }
        }
예제 #10
0
 public UnaryNotNode(SectionSearchQueryPlan subquery)
 {
     m_subquery = subquery;
 }
예제 #11
0
 public AndNotNode(SectionSearchQueryPlan positiveNode, SectionSearchQueryPlan negativeNode)
 {
     m_positiveNode = positiveNode;
     m_negativeNode = negativeNode;
 }