Search in sources :

Example 1 with FieldsProducer

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

the class TestCodecs method testFixedPostings.

public void testFixedPostings() throws Throwable {
    final int NUM_TERMS = 100;
    final TermData[] terms = new TermData[NUM_TERMS];
    for (int i = 0; i < NUM_TERMS; i++) {
        final int[] docs = new int[] { i };
        final String text = Integer.toString(i, Character.MAX_RADIX);
        terms[i] = new TermData(text, docs, null);
    }
    final FieldInfos.Builder builder = new FieldInfos.Builder();
    final FieldData field = new FieldData("field", builder, terms, true, false);
    final FieldData[] fields = new FieldData[] { field };
    final FieldInfos fieldInfos = builder.finish();
    final Directory dir = newDirectory();
    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);
    final FieldsProducer reader = codec.postingsFormat().fieldsProducer(new SegmentReadState(dir, si, fieldInfos, newIOContext(random())));
    final Iterator<String> fieldsEnum = reader.iterator();
    String fieldName = fieldsEnum.next();
    assertNotNull(fieldName);
    final Terms terms2 = reader.terms(fieldName);
    assertNotNull(terms2);
    final TermsEnum termsEnum = terms2.iterator();
    PostingsEnum postingsEnum = null;
    for (int i = 0; i < NUM_TERMS; i++) {
        final BytesRef term = termsEnum.next();
        assertNotNull(term);
        assertEquals(terms[i].text2, term.utf8ToString());
        // internal state:
        for (int iter = 0; iter < 2; iter++) {
            postingsEnum = TestUtil.docs(random(), termsEnum, postingsEnum, PostingsEnum.NONE);
            assertEquals(terms[i].docs[0], postingsEnum.nextDoc());
            assertEquals(DocIdSetIterator.NO_MORE_DOCS, postingsEnum.nextDoc());
        }
    }
    assertNull(termsEnum.next());
    for (int i = 0; i < NUM_TERMS; i++) {
        assertEquals(termsEnum.seekCeil(new BytesRef(terms[i].text2)), TermsEnum.SeekStatus.FOUND);
    }
    assertFalse(fieldsEnum.hasNext());
    reader.close();
    dir.close();
}
Also used : FieldsProducer(org.apache.lucene.codecs.FieldsProducer) Codec(org.apache.lucene.codecs.Codec) BytesRef(org.apache.lucene.util.BytesRef) Directory(org.apache.lucene.store.Directory)

Example 2 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 3 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 4 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 5 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)

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