Java Code Examples for org.apache.lucene.index.PostingsEnum#featureRequested()

The following examples show how to use org.apache.lucene.index.PostingsEnum#featureRequested() . 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: SimpleTextFieldsReader.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException {

  boolean hasPositions = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
  if (hasPositions && PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS)) {

    SimpleTextPostingsEnum docsAndPositionsEnum;
    if (reuse != null && reuse instanceof SimpleTextPostingsEnum && ((SimpleTextPostingsEnum) reuse).canReuse(SimpleTextFieldsReader.this.in)) {
      docsAndPositionsEnum = (SimpleTextPostingsEnum) reuse;
    } else {
      docsAndPositionsEnum = new SimpleTextPostingsEnum();
    }
    return docsAndPositionsEnum.reset(docsStart, indexOptions, docFreq);

  }

  SimpleTextDocsEnum docsEnum;
  if (reuse != null && reuse instanceof SimpleTextDocsEnum && ((SimpleTextDocsEnum) reuse).canReuse(SimpleTextFieldsReader.this.in)) {
    docsEnum = (SimpleTextDocsEnum) reuse;
  } else {
    docsEnum = new SimpleTextDocsEnum();
  }
  return docsEnum.reset(docsStart, indexOptions == IndexOptions.DOCS, docFreq);
}
 
Example 2
Source File: IDVersionPostingsReader.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public PostingsEnum postings(FieldInfo fieldInfo, BlockTermState termState, PostingsEnum reuse, int flags) throws IOException {
  SingleDocsEnum docsEnum;

  if (PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS)) {
    SinglePostingsEnum posEnum;

    if (reuse instanceof SinglePostingsEnum) {
      posEnum = (SinglePostingsEnum) reuse;
    } else {
      posEnum = new SinglePostingsEnum();
    }
    IDVersionTermState _termState = (IDVersionTermState) termState;
    posEnum.reset(_termState.docID, _termState.idVersion);
    return posEnum;
  }

  if (reuse instanceof SingleDocsEnum) {
    docsEnum = (SingleDocsEnum) reuse;
  } else {
    docsEnum = new SingleDocsEnum();
  }
  docsEnum.reset(((IDVersionTermState) termState).docID);

  return docsEnum;
}
 
Example 3
Source File: Lucene84PostingsReader.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public ImpactsEnum impacts(FieldInfo fieldInfo, BlockTermState state, int flags) throws IOException {
  if (state.docFreq <= BLOCK_SIZE) {
    // no skip data
    return new SlowImpactsEnum(postings(fieldInfo, state, null, flags));
  }

  final boolean indexHasPositions = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
  final boolean indexHasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
  final boolean indexHasPayloads = fieldInfo.hasPayloads();

  if (indexHasPositions == false || PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS) == false) {
    return new BlockImpactsDocsEnum(fieldInfo, (IntBlockTermState) state);
  }

  if (indexHasPositions &&
      PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS) &&
      (indexHasOffsets == false || PostingsEnum.featureRequested(flags, PostingsEnum.OFFSETS) == false) &&
      (indexHasPayloads == false || PostingsEnum.featureRequested(flags, PostingsEnum.PAYLOADS) == false)) {
    return new BlockImpactsPostingsEnum(fieldInfo, (IntBlockTermState) state);
  }

  return new BlockImpactsEverythingEnum(fieldInfo, (IntBlockTermState) state, flags);
}
 
Example 4
Source File: Lucene50PostingsReader.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public ImpactsEnum impacts(FieldInfo fieldInfo, BlockTermState state, int flags) throws IOException {
  if (state.docFreq <= BLOCK_SIZE || version < Lucene50PostingsFormat.VERSION_IMPACT_SKIP_DATA) {
    // no skip data
    return new SlowImpactsEnum(postings(fieldInfo, state, null, flags));
  }

  final boolean indexHasPositions = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
  final boolean indexHasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
  final boolean indexHasPayloads = fieldInfo.hasPayloads();

  if (indexHasPositions &&
      PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS) &&
      (indexHasOffsets == false || PostingsEnum.featureRequested(flags, PostingsEnum.OFFSETS) == false) &&
      (indexHasPayloads == false || PostingsEnum.featureRequested(flags, PostingsEnum.PAYLOADS) == false)) {
    return new BlockImpactsPostingsEnum(fieldInfo, (IntBlockTermState) state);
  }

  return new BlockImpactsEverythingEnum(fieldInfo, (IntBlockTermState) state, flags);
}
 
