示例#1
0
        /// <summary>
        /// Return the best fragments.  Matches are scanned from <paramref name="matchedFields"/> and turned into fragments against
        /// <paramref name="storedField"/>.  The highlighting may not make sense if <paramref name="matchedFields"/> has matches with offsets that don't
        /// correspond features in <paramref name="storedField"/>.  It will outright throw a <see cref="IndexOutOfRangeException"/>
        /// if <paramref name="matchedFields"/> produces offsets outside of <paramref name="storedField"/>.  As such it is advisable that all
        /// <paramref name="matchedFields"/> share the same source as <paramref name="storedField"/> or are at least a prefix of it.
        /// </summary>
        /// <param name="fieldQuery"><see cref="FieldQuery"/> object</param>
        /// <param name="reader"><see cref="IndexReader"/> of the index</param>
        /// <param name="docId">document id to be highlighted</param>
        /// <param name="storedField">field of the document that stores the text</param>
        /// <param name="matchedFields">fields of the document to scan for matches</param>
        /// <param name="fragCharSize">the length (number of chars) of a fragment</param>
        /// <param name="maxNumFragments">maximum number of fragments</param>
        /// <param name="fragListBuilder"><see cref="IFragListBuilder"/> object</param>
        /// <param name="fragmentsBuilder"><see cref="IFragmentsBuilder"/> object</param>
        /// <param name="preTags">pre-tags to be used to highlight terms</param>
        /// <param name="postTags">post-tags to be used to highlight terms</param>
        /// <param name="encoder">an encoder that generates encoded text</param>
        /// <returns>
        /// created fragments or null when no fragments created.
        /// size of the array can be less than <paramref name="maxNumFragments"/>
        /// </returns>
        /// <exception cref="IOException">If there is a low-level I/O error</exception>
        public string[] GetBestFragments(FieldQuery fieldQuery, IndexReader reader, int docId,
                                         string storedField, ISet <string> matchedFields, int fragCharSize, int maxNumFragments,
                                         IFragListBuilder fragListBuilder, IFragmentsBuilder fragmentsBuilder,
                                         string[] preTags, string[] postTags, IEncoder encoder)
        {
            FieldFragList fieldFragList =
                GetFieldFragList(fragListBuilder, fieldQuery, reader, docId, matchedFields, fragCharSize);

            return(fragmentsBuilder.CreateFragments(reader, docId, storedField, fieldFragList, maxNumFragments,
                                                    preTags, postTags, encoder));
        }
示例#2
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));
        }
示例#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)
        {
            IEnumerator <string> matchedFieldsItr = matchedFields.GetEnumerator();

            if (!matchedFields.Any())
            {
                throw new ArgumentException("matchedFields must contain at least on field name.");
            }
            FieldPhraseList[]
                toMerge = new FieldPhraseList[matchedFields.Count];
            int i       = 0;

            while (matchedFieldsItr.MoveNext())
            {
                FieldTermStack stack = new FieldTermStack(reader, docId, matchedFieldsItr.Current, fieldQuery);
                toMerge[i++] = new FieldPhraseList(stack, fieldQuery, phraseLimit);
            }
            return(fragListBuilder.CreateFieldFragList(new FieldPhraseList(toMerge), fragCharSize));
        }