Ejemplo n.º 1
0
 public ShardSearcher(AtomicReaderContext ctx, IndexReaderContext parent)
     : base(parent)
 {
     this.Ctx = new List<AtomicReaderContext> { ctx };
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a searcher searching the provided top-level <see cref="IndexReaderContext"/>.
 /// <para/>
 /// @lucene.experimental
 /// </summary>
 /// <seealso cref="IndexReaderContext"/>
 /// <seealso cref="IndexReader.Context"/>
 public IndexSearcher(IndexReaderContext context)
     : this(context, null)
 {
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Expert: highlights the top-N passages from multiple fields,
        /// for the provided int[] docids, to custom object as
        /// returned by the <see cref="PassageFormatter"/>.  Use
        /// this API to render to something other than <see cref="string"/>.
        /// </summary>
        /// <param name="fieldsIn">field names to highlight. Must have a stored string value and also be indexed with offsets.</param>
        /// <param name="query">query to highlight.</param>
        /// <param name="searcher">searcher that was previously used to execute the query.</param>
        /// <param name="docidsIn">containing the document IDs to highlight.</param>
        /// <param name="maxPassagesIn">The maximum number of top-N ranked passages per-field used to form the highlighted snippets.</param>
        /// <returns>
        /// <see cref="T:IDictionary{string, object[]}"/> keyed on field name, containing the array of formatted snippets
        /// corresponding to the documents in <paramref name="docidsIn"/>.
        /// If no highlights were found for a document, the
        /// first <paramref name="maxPassagesIn"/> from the field will
        /// be returned.
        /// </returns>
        /// <exception cref="IOException">if an I/O error occurred during processing</exception>
        /// <exception cref="ArgumentException">if <c>field</c> was indexed without <see cref="IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS"/></exception>
        protected internal virtual IDictionary <string, object[]> HighlightFieldsAsObjects(string[] fieldsIn, Query query, IndexSearcher searcher, int[] docidsIn, int[] maxPassagesIn)
        {
            if (fieldsIn.Length < 1)
            {
                throw new ArgumentException("fieldsIn must not be empty");
            }
            if (fieldsIn.Length != maxPassagesIn.Length)
            {
                throw new ArgumentException("invalid number of maxPassagesIn");
            }
            IndexReader reader    = searcher.IndexReader;
            Query       rewritten = Rewrite(query);

            JCG.SortedSet <Term> queryTerms = new JCG.SortedSet <Term>();
            rewritten.ExtractTerms(queryTerms);

            IndexReaderContext          readerContext = reader.Context;
            IList <AtomicReaderContext> leaves        = readerContext.Leaves;

            // Make our own copies because we sort in-place:
            int[] docids = new int[docidsIn.Length];
            System.Array.Copy(docidsIn, 0, docids, 0, docidsIn.Length);
            string[] fields = new string[fieldsIn.Length];
            System.Array.Copy(fieldsIn, 0, fields, 0, fieldsIn.Length);
            int[] maxPassages = new int[maxPassagesIn.Length];
            System.Array.Copy(maxPassagesIn, 0, maxPassages, 0, maxPassagesIn.Length);

            // sort for sequential io
            ArrayUtil.TimSort(docids);
            new InPlaceMergeSorterAnonymousHelper(fields, maxPassages).Sort(0, fields.Length);

            // pull stored data:
            IList <string[]> contents = LoadFieldValues(searcher, fields, docids, maxLength);

            IDictionary <string, object[]> highlights = new Dictionary <string, object[]>();

            for (int i = 0; i < fields.Length; i++)
            {
                string field       = fields[i];
                int    numPassages = maxPassages[i];
                Term   floor       = new Term(field, "");
                Term   ceiling     = new Term(field, UnicodeUtil.BIG_TERM);

                // LUCENENET: Call custom GetViewBetween overload to mimic Java's exclusive upper bound behavior.
                var fieldTerms = queryTerms.GetViewBetween(floor, lowerValueInclusive: true, ceiling, upperValueInclusive: false);

                // TODO: should we have some reasonable defaults for term pruning? (e.g. stopwords)

                // Strip off the redundant field:
                BytesRef[] terms    = new BytesRef[fieldTerms.Count];
                int        termUpto = 0;
                foreach (Term term in fieldTerms)
                {
                    terms[termUpto++] = term.Bytes;
                }
                IDictionary <int, object> fieldHighlights = HighlightField(field, contents[i], GetBreakIterator(field), terms, docids, leaves, numPassages, query);

                object[] result = new object[docids.Length];
                for (int j = 0; j < docidsIn.Length; j++)
                {
                    fieldHighlights.TryGetValue(docidsIn[j], out result[j]);
                }
                highlights[field] = result;
            }
            return(highlights);
        }
Ejemplo n.º 4
0
 public virtual void SetReaderContext(IndexReaderContext topReaderContext, AtomicReaderContext readerContext)
 {
     this.m_readerContext    = readerContext;
     this.m_topReaderContext = topReaderContext;
 }
Ejemplo n.º 5
0
 public AssertingIndexSearcher(Random random, IndexReaderContext context, TaskScheduler ex)
     : base(context, ex)
 {
     this.random = new Random(random.Next());
 }
Ejemplo n.º 6
0
 public AssertingIndexSearcher(Random random, IndexReaderContext context)
     : base(context)
 {
     this.random = new Random(random.Next());
 }