Example 5
Source File: Lucene84PostingsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PostingsEnum postings(FieldInfo fieldInfo, BlockTermState termState, PostingsEnum reuse, int flags) throws IOException {
  
  boolean indexHasPositions = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;

  if (indexHasPositions == false || PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS) == false) {
    BlockDocsEnum docsEnum;
    if (reuse instanceof BlockDocsEnum) {
      docsEnum = (BlockDocsEnum) reuse;
      if (!docsEnum.canReuse(docIn, fieldInfo)) {
        docsEnum = new BlockDocsEnum(fieldInfo);
      }
    } else {
      docsEnum = new BlockDocsEnum(fieldInfo);
    }
    return docsEnum.reset((IntBlockTermState) termState, flags);
  } else {
    EverythingEnum everythingEnum;
    if (reuse instanceof EverythingEnum) {
      everythingEnum = (EverythingEnum) reuse;
      if (!everythingEnum.canReuse(docIn, fieldInfo)) {
        everythingEnum = new EverythingEnum(fieldInfo);
      }
    } else {
      everythingEnum = new EverythingEnum(fieldInfo);
    }
    return everythingEnum.reset((IntBlockTermState) termState, flags);
  }
}
 
Example 6
Source File: Lucene84PostingsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public PostingsEnum reset(IntBlockTermState termState, int flags) throws IOException {
  docFreq = termState.docFreq;
  totalTermFreq = indexHasFreq ? termState.totalTermFreq : docFreq;
  docTermStartFP = termState.docStartFP;
  skipOffset = termState.skipOffset;
  singletonDocID = termState.singletonDocID;
  if (docFreq > 1) {
    if (docIn == null) {
      // lazy init
      docIn = startDocIn.clone();
    }
    docIn.seek(docTermStartFP);
  }

  doc = -1;
  this.needsFreq = PostingsEnum.featureRequested(flags, PostingsEnum.FREQS);
  this.isFreqsRead = true;
  if (indexHasFreq == false || needsFreq == false) {
    for (int i = 0; i < ForUtil.BLOCK_SIZE; ++i) {
      freqBuffer[i] = 1;
    }
  }
  accum = 0;
  blockUpto = 0;
  nextSkipDoc = BLOCK_SIZE - 1; // we won't skip if target is found in first block
  docBufferUpto = BLOCK_SIZE;
  skipped = false;
  return this;
}
 
Example 7
Source File: Lucene50PostingsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PostingsEnum postings(FieldInfo fieldInfo, BlockTermState termState, PostingsEnum reuse, int flags) throws IOException {
  
  boolean indexHasPositions = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;

  if (indexHasPositions == false || PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS) == false) {
    BlockDocsEnum docsEnum;
    if (reuse instanceof BlockDocsEnum) {
      docsEnum = (BlockDocsEnum) reuse;
      if (!docsEnum.canReuse(docIn, fieldInfo)) {
        docsEnum = new BlockDocsEnum(fieldInfo);
      }
    } else {
      docsEnum = new BlockDocsEnum(fieldInfo);
    }
    return docsEnum.reset((IntBlockTermState) termState, flags);
  } else {
    EverythingEnum everythingEnum;
    if (reuse instanceof EverythingEnum) {
      everythingEnum = (EverythingEnum) reuse;
      if (!everythingEnum.canReuse(docIn, fieldInfo)) {
        everythingEnum = new EverythingEnum(fieldInfo);
      }
    } else {
      everythingEnum = new EverythingEnum(fieldInfo);
    }
    return everythingEnum.reset((IntBlockTermState) termState, flags);
  }
}
 
Example 8
Source File: Lucene50PostingsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public PostingsEnum reset(IntBlockTermState termState, int flags) throws IOException {
  docFreq = termState.docFreq;
  totalTermFreq = indexHasFreq ? termState.totalTermFreq : docFreq;
  docTermStartFP = termState.docStartFP;
  skipOffset = termState.skipOffset;
  singletonDocID = termState.singletonDocID;
  if (docFreq > 1) {
    if (docIn == null) {
      // lazy init
      docIn = startDocIn.clone();
    }
    docIn.seek(docTermStartFP);
  }

  doc = -1;
  this.needsFreq = PostingsEnum.featureRequested(flags, PostingsEnum.FREQS);
  this.isFreqsRead = true;
  if (indexHasFreq == false || needsFreq == false) {
    Arrays.fill(freqBuffer, 1);
  }
  accum = 0;
  docUpto = 0;
  nextSkipDoc = BLOCK_SIZE - 1; // we won't skip if target is found in first block
  docBufferUpto = BLOCK_SIZE;
  skipped = false;
  return this;
}
 
