org.apache.lucene.index.TermState Java Examples

The following examples show how to use org.apache.lucene.index.TermState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlendedTermQuery.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private TermContext adjustTTF(TermContext termContext, long sumTTF) {
    if (sumTTF == -1 && termContext.totalTermFreq() == -1) {
        return termContext;
    }
    TermContext newTermContext = new TermContext(termContext.topReaderContext);
    List<LeafReaderContext> leaves = termContext.topReaderContext.leaves();
    final int len;
    if (leaves == null) {
        len = 1;
    } else {
        len = leaves.size();
    }
    int df = termContext.docFreq();
    long ttf = sumTTF;
    for (int i = 0; i < len; i++) {
        TermState termState = termContext.get(i);
        if (termState == null) {
            continue;
        }
        newTermContext.register(termState, i, df, ttf);
        df = 0;
        ttf = 0;
    }
    return newTermContext;
}
 
Example #2
Source File: BlockTreeTermsReader.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Override
public void seekExact(BytesRef target, TermState otherState) {
  // if (DEBUG) {
  //   System.out.println("BTTR.seekExact termState seg=" + segment + " target=" + target.utf8ToString() + " " + target + " state=" + otherState);
  // }
  assert clearEOF();
  if (target.compareTo(term) != 0 || !termExists) {
    assert otherState != null && otherState instanceof BlockTermState;
    currentFrame = staticFrame;
    currentFrame.state.copyFrom(otherState);
    term.copyBytes(target);
    currentFrame.metaDataUpto = currentFrame.getTermBlockOrd();
    assert currentFrame.metaDataUpto > 0;
    validIndexPrefix = 0;
  } else {
    // if (DEBUG) {
    //   System.out.println("  skip seek: already on target state=" + currentFrame.state);
    // }
  }
}
 
Example #3
Source File: SolrRangeQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** Try to collect terms from the given terms enum and return count=sum(df) for terms visited so far
 *  or (-count - 1) if this should be rewritten into a boolean query.
 *  The termEnum will already be positioned on the next term if not exhausted.
 */
private long collectTerms(LeafReaderContext context, TermsEnum termsEnum, List<TermAndState> terms) throws IOException {
  long count = 0;
  final int threshold = Math.min(BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD, IndexSearcher.getMaxClauseCount());
  for (int i = 0; i < threshold; ++i) {
    final BytesRef term = termsEnum.next();
    if (term == null) {
      return -count - 1;
    }
    TermState state = termsEnum.termState();
    int df = termsEnum.docFreq();
    count += df;
    terms.add(new TermAndState(BytesRef.deepCopyOf(term), state, df, termsEnum.totalTermFreq()));
  }
  return termsEnum.next() == null ? (-count - 1) : count;
}
 
Example #4
Source File: BlendedTermQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static TermStates adjustFrequencies(IndexReaderContext readerContext,
                                            TermStates ctx, int artificialDf, long artificialTtf) throws IOException {
  List<LeafReaderContext> leaves = readerContext.leaves();
  final int len;
  if (leaves == null) {
    len = 1;
  } else {
    len = leaves.size();
  }
  TermStates newCtx = new TermStates(readerContext);
  for (int i = 0; i < len; ++i) {
    TermState termState = ctx.get(leaves.get(i));
    if (termState == null) {
      continue;
    }
    newCtx.register(termState, i);
  }
  newCtx.accumulateStatistics(artificialDf, artificialTtf);
  return newCtx;
}
 
Example #5
Source File: OrdsSegmentTermsEnum.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void seekExact(BytesRef target, TermState otherState) {
  // if (DEBUG) {
  //   System.out.println("BTTR.seekExact termState seg=" + segment + " target=" + target.utf8ToString() + " " + target + " state=" + otherState);
  // }
  assert clearEOF();
  if (target.compareTo(term.get()) != 0 || !termExists) {
    assert otherState != null && otherState instanceof BlockTermState;
    BlockTermState blockState = (BlockTermState) otherState;
    currentFrame = staticFrame;
    currentFrame.state.copyFrom(otherState);
    term.copyBytes(target);
    currentFrame.metaDataUpto = currentFrame.getTermBlockOrd();
    currentFrame.termOrd = blockState.ord+1;
    assert currentFrame.metaDataUpto > 0;
    validIndexPrefix = 0;
  } else {
    // if (DEBUG) {
    //   System.out.println("  skip seek: already on target state=" + currentFrame.state);
    // }
  }
  positioned = true;
}
 
