Java Code Examples for org.apache.lucene.index.ImpactsEnum

The following examples show how to use org.apache.lucene.index.ImpactsEnum. These examples are extracted from open source projects. 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 Project: lucene-solr   Source File: Lucene84PostingsReader.java    License: 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 2
Source Project: lucene-solr   Source File: PhraseQuery.java    License: Apache License 2.0 6 votes vote down vote up
public PostingsAndFreq(PostingsEnum postings, ImpactsEnum impacts, int position, Term... terms) {
  this.postings = postings;
  this.impacts = impacts;
  this.position = position;
  nTerms = terms==null ? 0 : terms.length;
  if (nTerms>0) {
    if (terms.length==1) {
      this.terms = terms;
    } else {
      Term[] terms2 = new Term[terms.length];
      System.arraycopy(terms, 0, terms2, 0, terms.length);
      Arrays.sort(terms2);
      this.terms = terms2;
    }
  } else {
    this.terms = null;
  }
}
 
Example 3
Source Project: lucene-solr   Source File: ExactPhraseMatcher.java    License: Apache License 2.0 6 votes vote down vote up
ExactPhraseMatcher(PhraseQuery.PostingsAndFreq[] postings, ScoreMode scoreMode, SimScorer scorer, float matchCost) {
  super(matchCost);

  final DocIdSetIterator approximation = ConjunctionDISI.intersectIterators(Arrays.stream(postings).map(p -> p.postings).collect(Collectors.toList()));
  final ImpactsSource impactsSource = mergeImpacts(Arrays.stream(postings).map(p -> p.impacts).toArray(ImpactsEnum[]::new));

  if (scoreMode == ScoreMode.TOP_SCORES) {
    this.approximation = this.impactsApproximation = new ImpactsDISI(approximation, impactsSource, scorer);
  } else {
    this.approximation = approximation;
    this.impactsApproximation = new ImpactsDISI(approximation, impactsSource, scorer);
  }

  List<PostingsAndPosition> postingsAndPositions = new ArrayList<>();
  for(PhraseQuery.PostingsAndFreq posting : postings) {
    postingsAndPositions.add(new PostingsAndPosition(posting.postings, posting.position));
  }
  this.postings = postingsAndPositions.toArray(new PostingsAndPosition[postingsAndPositions.size()]);
}
 
Example 4
Source Project: lucene-solr   Source File: Lucene50PostingsReader.java    License: 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 Project: lucene-solr   Source File: OrdsSegmentTermsEnum.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  assert !eof;
  //if (DEBUG) {
  //System.out.println("BTTR.docs seg=" + segment);
  //}
  currentFrame.decodeMetaData();
  //if (DEBUG) {
  //System.out.println("  state=" + currentFrame.state);
  //}
  return fr.parent.postingsReader.impacts(fr.fieldInfo, currentFrame.state, flags);
}
 
Example 6
Source Project: lucene-solr   Source File: SegmentTermsEnum.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  assert !eof;
  //if (DEBUG) {
  //System.out.println("BTTR.docs seg=" + segment);
  //}
  currentFrame.decodeMetaData();
  //if (DEBUG) {
  //System.out.println("  state=" + currentFrame.state);
  //}
  return fr.parent.postingsReader.impacts(fr.fieldInfo, currentFrame.state, flags);
}
 
Example 7
Source Project: lucene-solr   Source File: TermScorer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Construct a {@link TermScorer} that will use impacts to skip blocks of
 * non-competitive documents.
 */
TermScorer(Weight weight, ImpactsEnum impactsEnum, LeafSimScorer docScorer) {
  super(weight);
  postingsEnum = this.impactsEnum = impactsEnum;
  impactsDisi = new ImpactsDISI(impactsEnum, impactsEnum, docScorer.getSimScorer());
  iterator = impactsDisi;
  this.docScorer = docScorer;
}
 
