コード例 #1
0
        public virtual FieldFragList CreateFieldFragList(FieldPhraseList fieldPhraseList,
                                                         int fragCharSize)
        {
            FieldFragList ffl = new SimpleFieldFragList(fragCharSize);

            IList <WeightedPhraseInfo> wpil = new JCG.List <WeightedPhraseInfo>();

            using IEnumerator <WeightedPhraseInfo> ite = fieldPhraseList.PhraseList.GetEnumerator();
            WeightedPhraseInfo phraseInfo = null;

            while (true)
            {
                if (!ite.MoveNext())
                {
                    break;
                }
                phraseInfo = ite.Current;
                if (phraseInfo is null)
                {
                    break;
                }

                wpil.Add(phraseInfo);
            }
            if (wpil.Count > 0)
            {
                ffl.Add(0, int.MaxValue, wpil);
            }
            return(ffl);
        }
コード例 #2
0
        /// <summary>
        /// Build a <see cref="FieldFragList"/> for one field.
        /// </summary>
        private FieldFragList GetFieldFragList(IFragListBuilder fragListBuilder,
                                               FieldQuery fieldQuery, IndexReader reader, int docId,
                                               string matchedField, int fragCharSize)
        {
            FieldTermStack  fieldTermStack  = new FieldTermStack(reader, docId, matchedField, fieldQuery);
            FieldPhraseList fieldPhraseList = new FieldPhraseList(fieldTermStack, fieldQuery, phraseLimit);

            return(fragListBuilder.CreateFieldFragList(fieldPhraseList, fragCharSize));
        }
コード例 #3
0
        /// <summary>
        /// Build a <see cref="FieldFragList"/> for more than one field.
        /// </summary>
        private FieldFragList GetFieldFragList(IFragListBuilder fragListBuilder,
                                               FieldQuery fieldQuery, IndexReader reader, int docId,
                                               ISet <string> matchedFields, int fragCharSize)
        {
            if (matchedFields.Count == 0)
            {
                throw new ArgumentException("matchedFields must contain at least on field name.");
            }
            FieldPhraseList[]
                toMerge = new FieldPhraseList[matchedFields.Count];
            int i       = 0;

            foreach (var matchedField in matchedFields)
            {
                FieldTermStack stack = new FieldTermStack(reader, docId, matchedField, fieldQuery);
                toMerge[i++] = new FieldPhraseList(stack, fieldQuery, phraseLimit);
            }
            return(fragListBuilder.CreateFieldFragList(new FieldPhraseList(toMerge), fragCharSize));
        }
コード例 #4
0
        protected virtual FieldFragList CreateFieldFragList(FieldPhraseList fieldPhraseList, FieldFragList fieldFragList, int fragCharSize)
        {
            if (fragCharSize < minFragCharSize)
            {
                throw new ArgumentException("fragCharSize(" + fragCharSize + ") is too small. It must be " + minFragCharSize + " or higher.");
            }

            List <WeightedPhraseInfo> wpil = new List <WeightedPhraseInfo>();

            using (IteratorQueue <WeightedPhraseInfo> queue = new IteratorQueue <WeightedPhraseInfo>(fieldPhraseList.PhraseList.GetEnumerator()))
            {
                WeightedPhraseInfo phraseInfo = null;
                int startOffset = 0;
                while ((phraseInfo = queue.Top()) != null)
                {
                    // if the phrase violates the border of previous fragment, discard it and try next phrase
                    if (phraseInfo.StartOffset < startOffset)
                    {
                        queue.RemoveTop();
                        continue;
                    }

                    wpil.Clear();
                    int currentPhraseStartOffset = phraseInfo.StartOffset;
                    int currentPhraseEndOffset   = phraseInfo.EndOffset;
                    int spanStart = Math.Max(currentPhraseStartOffset - margin, startOffset);
                    int spanEnd   = Math.Max(currentPhraseEndOffset, spanStart + fragCharSize);
                    if (AcceptPhrase(queue.RemoveTop(), currentPhraseEndOffset - currentPhraseStartOffset, fragCharSize))
                    {
                        wpil.Add(phraseInfo);
                    }
                    while ((phraseInfo = queue.Top()) != null)
                    { // pull until we crossed the current spanEnd
                        if (phraseInfo.EndOffset <= spanEnd)
                        {
                            currentPhraseEndOffset = phraseInfo.EndOffset;
                            if (AcceptPhrase(queue.RemoveTop(), currentPhraseEndOffset - currentPhraseStartOffset, fragCharSize))
                            {
                                wpil.Add(phraseInfo);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (wpil.Count == 0)
                    {
                        continue;
                    }

                    int matchLen = currentPhraseEndOffset - currentPhraseStartOffset;
                    // now recalculate the start and end position to "center" the result
                    int newMargin = Math.Max(0, (fragCharSize - matchLen) / 2); // matchLen can be > fragCharSize prevent IAOOB here
                    spanStart = currentPhraseStartOffset - newMargin;
                    if (spanStart < startOffset)
                    {
                        spanStart = startOffset;
                    }
                    // whatever is bigger here we grow this out
                    spanEnd     = spanStart + Math.Max(matchLen, fragCharSize);
                    startOffset = spanEnd;
                    fieldFragList.Add(spanStart, spanEnd, wpil);
                }
            }
            return(fieldFragList);
        }
コード例 #5
0
 // LUCENENET specific - need to make this overload of CreateFieldFragList abstract so it satisfies
 // the interface contract.
 public abstract FieldFragList CreateFieldFragList(FieldPhraseList fieldPhraseList, int fragCharSize);