Example #6
Source File: SegmentTermsEnum.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void seekExact(BytesRef target, TermState otherState) {
  // if (DEBUG) {
  //   System.out.println("BTTR.seekExact termState seg=" + segment + " target=" + target.utf8ToString() + " " + target + " state=" + otherState);
  // }
  assert clearEOF();
  if (target.compareTo(term.get()) != 0 || !termExists) {
    assert otherState != null && otherState instanceof BlockTermState;
    currentFrame = staticFrame;
    currentFrame.state.copyFrom(otherState);
    term.copyBytes(target);
    currentFrame.metaDataUpto = currentFrame.getTermBlockOrd();
    assert currentFrame.metaDataUpto > 0;
    validIndexPrefix = 0;
  } else {
    // if (DEBUG) {
    //   System.out.println("  skip seek: already on target state=" + currentFrame.state);
    // }
  }
}
 
Example #7
Source File: IDVersionSegmentTermsEnum.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void seekExact(BytesRef target, TermState otherState) {
  // if (DEBUG) {
  //   System.out.println("BTTR.seekExact termState seg=" + segment + " target=" + target.utf8ToString() + " " + target + " state=" + otherState);
  // }
  assert clearEOF();
  if (target.compareTo(term.get()) != 0 || !termExists) {
    assert otherState != null && otherState instanceof BlockTermState;
    currentFrame = staticFrame;
    currentFrame.state.copyFrom(otherState);
    term.copyBytes(target);
    currentFrame.metaDataUpto = currentFrame.getTermBlockOrd();
    assert currentFrame.metaDataUpto > 0;
    validIndexPrefix = 0;
  } else {
    // if (DEBUG) {
    //   System.out.println("  skip seek: already on target state=" + currentFrame.state);
    // }
  }
}
 
Example #8
Source File: IDVersionSegmentTermsEnum.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public TermState termState() throws IOException {
  assert !eof;
  currentFrame.decodeMetaData();
  TermState ts = currentFrame.state.clone();
  //if (DEBUG) System.out.println("BTTR.termState seg=" + segment + " state=" + ts);
  return ts;
}
 
Example #9
Source File: BlockTreeTermsReader.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Override
public TermState termState() throws IOException {
  assert !eof;
  currentFrame.decodeMetaData();
  TermState ts = currentFrame.state.clone();
  //if (DEBUG) System.out.println("BTTR.termState seg=" + segment + " state=" + ts);
  return ts;
}
 
Example #10
Source File: Lucene50PostingsFormat.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void copyFrom(TermState _other) {
  super.copyFrom(_other);
  IntBlockTermState other = (IntBlockTermState) _other;
  docStartFP = other.docStartFP;
  posStartFP = other.posStartFP;
  payStartFP = other.payStartFP;
  lastPosBlockOffset = other.lastPosBlockOffset;
  skipOffset = other.skipOffset;
  singletonDocID = other.singletonDocID;
}
 
Example #11
Source File: Lucene84PostingsFormat.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void copyFrom(TermState _other) {
  super.copyFrom(_other);
  IntBlockTermState other = (IntBlockTermState) _other;
  docStartFP = other.docStartFP;
  posStartFP = other.posStartFP;
  payStartFP = other.payStartFP;
  lastPosBlockOffset = other.lastPosBlockOffset;
  skipOffset = other.skipOffset;
  singletonDocID = other.singletonDocID;
}
 
Example #12
Source File: BlockTermState.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void copyFrom(TermState _other) {
  assert _other instanceof BlockTermState : "can not copy from " + _other.getClass().getName();
  BlockTermState other = (BlockTermState) _other;
  super.copyFrom(_other);
  docFreq = other.docFreq;
  totalTermFreq = other.totalTermFreq;
  termBlockOrd = other.termBlockOrd;
  blockFilePointer = other.blockFilePointer;
}
 
Example #13
Source File: SegmentTermsEnum.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public TermState termState() throws IOException {
  assert !eof;
  currentFrame.decodeMetaData();
  TermState ts = currentFrame.state.clone();
  //if (DEBUG) System.out.println("BTTR.termState seg=" + segment + " state=" + ts);
  return ts;
}
 
Example #14
Source File: IDVersionTermState.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void copyFrom(TermState _other) {
  super.copyFrom(_other);
  IDVersionTermState other = (IDVersionTermState) _other;
  idVersion = other.idVersion;
  docID = other.docID;
}
 
