@Override public long totalTermFreq() throws IOException { long sum = 0; for(int i=0;i<numTop;i++) { final long v = top[i].terms.totalTermFreq(); if (v == -1) { return v; } sum += v; } return sum; }
@Override public long totalTermFreq() throws IOException { return actualEnum.totalTermFreq(); }
@Override public long totalTermFreq() throws IOException { return in.totalTermFreq(); }
@Override public long totalTermFreq() throws IOException { return tenum.totalTermFreq(); }
/** Returns an expected cost in simple operations * of processing the occurrences of a term * in a document that contains the term. * This is for use by {@link TwoPhaseIterator#matchCost} implementations. * <br>This may be inaccurate when {@link TermsEnum#totalTermFreq()} is not available. * @param termsEnum The term is the term at which this TermsEnum is positioned. */ static float termPositionsCost(TermsEnum termsEnum) throws IOException { int docFreq = termsEnum.docFreq(); assert docFreq > 0; long totalTermFreq = termsEnum.totalTermFreq(); // -1 when not available float expOccurrencesInMatchingDoc = (totalTermFreq < docFreq) ? 1 : (totalTermFreq / (float) docFreq); return TERM_POSNS_SEEK_OPS_PER_DOC + expOccurrencesInMatchingDoc * TERM_OPS_PER_POS; }
/** Returns an expected cost in simple operations * of processing the occurrences of a term * in a document that contains the term. * <br>This may be inaccurate when {@link TermsEnum#totalTermFreq()} is not available. * @param termsEnum The term is the term at which this TermsEnum is positioned. * <p> * This is a copy of org.apache.lucene.search.PhraseQuery.termPositionsCost(). * <br> * TODO: keep only a single copy of this method and the constants used in it * when SpanTermQuery moves to the o.a.l.search package. */ static float termPositionsCost(TermsEnum termsEnum) throws IOException { int docFreq = termsEnum.docFreq(); assert docFreq > 0; long totalTermFreq = termsEnum.totalTermFreq(); // -1 when not available float expOccurrencesInMatchingDoc = (totalTermFreq < docFreq) ? 1 : (totalTermFreq / (float) docFreq); return TERM_POSNS_SEEK_OPS_PER_DOC + expOccurrencesInMatchingDoc * TERM_OPS_PER_POS; }
TermAndState(String field, TermsEnum termsEnum) throws IOException { this.field = field; this.termsEnum = termsEnum; this.term = BytesRef.deepCopyOf(termsEnum.term()); this.state = termsEnum.termState(); this.docFreq = termsEnum.docFreq(); this.totalTermFreq = termsEnum.totalTermFreq(); } }
/** Try to collect terms from the given terms enum and return true iff all * terms could be collected. If {@code false} is returned, the enum is * left positioned on the next term. */ private boolean collectTerms(LeafReaderContext context, TermsEnum termsEnum, List<TermAndState> terms) throws IOException { final int threshold = Math.min(BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD, BooleanQuery.getMaxClauseCount()); for (int i = 0; i < threshold; ++i) { final BytesRef term = termsEnum.next(); if (term == null) { return true; } TermState state = termsEnum.termState(); terms.add(new TermAndState(BytesRef.deepCopyOf(term), state, termsEnum.docFreq(), termsEnum.totalTermFreq())); } return termsEnum.next() == null; }
t.termState.register(state, readerContext.ord, termsEnum.docFreq(), termsEnum.totalTermFreq()); } else { visitedTerms.put(st.bytes.get(), st); assert st.termState.docFreq() == 0; st.termState.register(state, readerContext.ord, termsEnum.docFreq(), termsEnum.totalTermFreq()); stQueue.offer(st);
/** Returns the number of documents containing the term * <code>t</code>. This method returns 0 if the term or * field does not exists. This method does not take into * account deleted documents that have not yet been merged * away. */ @Override public final long totalTermFreq(Term term) throws IOException { final Terms terms = terms(term.field()); if (terms == null) { return 0; } final TermsEnum termsEnum = terms.iterator(); if (termsEnum.seekExact(term.bytes())) { return termsEnum.totalTermFreq(); } else { return 0; } }
if (termsEnum.totalTermFreq() != -1) { throw new RuntimeException("field \"" + field + "\" hasFreqs is false, but TermsEnum.totalTermFreq()=" + termsEnum.totalTermFreq() + " (should be -1)"); final long totalTermFreq2 = termsEnum.totalTermFreq(); final boolean hasTotalTermFreq = hasFreqs && totalTermFreq2 != -1;
/** * Creates a {@link TermContext} from a top-level {@link IndexReaderContext} and the * given {@link 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 {@link TermContext} * using the leaf reader's ordinal. * <p> * Note: the given context must be a top-level context. */ public static TermContext build(IndexReaderContext context, Term term) throws IOException { assert context != null && context.isTopLevel; final String field = term.field(); final BytesRef bytes = term.bytes(); final TermContext perReaderTermState = new TermContext(context); //if (DEBUG) System.out.println("prts.build term=" + term); for (final LeafReaderContext ctx : context.leaves()) { //if (DEBUG) System.out.println(" r=" + leaves[i].reader); final Terms terms = ctx.reader().terms(field); if (terms != null) { final TermsEnum termsEnum = terms.iterator(); if (termsEnum.seekExact(bytes)) { final TermState termState = termsEnum.termState(); //if (DEBUG) System.out.println(" found"); perReaderTermState.register(termState, ctx.ord, termsEnum.docFreq(), termsEnum.totalTermFreq()); } } } return perReaderTermState; }
termCount++; final int freq = (int) termsEnum.totalTermFreq();
termCount++; final int freq = (int) termsEnum.totalTermFreq();
private void buildTermStatistics(XContentBuilder builder, TermsEnum termIter) throws IOException { // write term statistics. At this point we do not naturally have a // boolean that says if these values actually were requested. // However, we can assume that they were not if the statistic values are // <= 0. assert (((termIter.docFreq() > 0) && (termIter.totalTermFreq() > 0)) || ((termIter.docFreq() == -1) && (termIter.totalTermFreq() == -1))); int docFreq = termIter.docFreq(); if (docFreq > 0) { builder.field(FieldStrings.DOC_FREQ, docFreq); builder.field(FieldStrings.TTF, termIter.totalTermFreq()); } }
public long internalFrequency(BytesRef term) throws IOException { if (termsEnum.seekExact(term)) { return useTotalTermFrequency ? termsEnum.totalTermFreq() : termsEnum.docFreq(); } return 0; }
public long frequency(BytesRef term) throws IOException { if (termsEnum.seekExact(term)) { return useTotalTermFreq ? termsEnum.totalTermFreq() : termsEnum.docFreq(); } return 0; }
private void writeTermStatistics(TermsEnum topLevelIterator) throws IOException { int docFreq = topLevelIterator.docFreq(); assert (docFreq >= -1); writePotentiallyNegativeVInt(docFreq); long ttf = topLevelIterator.totalTermFreq(); assert (ttf >= -1); writePotentiallyNegativeVLong(ttf); }
private TermStatistics getTermStatistics(TermsEnum termsEnum, Term term) throws IOException { if (dfs != null) { return dfs.termStatistics().get(term); } return new TermStatistics(termsEnum.term(), termsEnum.docFreq(), termsEnum.totalTermFreq()); }
long termFreq = termsEnum.totalTermFreq(); if (termFreq > Integer.MAX_VALUE) { throw new IllegalArgumentException("Sorry can't handle longs yet");