Search in sources :

Example 1 with BlockTreeTermsReader

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

the class MockRandomPostingsFormat method fieldsProducer.

@Override
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
    final String seedFileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, SEED_EXT);
    final ChecksumIndexInput in = state.directory.openChecksumInput(seedFileName, state.context);
    CodecUtil.checkIndexHeader(in, "MockRandomSeed", 0, 0, state.segmentInfo.getId(), state.segmentSuffix);
    final long seed = in.readLong();
    CodecUtil.checkFooter(in);
    if (LuceneTestCase.VERBOSE) {
        System.out.println("MockRandomCodec: reading from seg=" + state.segmentInfo.name + " formatID=" + state.segmentSuffix + " seed=" + seed);
    }
    in.close();
    final Random random = new Random(seed);
    int readBufferSize = TestUtil.nextInt(random, 1, 4096);
    if (LuceneTestCase.VERBOSE) {
        System.out.println("MockRandomCodec: readBufferSize=" + readBufferSize);
    }
    PostingsReaderBase postingsReader = new Lucene50PostingsReader(state);
    final FieldsProducer fields;
    final int t1 = random.nextInt(5);
    if (t1 == 0) {
        boolean success = false;
        try {
            fields = new FSTTermsReader(state, postingsReader);
            success = true;
        } finally {
            if (!success) {
                postingsReader.close();
            }
        }
    } else if (t1 == 1) {
        boolean success = false;
        try {
            fields = new FSTOrdTermsReader(state, postingsReader);
            success = true;
        } finally {
            if (!success) {
                postingsReader.close();
            }
        }
    } else if (t1 == 2) {
        // Use BlockTree terms dict
        if (LuceneTestCase.VERBOSE) {
            System.out.println("MockRandomCodec: reading BlockTree terms dict");
        }
        boolean success = false;
        try {
            fields = new BlockTreeTermsReader(postingsReader, state);
            success = true;
        } finally {
            if (!success) {
                postingsReader.close();
            }
        }
    } else if (t1 == 3) {
        if (LuceneTestCase.VERBOSE) {
            System.out.println("MockRandomCodec: reading Block terms dict");
        }
        final TermsIndexReaderBase indexReader;
        boolean success = false;
        try {
            final boolean doFixedGap = random.nextBoolean();
            if (doFixedGap) {
                if (LuceneTestCase.VERBOSE) {
                    System.out.println("MockRandomCodec: fixed-gap terms index");
                }
                indexReader = new FixedGapTermsIndexReader(state);
            } else {
                final int n2 = random.nextInt(3);
                if (n2 == 1) {
                    random.nextInt();
                } else if (n2 == 2) {
                    random.nextLong();
                }
                if (LuceneTestCase.VERBOSE) {
                    System.out.println("MockRandomCodec: variable-gap terms index");
                }
                indexReader = new VariableGapTermsIndexReader(state);
            }
            success = true;
        } finally {
            if (!success) {
                postingsReader.close();
            }
        }
        success = false;
        try {
            fields = new BlockTermsReader(indexReader, postingsReader, state);
            success = true;
        } finally {
            if (!success) {
                try {
                    postingsReader.close();
                } finally {
                    indexReader.close();
                }
            }
        }
    } else if (t1 == 4) {
        // Use OrdsBlockTree terms dict
        if (LuceneTestCase.VERBOSE) {
            System.out.println("MockRandomCodec: reading OrdsBlockTree terms dict");
        }
        boolean success = false;
        try {
            fields = new OrdsBlockTreeTermsReader(postingsReader, state);
            success = true;
        } finally {
            if (!success) {
                postingsReader.close();
            }
        }
    } else {
        // BUG!
        throw new AssertionError();
    }
    return fields;
}
Also used : ChecksumIndexInput(org.apache.lucene.store.ChecksumIndexInput) FieldsProducer(org.apache.lucene.codecs.FieldsProducer) FixedGapTermsIndexReader(org.apache.lucene.codecs.blockterms.FixedGapTermsIndexReader) Lucene50PostingsReader(org.apache.lucene.codecs.lucene50.Lucene50PostingsReader) BlockTermsReader(org.apache.lucene.codecs.blockterms.BlockTermsReader) VariableGapTermsIndexReader(org.apache.lucene.codecs.blockterms.VariableGapTermsIndexReader) FSTOrdTermsReader(org.apache.lucene.codecs.memory.FSTOrdTermsReader) Random(java.util.Random) PostingsReaderBase(org.apache.lucene.codecs.PostingsReaderBase) OrdsBlockTreeTermsReader(org.apache.lucene.codecs.blocktreeords.OrdsBlockTreeTermsReader) FSTTermsReader(org.apache.lucene.codecs.memory.FSTTermsReader) BlockTreeTermsReader(org.apache.lucene.codecs.blocktree.BlockTreeTermsReader) OrdsBlockTreeTermsReader(org.apache.lucene.codecs.blocktreeords.OrdsBlockTreeTermsReader) TermsIndexReaderBase(org.apache.lucene.codecs.blockterms.TermsIndexReaderBase)

Example 2 with BlockTreeTermsReader

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

the class Lucene50PostingsFormat method fieldsProducer.

@Override
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
    PostingsReaderBase postingsReader = new Lucene50PostingsReader(state);
    boolean success = false;
    try {
        FieldsProducer ret = new BlockTreeTermsReader(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) BlockTreeTermsReader(org.apache.lucene.codecs.blocktree.BlockTreeTermsReader)

Aggregations

FieldsProducer (org.apache.lucene.codecs.FieldsProducer)2 PostingsReaderBase (org.apache.lucene.codecs.PostingsReaderBase)2 BlockTreeTermsReader (org.apache.lucene.codecs.blocktree.BlockTreeTermsReader)2 Random (java.util.Random)1 BlockTermsReader (org.apache.lucene.codecs.blockterms.BlockTermsReader)1 FixedGapTermsIndexReader (org.apache.lucene.codecs.blockterms.FixedGapTermsIndexReader)1 TermsIndexReaderBase (org.apache.lucene.codecs.blockterms.TermsIndexReaderBase)1 VariableGapTermsIndexReader (org.apache.lucene.codecs.blockterms.VariableGapTermsIndexReader)1 OrdsBlockTreeTermsReader (org.apache.lucene.codecs.blocktreeords.OrdsBlockTreeTermsReader)1 Lucene50PostingsReader (org.apache.lucene.codecs.lucene50.Lucene50PostingsReader)1 FSTOrdTermsReader (org.apache.lucene.codecs.memory.FSTOrdTermsReader)1 FSTTermsReader (org.apache.lucene.codecs.memory.FSTTermsReader)1 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)1