Example #15
Source File: BlendedTermQuery.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static TermContext adjustDF(TermContext ctx, int newDocFreq) {
    // Use a value of ttf that is consistent with the doc freq (ie. gte)
    long newTTF;
    if (ctx.totalTermFreq() < 0) {
        newTTF = -1;
    } else {
        newTTF = Math.max(ctx.totalTermFreq(), newDocFreq);
    }
    List<LeafReaderContext> leaves = ctx.topReaderContext.leaves();
    final int len;
    if (leaves == null) {
        len = 1;
    } else {
        len = leaves.size();
    }
    TermContext newCtx = new TermContext(ctx.topReaderContext);
    for (int i = 0; i < len; ++i) {
        TermState termState = ctx.get(i);
        if (termState == null) {
            continue;
        }
        newCtx.register(termState, i, newDocFreq, newTTF);
        newDocFreq = 0;
        newTTF = 0;
    }
    return newCtx;
}
 
Example #16
Source File: OrdsSegmentTermsEnum.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public TermState termState() throws IOException {
  assert !eof;
  currentFrame.decodeMetaData();
  BlockTermState ts = (BlockTermState) currentFrame.state.clone();
  assert currentFrame.termOrd > 0;
  ts.ord = currentFrame.termOrd-1;
  //if (DEBUG) System.out.println("BTTR.termState seg=" + segment + " state=" + ts);
  return ts;
}
 
Example #17
Source File: BlockTermsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public TermState termState() throws IOException {
  //System.out.println("BTR.termState this=" + this);
  decodeMetaData();
  TermState ts = state.clone();
  //System.out.println("  return ts=" + ts);
  return ts;
}
 
Example #18
Source File: BlockTermsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void seekExact(BytesRef target, TermState otherState) {
  //System.out.println("BTR.seekExact termState target=" + target.utf8ToString() + " " + target + " this=" + this);
  assert otherState != null && otherState instanceof BlockTermState;
  assert !doOrd || ((BlockTermState) otherState).ord < numTerms;
  state.copyFrom(otherState);
  seekPending = true;
  indexIsCurrent = false;
  term.copyBytes(target);
}
 
Example #19
Source File: FSTTermsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void seekExact(BytesRef target, TermState otherState) {
  if (!target.equals(term)) {
    state.copyFrom(otherState);
    term = BytesRef.deepCopyOf(target);
    seekPending = true;
  }
}
 
Example #20
Source File: SolrRangeQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void seekExact(BytesRef term, TermState state) throws IOException {
  te.seekExact(term, state);
}
 
Example #21
Source File: DirectPostingsFormat.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void seekExact(BytesRef term, TermState state) throws IOException {
  termOrd = (int) ((OrdTermState) state).ord;
  setTerm();
  assert term.equals(scratch);
}
 
Example #22
Source File: MultiTermQueryConstantScoreWrapper.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
TermAndState(BytesRef term, TermState state, int docFreq, long totalTermFreq) {
  this.term = term;
  this.state = state;
  this.docFreq = docFreq;
  this.totalTermFreq = totalTermFreq;
}
 
Example #23
Source File: DirectPostingsFormat.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public TermState termState() {
  OrdTermState state = new OrdTermState();
  state.ord = termOrd;
  return state;
}
 
Example #24
Source File: FuzzyTermsEnum.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void seekExact(BytesRef term, TermState state) throws IOException {
  actualEnum.seekExact(term, state);
}
 
Example #25
Source File: FuzzyTermsEnum.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public TermState termState() throws IOException {
  return actualEnum.termState();
}
 
Example #26
Source File: IntersectTermsEnum.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public TermState termState() throws IOException {
  currentFrame.decodeMetaData();
  return currentFrame.termState.clone();
}
 
Example #27
Source File: SolrRangeQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public TermState termState() throws IOException {
  return te.termState();
}
 
Example #28
Source File: SolrRangeQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
TermAndState(BytesRef term, TermState state, int docFreq, long totalTermFreq) {
  this.term = term;
  this.state = state;
  this.docFreq = docFreq;
  this.totalTermFreq = totalTermFreq;
}
 
Example #29
Source File: FSTTermsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public TermState termState() throws IOException {
  decodeMetaData();
  return state.clone();
}
 
Example #30
Source File: BlockTreeTermsReader.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
@Override
public TermState termState() throws IOException {
  currentFrame.decodeMetaData();
  return currentFrame.termState.clone();
}