Search in sources :

Example 6 with FieldsProducer

use of org.apache.lucene.codecs.FieldsProducer in project lucene-solr by apache.

the class TestCodecs method testRandomPostings.

public void testRandomPostings() throws Throwable {
    final FieldInfos.Builder builder = new FieldInfos.Builder();
    final FieldData[] fields = new FieldData[NUM_FIELDS];
    for (int i = 0; i < NUM_FIELDS; i++) {
        final boolean omitTF = 0 == (i % 3);
        final boolean storePayloads = 1 == (i % 3);
        fields[i] = new FieldData(fieldNames[i], builder, this.makeRandomTerms(omitTF, storePayloads), omitTF, storePayloads);
    }
    final Directory dir = newDirectory();
    final FieldInfos fieldInfos = builder.finish();
    if (VERBOSE) {
        System.out.println("TEST: now write postings");
    }
    Codec codec = Codec.getDefault();
    final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, SEGMENT, 10000, false, codec, Collections.emptyMap(), StringHelper.randomId(), new HashMap<>(), null);
    this.write(si, fieldInfos, dir, fields);
    if (VERBOSE) {
        System.out.println("TEST: now read postings");
    }
    final FieldsProducer terms = codec.postingsFormat().fieldsProducer(new SegmentReadState(dir, si, fieldInfos, newIOContext(random())));
    final Verify[] threads = new Verify[NUM_TEST_THREADS - 1];
    for (int i = 0; i < NUM_TEST_THREADS - 1; i++) {
        threads[i] = new Verify(si, fields, terms);
        threads[i].setDaemon(true);
        threads[i].start();
    }
    new Verify(si, fields, terms).run();
    for (int i = 0; i < NUM_TEST_THREADS - 1; i++) {
        threads[i].join();
        assert !threads[i].failed;
    }
    terms.close();
    dir.close();
}
Also used : FieldsProducer(org.apache.lucene.codecs.FieldsProducer) Codec(org.apache.lucene.codecs.Codec) Directory(org.apache.lucene.store.Directory)

Example 7 with FieldsProducer

use of org.apache.lucene.codecs.FieldsProducer in project lucene-solr by apache.

the class DirectPostingsFormat method fieldsProducer.

@Override
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
    FieldsProducer postings = PostingsFormat.forName("Lucene50").fieldsProducer(state);
    if (state.context.context != IOContext.Context.MERGE) {
        FieldsProducer loadedPostings;
        try {
            postings.checkIntegrity();
            loadedPostings = new DirectFields(state, postings, minSkipCount, lowFreqCutoff);
        } finally {
            postings.close();
        }
        return loadedPostings;
    } else {
        // Don't load postings for merge:
        return postings;
    }
}
Also used : FieldsProducer(org.apache.lucene.codecs.FieldsProducer)

Example 8 with FieldsProducer

use of org.apache.lucene.codecs.FieldsProducer in project lucene-solr by apache.

the class FSTOrdPostingsFormat method fieldsProducer.

@Override
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
    PostingsReaderBase postingsReader = new Lucene50PostingsReader(state);
    boolean success = false;
    try {
        FieldsProducer ret = new FSTOrdTermsReader(state, postingsReader);
        success = true;
        return ret;
    } finally {
        if (!success) {
            IOUtils.closeWhileHandlingException(postingsReader);
        }
    }
}
Also used : FieldsProducer(org.apache.lucene.codecs.FieldsProducer) PostingsReaderBase(org.apache.lucene.codecs.PostingsReaderBase) Lucene50PostingsReader(org.apache.lucene.codecs.lucene50.Lucene50PostingsReader)

Example 9 with FieldsProducer

use of org.apache.lucene.codecs.FieldsProducer in project lucene-solr by apache.

the class FSTPostingsFormat method fieldsProducer.

@Override
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
    PostingsReaderBase postingsReader = new Lucene50PostingsReader(state);
    boolean success = false;
    try {
        FieldsProducer ret = new FSTTermsReader(state, postingsReader);
        success = true;
        return ret;
    } finally {
        if (!success) {
            IOUtils.closeWhileHandlingException(postingsReader);
        }
    }
}
Also used : FieldsProducer(org.apache.lucene.codecs.FieldsProducer) PostingsReaderBase(org.apache.lucene.codecs.PostingsReaderBase) Lucene50PostingsReader(org.apache.lucene.codecs.lucene50.Lucene50PostingsReader)

Example 10 with FieldsProducer

use of org.apache.lucene.codecs.FieldsProducer in project lucene-solr by apache.

the class BlockTreeOrdsPostingsFormat method fieldsProducer.

@Override
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
    PostingsReaderBase postingsReader = new Lucene50PostingsReader(state);
    boolean success = false;
    try {
        FieldsProducer ret = new OrdsBlockTreeTermsReader(postingsReader, state);
        success = true;
        return ret;
    } finally {
        if (!success) {
            IOUtils.closeWhileHandlingException(postingsReader);
        }
    }
}
Also used : FieldsProducer(org.apache.lucene.codecs.FieldsProducer) PostingsReaderBase(org.apache.lucene.codecs.PostingsReaderBase) Lucene50PostingsReader(org.apache.lucene.codecs.lucene50.Lucene50PostingsReader)

Aggregations

FieldsProducer (org.apache.lucene.codecs.FieldsProducer)18 PostingsReaderBase (org.apache.lucene.codecs.PostingsReaderBase)9 Lucene50PostingsReader (org.apache.lucene.codecs.lucene50.Lucene50PostingsReader)7 Directory (org.apache.lucene.store.Directory)7 BlockTermsReader (org.apache.lucene.codecs.blockterms.BlockTermsReader)4 TermsIndexReaderBase (org.apache.lucene.codecs.blockterms.TermsIndexReaderBase)4 Codec (org.apache.lucene.codecs.Codec)3 VariableGapTermsIndexReader (org.apache.lucene.codecs.blockterms.VariableGapTermsIndexReader)3 BytesRef (org.apache.lucene.util.BytesRef)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 FieldsConsumer (org.apache.lucene.codecs.FieldsConsumer)2 FixedGapTermsIndexReader (org.apache.lucene.codecs.blockterms.FixedGapTermsIndexReader)2 BlockTreeTermsReader (org.apache.lucene.codecs.blocktree.BlockTreeTermsReader)2 Document (org.apache.lucene.document.Document)2 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)2 Map (java.util.Map)1 Random (java.util.Random)1 SortedMap (java.util.SortedMap)1