@Override public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException { return actualEnum.postings(reuse, flags); }
@Override public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException { return in.postings(reuse, flags); }
@Override public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException { return tenum.postings(reuse, flags); }
/** Get {@link PostingsEnum} for the current term. Do not * call this when the enum is unpositioned. This method * will not return null. * <p> * <b>NOTE</b>: the returned iterator may return deleted documents, so * deleted documents have to be checked on top of the {@link PostingsEnum}. * <p> * Use this method if you only require documents and frequencies, * and do not need any proximity data. * This method is equivalent to * {@link #postings(PostingsEnum, int) postings(reuse, PostingsEnum.FREQS)} * * @param reuse pass a prior PostingsEnum for possible reuse * @see #postings(PostingsEnum, int) */ public final PostingsEnum postings(PostingsEnum reuse) throws IOException { return postings(reuse, PostingsEnum.FREQS); }
@Override public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException { MappingMultiPostingsEnum mappingDocsAndPositionsEnum; if (reuse instanceof MappingMultiPostingsEnum) { MappingMultiPostingsEnum postings = (MappingMultiPostingsEnum) reuse; if (postings.field.equals(this.field)) { mappingDocsAndPositionsEnum = postings; } else { mappingDocsAndPositionsEnum = new MappingMultiPostingsEnum(field, mergeState); } } else { mappingDocsAndPositionsEnum = new MappingMultiPostingsEnum(field, mergeState); } MultiPostingsEnum docsAndPositionsEnum = (MultiPostingsEnum) in.postings(mappingDocsAndPositionsEnum.multiDocsAndPositionsEnum, flags); mappingDocsAndPositionsEnum.reset(docsAndPositionsEnum); return mappingDocsAndPositionsEnum; } }
/** Returns {@link PostingsEnum} for the specified field and * term, with control over whether freqs are required. * Some codecs may be able to optimize their * implementation when freqs are not required. This will * return null if the field or term does not exist. See {@link * TermsEnum#postings(PostingsEnum,int)}.*/ public static PostingsEnum getTermDocsEnum(IndexReader r, String field, BytesRef term, int flags) throws IOException { assert field != null; assert term != null; final Terms terms = getTerms(r, field); if (terms != null) { final TermsEnum termsEnum = terms.iterator(); if (termsEnum.seekExact(term)) { return termsEnum.postings(null, flags); } } return null; }
/** Returns {@link PostingsEnum} for the specified * field and term, with control over whether offsets and payloads are * required. Some codecs may be able to optimize * their implementation when offsets and/or payloads are not * required. This will return null if the field or term does not * exist. See {@link TermsEnum#postings(PostingsEnum,int)}. */ public static PostingsEnum getTermPositionsEnum(IndexReader r, String field, BytesRef term, int flags) throws IOException { assert field != null; assert term != null; final Terms terms = getTerms(r, field); if (terms != null) { final TermsEnum termsEnum = terms.iterator(); if (termsEnum.seekExact(term)) { return termsEnum.postings(null, flags); } } return null; }
@Override public Scorer scorer(LeafReaderContext context) throws IOException { Similarity.SimScorer simScorer = similarity.simScorer(simWeight, context); // we use termscorers + disjunction as an impl detail List<Scorer> subScorers = new ArrayList<>(); for (int i = 0; i < terms.length; i++) { TermState state = termContexts[i].get(context.ord); if (state != null) { TermsEnum termsEnum = context.reader().terms(terms[i].field()).iterator(); termsEnum.seekExact(terms[i].bytes(), state); PostingsEnum postings = termsEnum.postings(null, PostingsEnum.FREQS); subScorers.add(new TermScorer(this, postings, simScorer)); } } if (subScorers.isEmpty()) { return null; } else if (subScorers.size() == 1) { // we must optimize this case (term not in segment), disjunctionscorer requires >= 2 subs return subScorers.get(0); } else { return new SynonymScorer(simScorer, this, subScorers); } }
@Override public Scorer scorer(LeafReaderContext context) throws IOException { assert termStates == null || termStates.wasBuiltFor(ReaderUtil.getTopLevelContext(context)) : "The top-reader used to create Weight is not the same as the current reader's top-reader (" + ReaderUtil.getTopLevelContext(context);; final TermsEnum termsEnum = getTermsEnum(context); if (termsEnum == null) { return null; } PostingsEnum docs = termsEnum.postings(null, needsScores ? PostingsEnum.FREQS : PostingsEnum.NONE); assert docs != null; return new TermScorer(this, docs, similarity.simScorer(stats, context)); }
/** * Create a {@link DisjunctionMatchesIterator} over a list of terms extracted from a {@link BytesRefIterator} * * Only terms that have at least one match in the given document will be included */ static MatchesIterator fromTermsEnum(LeafReaderContext context, int doc, Query query, String field, BytesRefIterator terms) throws IOException { Objects.requireNonNull(field); List<MatchesIterator> mis = new ArrayList<>(); Terms t = context.reader().terms(field); if (t == null) return null; TermsEnum te = t.iterator(); PostingsEnum reuse = null; for (BytesRef term = terms.next(); term != null; term = terms.next()) { if (te.seekExact(term)) { PostingsEnum pe = te.postings(reuse, PostingsEnum.OFFSETS); if (pe.advance(doc) == doc) { mis.add(new TermMatchesIterator(query, pe)); reuse = null; } else { reuse = pe; } } } return fromSubIterators(mis); }
@Override public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException { MultiPostingsEnum docsEnum; // Can only reuse if incoming enum is also a MultiDocsEnum if (reuse != null && reuse instanceof MultiPostingsEnum) { docsEnum = (MultiPostingsEnum) reuse; // ... and was previously created w/ this MultiTermsEnum: if (!docsEnum.canReuse(this)) { docsEnum = new MultiPostingsEnum(this, subs.length); } } else { docsEnum = new MultiPostingsEnum(this, subs.length); } int upto = 0; ArrayUtil.timSort(top, 0, numTop, INDEX_COMPARATOR); for(int i=0;i<numTop;i++) { final TermsEnumWithSlice entry = top[i]; assert entry.index < docsEnum.subPostingsEnums.length: entry.index + " vs " + docsEnum.subPostingsEnums.length + "; " + subs.length; final PostingsEnum subPostingsEnum = entry.terms.postings(docsEnum.subPostingsEnums[entry.index], flags); assert subPostingsEnum != null; docsEnum.subPostingsEnums[entry.index] = subPostingsEnum; subDocs[upto].postingsEnum = subPostingsEnum; subDocs[upto].slice = entry.subSlice; upto++; } return docsEnum.reset(subDocs, upto); }
/** Returns {@link PostingsEnum} for the specified term. * This will return null if either the field or * term does not exist. * <p><b>NOTE:</b> The returned {@link PostingsEnum} may contain deleted docs. * @see TermsEnum#postings(PostingsEnum) */ public final PostingsEnum postings(Term term, int flags) throws IOException { assert term.field() != null; assert term.bytes() != null; final Terms terms = terms(term.field()); if (terms != null) { final TermsEnum termsEnum = terms.iterator(); if (termsEnum.seekExact(term.bytes())) { return termsEnum.postings(null, flags); } } return null; }
final PostingsEnum inDocsAndPositions = in.postings(inReuse, flags); final PostingsEnum inDocs = in.postings(inReuse, flags); final boolean withFreqs = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS) >=0 && PostingsEnum.featureRequested(flags, PostingsEnum.FREQS); return new SortingDocsEnum(docMap.size(), wrapReuse, inDocs, withFreqs, docMap);
@Override public Scorer scorer(LeafReaderContext context) throws IOException { Terms terms = context.reader().terms(fieldName); if (terms == null) { return null; } TermsEnum termsEnum = terms.iterator(); if (termsEnum.seekExact(new BytesRef(featureName)) == false) { return null; } SimScorer scorer = function.scorer(fieldName, boost); PostingsEnum postings = termsEnum.postings(null, PostingsEnum.FREQS); return new Scorer(this) { @Override public int docID() { return postings.docID(); } @Override public float score() throws IOException { return scorer.score(postings.docID(), postings.freq()); } @Override public DocIdSetIterator iterator() { return postings; } }; }
PostingsEnum postingsEnum = te.postings(null, 24); postingsFreqs[i] = new CustomPhraseQuery.PostingsAndFreq(postingsEnum, query.positions[i], t);
@Override public Matches matches(LeafReaderContext context, int doc) throws IOException { TermsEnum te = getTermsEnum(context); if (te == null) { return null; } if (context.reader().terms(term.field()).hasPositions() == false) { return super.matches(context, doc); } return MatchesUtils.forField(term.field(), () -> { PostingsEnum pe = te.postings(null, PostingsEnum.OFFSETS); if (pe.advance(doc) != doc) { return null; } return new TermMatchesIterator(getQuery(), pe); }); }
PostingsEnum postingsEnum = te.postings(null, exposeOffsets ? PostingsEnum.ALL : PostingsEnum.POSITIONS); postingsFreqs[i] = new PostingsAndFreq(postingsEnum, positions[i], t); totalMatchCost += termPositionsCost(te);
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { String desc = "weight(" + getQuery() + " in " + doc + ") [" + function + "]"; Terms terms = context.reader().terms(fieldName); if (terms == null) { return Explanation.noMatch(desc + ". Field " + fieldName + " doesn't exist."); } TermsEnum termsEnum = terms.iterator(); if (termsEnum.seekExact(new BytesRef(featureName)) == false) { return Explanation.noMatch(desc + ". Feature " + featureName + " doesn't exist."); } PostingsEnum postings = termsEnum.postings(null, PostingsEnum.FREQS); if (postings.advance(doc) != doc) { return Explanation.noMatch(desc + ". Feature " + featureName + " isn't set."); } return function.explain(fieldName, featureName, boost, doc, postings.freq()); }
@Override public Spans getSpans(final LeafReaderContext context, Postings requiredPostings) throws IOException { assert termContext.wasBuiltFor(ReaderUtil.getTopLevelContext(context)) : "The top-reader used to create Weight is not the same as the current reader's top-reader (" + ReaderUtil.getTopLevelContext(context); final TermState state = termContext.get(context.ord); if (state == null) { // term is not present in that reader assert context.reader().docFreq(term) == 0 : "no termstate found but term exists in reader term=" + term; return null; } final Terms terms = context.reader().terms(term.field()); if (terms == null) return null; if (terms.hasPositions() == false) throw new IllegalStateException("field \"" + term.field() + "\" was indexed without position data; cannot run SpanTermQuery (term=" + term.text() + ")"); final TermsEnum termsEnum = terms.iterator(); termsEnum.seekExact(term.bytes(), state); final PostingsEnum postings = termsEnum.postings(null, requiredPostings.getRequiredPostings()); float positionsCost = termPositionsCost(termsEnum) * PHRASE_TO_SPAN_TERM_POSITIONS_COST; return new TermSpans(getSimScorer(context), postings, term, positionsCost); } }