Example 9
Source File: Lucene84PostingsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public EverythingEnum reset(IntBlockTermState termState, int flags) throws IOException {
  docFreq = termState.docFreq;
  docTermStartFP = termState.docStartFP;
  posTermStartFP = termState.posStartFP;
  payTermStartFP = termState.payStartFP;
  skipOffset = termState.skipOffset;
  totalTermFreq = termState.totalTermFreq;
  singletonDocID = termState.singletonDocID;
  if (docFreq > 1) {
    if (docIn == null) {
      // lazy init
      docIn = startDocIn.clone();
    }
    docIn.seek(docTermStartFP);
  }
  posPendingFP = posTermStartFP;
  payPendingFP = payTermStartFP;
  posPendingCount = 0;
  if (termState.totalTermFreq < BLOCK_SIZE) {
    lastPosBlockFP = posTermStartFP;
  } else if (termState.totalTermFreq == BLOCK_SIZE) {
    lastPosBlockFP = -1;
  } else {
    lastPosBlockFP = posTermStartFP + termState.lastPosBlockOffset;
  }

  this.needsOffsets = PostingsEnum.featureRequested(flags, PostingsEnum.OFFSETS);
  this.needsPayloads = PostingsEnum.featureRequested(flags, PostingsEnum.PAYLOADS);

  doc = -1;
  accum = 0;
  blockUpto = 0;
  if (docFreq > BLOCK_SIZE) {
    nextSkipDoc = BLOCK_SIZE - 1; // we won't skip if target is found in first block
  } else {
    nextSkipDoc = NO_MORE_DOCS; // not enough docs for skipping
  }
  docBufferUpto = BLOCK_SIZE;
  skipped = false;
  return this;
}
 
Example 10
Source File: Lucene84PostingsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public BlockImpactsEverythingEnum(FieldInfo fieldInfo, IntBlockTermState termState, int flags) throws IOException {
  indexHasFreq = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) >= 0;
  indexHasPos = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
  indexHasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
  indexHasPayloads = fieldInfo.hasPayloads();
  
  needsPositions = PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS);
  needsOffsets = PostingsEnum.featureRequested(flags, PostingsEnum.OFFSETS);
  needsPayloads = PostingsEnum.featureRequested(flags, PostingsEnum.PAYLOADS);
  
  this.docIn = Lucene84PostingsReader.this.docIn.clone();

  if (indexHasPos && needsPositions) {
    this.posIn = Lucene84PostingsReader.this.posIn.clone();
  } else {
    this.posIn = null;
  }
  
  if ((indexHasOffsets && needsOffsets) || (indexHasPayloads && needsPayloads)) {
    this.payIn = Lucene84PostingsReader.this.payIn.clone();
  } else {
    this.payIn = null;
  }
  
  if (indexHasOffsets) {
    offsetStartDeltaBuffer = new long[BLOCK_SIZE];
    offsetLengthBuffer = new long[BLOCK_SIZE];
  } else {
    offsetStartDeltaBuffer = null;
    offsetLengthBuffer = null;
    startOffset = -1;
    endOffset = -1;
  }

  if (indexHasPayloads) {
    payloadLengthBuffer = new long[BLOCK_SIZE];
    payloadBytes = new byte[128];
    payload = new BytesRef();
  } else {
    payloadLengthBuffer = null;
    payloadBytes = null;
    payload = null;
  }

  docFreq = termState.docFreq;
  docTermStartFP = termState.docStartFP;
  posTermStartFP = termState.posStartFP;
  payTermStartFP = termState.payStartFP;
  totalTermFreq = termState.totalTermFreq;
  docIn.seek(docTermStartFP);
  posPendingFP = posTermStartFP;
  payPendingFP = payTermStartFP;
  posPendingCount = 0;
  if (termState.totalTermFreq < BLOCK_SIZE) {
    lastPosBlockFP = posTermStartFP;
  } else if (termState.totalTermFreq == BLOCK_SIZE) {
    lastPosBlockFP = -1;
  } else {
    lastPosBlockFP = posTermStartFP + termState.lastPosBlockOffset;
  }

  doc = -1;
  accum = 0;
  docUpto = 0;
  posDocUpTo = 0;
  isFreqsRead = true;
  docBufferUpto = BLOCK_SIZE;

  skipper = new Lucene84ScoreSkipReader(docIn.clone(),
      MAX_SKIP_LEVELS,
      indexHasPos,
      indexHasOffsets,
      indexHasPayloads);
  skipper.init(docTermStartFP+termState.skipOffset, docTermStartFP, posTermStartFP, payTermStartFP, docFreq);

  if (indexHasFreq == false) {
    for (int i = 0; i < ForUtil.BLOCK_SIZE; ++i) {
      freqBuffer[i] = 1;
    }
  }
}
 
