@Override float maxFreq() throws IOException { // every term position in each postings list can be at the head of at most // one matching phrase, so the maximum possible phrase freq is the sum of // the freqs of the postings lists. float maxFreq = 0; for (PhrasePositions phrasePosition : phrasePositions) { maxFreq += phrasePosition.postings.freq(); } return maxFreq; }
/** * Create a new {@link TermMatchesIterator} for the given term and postings list */ TermMatchesIterator(Query query, PostingsEnum pe) throws IOException { this.pe = pe; this.query = query; this.upto = pe.freq(); }
@Override public void reset() throws IOException { for (PostingsAndPosition posting : postings) { posting.freq = posting.postings.freq(); posting.pos = -1; posting.upTo = 0; } }
@Override public int freq() throws IOException { assert current != null; return current.freq(); }
@Override public int freq() throws IOException { return in.freq(); }
@Override public int freq() throws IOException { return current.postings.freq(); }
final int freq() throws IOException { return postingsEnum.freq(); }
final void firstPosition() throws IOException { count = postings.freq(); // read first pos nextPosition(); }
@Override public int advance(int target) throws IOException { assert target > doc; doc = postings.advance(target); if (doc != DocIdSetIterator.NO_MORE_DOCS) { freq = postings.freq(); assert freq >= 1; count = 0; } position = -1; return doc; }
@Override public int nextDoc() throws IOException { doc = postings.nextDoc(); if (doc != DocIdSetIterator.NO_MORE_DOCS) { freq = postings.freq(); assert freq >= 1; count = 0; } position = -1; return doc; }
final void firstPosition() throws IOException { count = postings.freq(); // read first pos nextPosition(); }
@Override public float score() throws IOException { assert docID() != DocIdSetIterator.NO_MORE_DOCS; return docScorer.score(postingsEnum.docID(), postingsEnum.freq()); }
@Override public int freq() throws IOException { int doc = docID(); if (doc == posQueueDoc) { return freq; } freq = 0; started = false; posQueue.clear(); for (PostingsAndPosition pp : subs) { if (pp.pe.docID() == doc) { pp.pos = pp.pe.nextPosition(); pp.upto = pp.pe.freq(); posQueue.add(pp); freq += pp.upto; } } return freq; }
private int getPhraseScore(final ComplexQueryData data, final int docBase, final PostingsEnum postingsEnum) throws IOException { int weight = 0; while (postingsEnum.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { int docId = postingsEnum.docID(); if (data.documentIds.has(docBase + docId)) { IntsHolder positions = data.scorer.getPositions(docBase + docId); if (positions == null) { continue; } int freq = postingsEnum.freq(); for (int i = 0; i < freq; i++) { int pos = postingsEnum.nextPosition(); if (positions.has(pos)) { weight++; } } } } return weight; }
posting.freq = posting.postings.freq(); posting.pos = posting.postings.nextPosition(); posting.upTo = 1;
@Override public int freq() throws IOException { int doc = docID(); if (doc != posQueueDoc) { posQueue.clear(); for (PostingsEnum sub : subs) { if (sub.docID() == doc) { int freq = sub.freq(); for (int i = 0; i < freq; i++) { posQueue.add(sub.nextPosition()); } } } posQueue.sort(); posQueueDoc = doc; } return posQueue.size(); }
private void addPositions(final PostingsEnum in, final IndexOutput out) throws IOException { int freq = in.freq(); out.writeVInt(freq); int previousPosition = 0; int previousEndOffset = 0; for (int i = 0; i < freq; i++) { final int pos = in.nextPosition(); final BytesRef payload = in.getPayload(); // The low-order bit of token is set only if there is a payload, the // previous bits are the delta-encoded position. final int token = (pos - previousPosition) << 1 | (payload == null ? 0 : 1); out.writeVInt(token); previousPosition = pos; if (storeOffsets) { // don't encode offsets if they are not stored final int startOffset = in.startOffset(); final int endOffset = in.endOffset(); out.writeVInt(startOffset - previousEndOffset); out.writeVInt(endOffset - startOffset); previousEndOffset = endOffset; } if (payload != null) { out.writeVInt(payload.length); out.writeBytes(payload.bytes, payload.offset, payload.length); } } }
@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()); }
freqs[i] = in.freq(); ++i;
int freq; if (writeFreqs) { freq = postingsEnum.freq(); totalTermFreq += freq; } else {