Search in sources :

Example 1 with ReaderSlice

use of org.apache.lucene.index.ReaderSlice in project lucene-solr by apache.

the class FieldsConsumer method merge.

/** Merges in the fields from the readers in 
   *  <code>mergeState</code>. The default implementation skips
   *  and maps around deleted documents, and calls {@link #write(Fields)}.
   *  Implementations can override this method for more sophisticated
   *  merging (bulk-byte copying, etc). */
public void merge(MergeState mergeState) throws IOException {
    final List<Fields> fields = new ArrayList<>();
    final List<ReaderSlice> slices = new ArrayList<>();
    int docBase = 0;
    for (int readerIndex = 0; readerIndex < mergeState.fieldsProducers.length; readerIndex++) {
        final FieldsProducer f = mergeState.fieldsProducers[readerIndex];
        final int maxDoc = mergeState.maxDocs[readerIndex];
        f.checkIntegrity();
        slices.add(new ReaderSlice(docBase, maxDoc, readerIndex));
        fields.add(f);
        docBase += maxDoc;
    }
    Fields mergedFields = new MappedMultiFields(mergeState, new MultiFields(fields.toArray(Fields.EMPTY_ARRAY), slices.toArray(ReaderSlice.EMPTY_ARRAY)));
    write(mergedFields);
}
Also used : Fields(org.apache.lucene.index.Fields) MultiFields(org.apache.lucene.index.MultiFields) MappedMultiFields(org.apache.lucene.index.MappedMultiFields) ArrayList(java.util.ArrayList) MultiFields(org.apache.lucene.index.MultiFields) MappedMultiFields(org.apache.lucene.index.MappedMultiFields) MappedMultiFields(org.apache.lucene.index.MappedMultiFields) ReaderSlice(org.apache.lucene.index.ReaderSlice)

Example 2 with ReaderSlice

use of org.apache.lucene.index.ReaderSlice in project neo4j by neo4j.

the class PartitionedUniquenessVerifier method termsForField.

private Terms termsForField(String fieldName) throws IOException {
    List<Terms> terms = new ArrayList<>();
    List<ReaderSlice> readerSlices = new ArrayList<>();
    for (LeafReader leafReader : allLeafReaders()) {
        Fields fields = leafReader.fields();
        Terms leafTerms = fields.terms(fieldName);
        if (leafTerms != null) {
            ReaderSlice readerSlice = new ReaderSlice(0, Math.toIntExact(leafTerms.size()), 0);
            terms.add(leafTerms);
            readerSlices.add(readerSlice);
        }
    }
    Terms[] termsArray = terms.toArray(new Terms[terms.size()]);
    ReaderSlice[] readerSlicesArray = readerSlices.toArray(new ReaderSlice[readerSlices.size()]);
    return new MultiTerms(termsArray, readerSlicesArray);
}
Also used : Fields(org.apache.lucene.index.Fields) LeafReader(org.apache.lucene.index.LeafReader) MultiTerms(org.apache.lucene.index.MultiTerms) ArrayList(java.util.ArrayList) Terms(org.apache.lucene.index.Terms) MultiTerms(org.apache.lucene.index.MultiTerms) ReaderSlice(org.apache.lucene.index.ReaderSlice)

Aggregations

ArrayList (java.util.ArrayList)2 Fields (org.apache.lucene.index.Fields)2 ReaderSlice (org.apache.lucene.index.ReaderSlice)2 LeafReader (org.apache.lucene.index.LeafReader)1 MappedMultiFields (org.apache.lucene.index.MappedMultiFields)1 MultiFields (org.apache.lucene.index.MultiFields)1 MultiTerms (org.apache.lucene.index.MultiTerms)1 Terms (org.apache.lucene.index.Terms)1