/// <summary> /// Walks up the reader tree and return the given context's top level reader /// context, or in other words the reader tree's root context. /// </summary> public static IndexReaderContext GetTopLevelContext(IndexReaderContext context) { while (context.Parent != null) { context = context.Parent; } return context; }
//public static boolean DEBUG = BlockTreeTermsWriter.DEBUG; /// <summary> /// Creates an empty <seealso cref="TermContext"/> from a <seealso cref="IndexReaderContext"/> /// </summary> public TermContext(IndexReaderContext context) { Debug.Assert(context != null && context.IsTopLevel); TopReaderContext = context; docFreq = 0; int len; if (context.Leaves == null) { len = 1; } else { len = context.Leaves.Count; } States = new TermState[len]; }
public static Spans Wrap(IndexReaderContext topLevelReaderContext, SpanQuery query) { IDictionary<Term, TermContext> termContexts = new Dictionary<Term, TermContext>(); SortedSet<Term> terms = new SortedSet<Term>(); query.ExtractTerms(terms); foreach (Term term in terms) { termContexts[term] = TermContext.Build(topLevelReaderContext, term); } IList<AtomicReaderContext> leaves = topLevelReaderContext.Leaves(); if (leaves.Count == 1) { AtomicReaderContext ctx = leaves[0]; return query.GetSpans(ctx, ((AtomicReader)ctx.Reader()).LiveDocs, termContexts); } return new MultiSpansWrapper(leaves, query, termContexts); }
/// <param name="context"> /// that contains doc with payloads to extract /// </param> /// <seealso cref= IndexReader#getContext() </seealso> public PayloadSpanUtil(IndexReaderContext context) { this.Context = context; }
/// <summary> /// Creates a <seealso cref="TermContext"/> with an initial <seealso cref="TermState"/>, /// <seealso cref="IndexReader"/> pair. /// </summary> public TermContext(IndexReaderContext context, TermState state, int ord, int docFreq, long totalTermFreq) : this(context) { Register(state, ord, docFreq, totalTermFreq); }
/// <summary> /// Creates a <seealso cref="TermContext"/> from a top-level <seealso cref="IndexReaderContext"/> and the /// given <seealso cref="Term"/>. this method will lookup the given term in all context's leaf readers /// and register each of the readers containing the term in the returned <seealso cref="TermContext"/> /// using the leaf reader's ordinal. /// <p> /// Note: the given context must be a top-level context. /// </summary> public static TermContext Build(IndexReaderContext context, Term term) { Debug.Assert(context != null && context.IsTopLevel); string field = term.Field; BytesRef bytes = term.Bytes; TermContext perReaderTermState = new TermContext(context); //if (DEBUG) System.out.println("prts.build term=" + term); foreach (AtomicReaderContext ctx in context.Leaves) { //if (DEBUG) System.out.println(" r=" + leaves[i].reader); Fields fields = ctx.AtomicReader.Fields; if (fields != null) { Terms terms = fields.Terms(field); if (terms != null) { TermsEnum termsEnum = terms.Iterator(null); if (termsEnum.SeekExact(bytes)) { TermState termState = termsEnum.TermState(); //if (DEBUG) System.out.println(" found"); perReaderTermState.Register(termState, ctx.Ord, termsEnum.DocFreq(), termsEnum.TotalTermFreq()); } } } } return perReaderTermState; }
/// <summary> /// Creates a <see cref="TermContext"/> with an initial <see cref="TermState"/>, /// <see cref="IndexReader"/> pair. /// </summary> public TermContext(IndexReaderContext context, TermState state, int ord, int docFreq, long totalTermFreq) : this(context) { Register(state, ord, docFreq, totalTermFreq); }