Search in sources :

Example 6 with Lucene50PostingsReader

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

the class LuceneVarGapFixedInterval method fieldsProducer.

@Override
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
    PostingsReaderBase postings = new Lucene50PostingsReader(state);
    TermsIndexReaderBase indexReader;
    boolean success = false;
    try {
        indexReader = new VariableGapTermsIndexReader(state);
        success = true;
    } finally {
        if (!success) {
            postings.close();
        }
    }
    success = false;
    try {
        FieldsProducer ret = new BlockTermsReader(indexReader, postings, state);
        success = true;
        return ret;
    } finally {
        if (!success) {
            try {
                postings.close();
            } finally {
                indexReader.close();
            }
        }
    }
}
Also used : FieldsProducer(org.apache.lucene.codecs.FieldsProducer) PostingsReaderBase(org.apache.lucene.codecs.PostingsReaderBase) Lucene50PostingsReader(org.apache.lucene.codecs.lucene50.Lucene50PostingsReader) BlockTermsReader(org.apache.lucene.codecs.blockterms.BlockTermsReader) VariableGapTermsIndexReader(org.apache.lucene.codecs.blockterms.VariableGapTermsIndexReader) TermsIndexReaderBase(org.apache.lucene.codecs.blockterms.TermsIndexReaderBase)

Example 7 with Lucene50PostingsReader

use of org.apache.lucene.codecs.lucene50.Lucene50PostingsReader 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)

Aggregations

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