Example 8
Source Project: lucene-solr   Source File: PhraseQuery.java    License: Apache License 2.0 5 votes vote down vote up
public PostingsAndFreq(PostingsEnum postings, ImpactsEnum impacts, int position, List<Term> terms) {
  this.postings = postings;
  this.impacts = impacts;
  this.position = position;
  nTerms = terms == null ? 0 : terms.size();
  if (nTerms > 0) {
    Term[] terms2 = terms.toArray(new Term[0]);
    if (nTerms > 1) {
      Arrays.sort(terms2);
    }
    this.terms = terms2;
  } else {
    this.terms = null;
  }
}
 
Example 9
Source Project: querqy   Source File: TermScorer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Construct a {@link org.apache.lucene.search.TermScorer} that will use impacts to skip blocks of
 * non-competitive documents.
 */
TermScorer(Weight weight, ImpactsEnum impactsEnum, LeafSimScorer docScorer) {
    super(weight);
    postingsEnum = this.impactsEnum = impactsEnum;
    impactsDisi = new ImpactsDISI(impactsEnum, impactsEnum, docScorer.getSimScorer());
    iterator = impactsDisi;
    this.docScorer = docScorer;
}
 
Example 10
@Override
public ImpactsEnum impacts(int flags) throws IOException {
    return delegate.impacts(flags);
}
 
Example 11
Source Project: lucene-solr   Source File: FSTTermsReader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  decodeMetaData();
  return postingsReader.impacts(fieldInfo, state, flags);
}
 
Example 12
Source Project: lucene-solr   Source File: DirectPostingsFormat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  return new SlowImpactsEnum(postings(null, flags));
}
 
Example 13
Source Project: lucene-solr   Source File: DirectPostingsFormat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  return new SlowImpactsEnum(postings(null, flags));
}
 
Example 14
Source Project: lucene-solr   Source File: OrdsIntersectTermsEnum.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  currentFrame.decodeMetaData();
  return fr.parent.postingsReader.impacts(fr.fieldInfo, currentFrame.termState, flags);
}
 
Example 15
Source Project: lucene-solr   Source File: BlockTermsReader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  decodeMetaData();
  return postingsReader.impacts(fieldInfo, state, flags);
}
 
Example 16
Source Project: lucene-solr   Source File: SimpleTextTermVectorsReader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  return new SlowImpactsEnum(postings(null, PostingsEnum.FREQS));
}
 
Example 17
Source Project: lucene-solr   Source File: SimpleTextFieldsReader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  return new SlowImpactsEnum(postings(null, flags));
}
 
Example 18
Source Project: lucene-solr   Source File: BloomFilteringPostingsFormat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  return delegate().impacts(flags);
}
 
Example 19
Source Project: lucene-solr   Source File: BlockReader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  readTermStateIfNotRead();
  return postingsReader.impacts(fieldMetadata.getFieldInfo(), termState, flags);
}
 
Example 20
Source Project: lucene-solr   Source File: STMergingTermsEnum.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) {
  throw new UnsupportedOperationException();
}
 
Example 21
Source Project: lucene-solr   Source File: IDVersionSegmentTermsEnum.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  // Only one posting, the slow impl is fine
  // We could make this throw UOE but then CheckIndex is angry
  return new SlowImpactsEnum(postings(null, flags));
}
 
Example 22
Source Project: lucene-solr   Source File: IDVersionPostingsReader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(FieldInfo fieldInfo, BlockTermState state, int flags) throws IOException {
  throw new UnsupportedOperationException("Should never be called, IDVersionSegmentTermsEnum implements impacts directly");
}
 
Example 23
Source Project: lucene-solr   Source File: RAMOnlyPostingsFormat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  return new SlowImpactsEnum(postings(null, PostingsEnum.FREQS));
}
 
Example 24
Source Project: lucene-solr   Source File: DocValuesConsumer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  throw new UnsupportedOperationException();
}
 
Example 25
Source Project: lucene-solr   Source File: Lucene80DocValuesProducer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  throw new UnsupportedOperationException();
}
 
