Esempio n. 1
0
        /// <summary>
        /// a constructor.
        /// </summary>
        /// <param name="fieldTermStack"><see cref="FieldTermStack"/> object</param>
        /// <param name="fieldQuery"><see cref="FieldQuery"/> object</param>
        /// <param name="phraseLimit">maximum size of phraseList</param>
        public FieldPhraseList(FieldTermStack fieldTermStack, FieldQuery fieldQuery, int phraseLimit)
        {
            string field = fieldTermStack.FieldName;

            IList <TermInfo> phraseCandidate = new JCG.List <TermInfo>();
            QueryPhraseMap   currMap; // LUCENENET: IDE0059: Remove unnecessary value assignment
            QueryPhraseMap   nextMap; // LUCENENET: IDE0059: Remove unnecessary value assignment

            while (!fieldTermStack.IsEmpty && (phraseList.Count < phraseLimit))
            {
                phraseCandidate.Clear();

                TermInfo ti;    // LUCENENET: IDE0059: Remove unnecessary value assignment
                TermInfo first; // LUCENENET: IDE0059: Remove unnecessary value assignment

                first   = ti = fieldTermStack.Pop();
                currMap = fieldQuery.GetFieldTermMap(field, ti.Text);
                while (currMap is null && ti.Next != first)
                {
                    ti      = ti.Next;
                    currMap = fieldQuery.GetFieldTermMap(field, ti.Text);
                }

                // if not found, discard top TermInfo from stack, then try next element
                if (currMap is null)
                {
                    continue;
                }

                // if found, search the longest phrase
                phraseCandidate.Add(ti);
                while (true)
                {
                    first   = ti = fieldTermStack.Pop();
                    nextMap = null;
                    if (ti != null)
                    {
                        nextMap = currMap.GetTermMap(ti.Text);
                        while (nextMap is null && ti.Next != first)
                        {
                            ti      = ti.Next;
                            nextMap = currMap.GetTermMap(ti.Text);
                        }
                    }
                    if (ti is null || nextMap is null)
                    {
                        if (ti != null)
                        {
                            fieldTermStack.Push(ti);
                        }
                        if (currMap.IsValidTermOrPhrase(phraseCandidate))
                        {
                            AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.Boost, currMap.TermOrPhraseNumber));
                        }
                        else
                        {
                            while (phraseCandidate.Count > 1)
                            {
                                //fieldTermStack.Push(phraseCandidate.Last.Value);
                                //phraseCandidate.RemoveLast();

                                TermInfo last = phraseCandidate[phraseCandidate.Count - 1];
                                phraseCandidate.Remove(last);
                                fieldTermStack.Push(last);

                                currMap = fieldQuery.SearchPhrase(field, phraseCandidate);
                                if (currMap != null)
                                {
                                    AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.Boost, currMap.TermOrPhraseNumber));
                                    break;
                                }
                            }
                        }
                        break;
                    }
Esempio n. 2
0
 /// <summary>
 /// create a <see cref="FieldPhraseList"/> that has no limit on the number of phrases to analyze
 /// </summary>
 /// <param name="fieldTermStack"><see cref="FieldTermStack"/> object</param>
 /// <param name="fieldQuery"><see cref="FieldQuery"/> object</param>
 public FieldPhraseList(FieldTermStack fieldTermStack, FieldQuery fieldQuery)
     : this(fieldTermStack, fieldQuery, int.MaxValue)
 {
 }