Example 11
Source File: Lucene50PostingsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public EverythingEnum reset(IntBlockTermState termState, int flags) throws IOException {
  docFreq = termState.docFreq;
  docTermStartFP = termState.docStartFP;
  posTermStartFP = termState.posStartFP;
  payTermStartFP = termState.payStartFP;
  skipOffset = termState.skipOffset;
  totalTermFreq = termState.totalTermFreq;
  singletonDocID = termState.singletonDocID;
  if (docFreq > 1) {
    if (docIn == null) {
      // lazy init
      docIn = startDocIn.clone();
    }
    docIn.seek(docTermStartFP);
  }
  posPendingFP = posTermStartFP;
  payPendingFP = payTermStartFP;
  posPendingCount = 0;
  if (termState.totalTermFreq < BLOCK_SIZE) {
    lastPosBlockFP = posTermStartFP;
  } else if (termState.totalTermFreq == BLOCK_SIZE) {
    lastPosBlockFP = -1;
  } else {
    lastPosBlockFP = posTermStartFP + termState.lastPosBlockOffset;
  }

  this.needsOffsets = PostingsEnum.featureRequested(flags, PostingsEnum.OFFSETS);
  this.needsPayloads = PostingsEnum.featureRequested(flags, PostingsEnum.PAYLOADS);

  doc = -1;
  accum = 0;
  docUpto = 0;
  if (docFreq > BLOCK_SIZE) {
    nextSkipDoc = BLOCK_SIZE - 1; // we won't skip if target is found in first block
  } else {
    nextSkipDoc = NO_MORE_DOCS; // not enough docs for skipping
  }
  docBufferUpto = BLOCK_SIZE;
  skipped = false;
  return this;
}
 
Example 12
Source File: Lucene50PostingsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public BlockImpactsEverythingEnum(FieldInfo fieldInfo, IntBlockTermState termState, int flags) throws IOException {
  indexHasFreq = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) >= 0;
  indexHasPos = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
  indexHasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
  indexHasPayloads = fieldInfo.hasPayloads();
  
  needsPositions = PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS);
  needsOffsets = PostingsEnum.featureRequested(flags, PostingsEnum.OFFSETS);
  needsPayloads = PostingsEnum.featureRequested(flags, PostingsEnum.PAYLOADS);
  
  this.docIn = Lucene50PostingsReader.this.docIn.clone();
  
  encoded = new byte[MAX_ENCODED_SIZE];

  if (indexHasPos && needsPositions) {
    this.posIn = Lucene50PostingsReader.this.posIn.clone();
  } else {
    this.posIn = null;
  }
  
  if ((indexHasOffsets && needsOffsets) || (indexHasPayloads && needsPayloads)) {
    this.payIn = Lucene50PostingsReader.this.payIn.clone();
  } else {
    this.payIn = null;
  }
  
  if (indexHasOffsets) {
    offsetStartDeltaBuffer = new int[MAX_DATA_SIZE];
    offsetLengthBuffer = new int[MAX_DATA_SIZE];
  } else {
    offsetStartDeltaBuffer = null;
    offsetLengthBuffer = null;
    startOffset = -1;
    endOffset = -1;
  }

  if (indexHasPayloads) {
    payloadLengthBuffer = new int[MAX_DATA_SIZE];
    payloadBytes = new byte[128];
    payload = new BytesRef();
  } else {
    payloadLengthBuffer = null;
    payloadBytes = null;
    payload = null;
  }

  docFreq = termState.docFreq;
  docTermStartFP = termState.docStartFP;
  posTermStartFP = termState.posStartFP;
  payTermStartFP = termState.payStartFP;
  totalTermFreq = termState.totalTermFreq;
  docIn.seek(docTermStartFP);
  posPendingFP = posTermStartFP;
  payPendingFP = payTermStartFP;
  posPendingCount = 0;
  if (termState.totalTermFreq < BLOCK_SIZE) {
    lastPosBlockFP = posTermStartFP;
  } else if (termState.totalTermFreq == BLOCK_SIZE) {
    lastPosBlockFP = -1;
  } else {
    lastPosBlockFP = posTermStartFP + termState.lastPosBlockOffset;
  }

  doc = -1;
  accum = 0;
  docUpto = 0;
  posDocUpTo = 0;
  isFreqsRead = true;
  docBufferUpto = BLOCK_SIZE;

  skipper = new Lucene50ScoreSkipReader(version,
      docIn.clone(),
      MAX_SKIP_LEVELS,
      indexHasPos,
      indexHasOffsets,
      indexHasPayloads);
  skipper.init(docTermStartFP+termState.skipOffset, docTermStartFP, posTermStartFP, payTermStartFP, docFreq);

  if (indexHasFreq == false) {
    Arrays.fill(freqBuffer, 1);
  }
}