Example 26
Source Project: lucene-solr   Source File: IntersectTermsEnum.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  currentFrame.decodeMetaData();
  return fr.parent.postingsReader.impacts(fr.fieldInfo, currentFrame.termState, flags);
}
 
Example 27
Source Project: lucene-solr   Source File: CompressingTermVectorsReader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  final PostingsEnum delegate = postings(null, PostingsEnum.FREQS);
  return new SlowImpactsEnum(delegate);
}
 
Example 28
Source Project: lucene-solr   Source File: FuzzyTermsEnum.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  return actualEnum.impacts(flags);
}
 
Example 29
Source Project: lucene-solr   Source File: TestSynonymQuery.java    License: Apache License 2.0 4 votes vote down vote up
public void testMergeImpacts() throws IOException {
  DummyImpactsEnum impacts1 = new DummyImpactsEnum();
  impacts1.reset(42,
      new Impact[][] {
        new Impact[] { new Impact(3, 10), new Impact(5, 12), new Impact(8, 13) },
        new Impact[] { new Impact(5, 11), new Impact(8, 13),  new Impact(12, 14) }
      },
      new int[] {
          110,
          945
      });
  DummyImpactsEnum impacts2 = new DummyImpactsEnum();
  impacts2.reset(45,
      new Impact[][] {
        new Impact[] { new Impact(2, 10), new Impact(6, 13) },
        new Impact[] { new Impact(3, 9), new Impact(5, 11), new Impact(7, 13) }
      },
      new int[] {
          90,
          1000
      });

  ImpactsSource mergedImpacts = SynonymQuery.mergeImpacts(new ImpactsEnum[] { impacts1, impacts2 }, new float[] { 1f, 1f });
  assertEquals(
      new Impact[][] {
        new Impact[] { new Impact(5, 10), new Impact(7, 12), new Impact(14, 13) },
        new Impact[] { new Impact(Integer.MAX_VALUE, 1) }
      },
      new int[] {
          90,
          1000
      },
      mergedImpacts.getImpacts());

  ImpactsSource mergedBoostedImpacts = SynonymQuery.mergeImpacts(new ImpactsEnum[] { impacts1, impacts2 }, new float[] { 0.3f, 0.9f });
  assertEquals(
      new Impact[][] {
          new Impact[] { new Impact(3, 10), new Impact(4, 12), new Impact(9, 13) },
          new Impact[] { new Impact(Integer.MAX_VALUE, 1) }
      },
      new int[] {
          90,
          1000
      },
      mergedBoostedImpacts.getImpacts());

  // docID is > the first doIdUpTo of impacts1
  impacts2.reset(112,
      new Impact[][] {
        new Impact[] { new Impact(2, 10), new Impact(6, 13) },
        new Impact[] { new Impact(3, 9), new Impact(5, 11), new Impact(7, 13) }
      },
      new int[] {
          150,
          1000
      });
  assertEquals(
      new Impact[][] {
        new Impact[] { new Impact(3, 10), new Impact(5, 12), new Impact(8, 13) }, // same as impacts1
        new Impact[] { new Impact(3, 9), new Impact(10, 11), new Impact(15, 13), new Impact(19, 14) }
      },
      new int[] {
          110,
          945
      },
      mergedImpacts.getImpacts());

  assertEquals(
      new Impact[][] {
          new Impact[] { new Impact(1, 10), new Impact(2, 12), new Impact(3, 13) }, // same as impacts1*boost
          new Impact[] { new Impact(3, 9), new Impact(7, 11), new Impact(10, 13), new Impact(11, 14) }
      },
      new int[] {
          110,
          945
      },
      mergedBoostedImpacts.getImpacts());
}
 
Example 30
Source Project: lucene-solr   Source File: DocTermOrds.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ImpactsEnum impacts(int flags) throws IOException {
  return termsEnum.impacts(flags);
}