Search in sources :

Example 11 with FieldsProducer

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

the class RandomPostingsTester method testFull.

/** Indexes all fields/terms at the specified
   *  IndexOptions, and fully tests at that IndexOptions. */
public void testFull(Codec codec, Path path, IndexOptions options, boolean withPayloads) throws Exception {
    Directory dir = LuceneTestCase.newFSDirectory(path);
    // TODO test thread safety of buildIndex too
    FieldsProducer fieldsProducer = buildIndex(codec, dir, options, withPayloads, true);
    testFields(fieldsProducer);
    IndexOptions[] allOptions = IndexOptions.values();
    int maxIndexOption = Arrays.asList(allOptions).indexOf(options);
    for (int i = 0; i <= maxIndexOption; i++) {
        testTerms(fieldsProducer, EnumSet.allOf(Option.class), allOptions[i], options, true);
        if (withPayloads) {
            // If we indexed w/ payloads, also test enums w/o accessing payloads:
            testTerms(fieldsProducer, EnumSet.complementOf(EnumSet.of(Option.PAYLOADS)), allOptions[i], options, true);
        }
    }
    fieldsProducer.close();
    dir.close();
}
Also used : FieldsProducer(org.apache.lucene.codecs.FieldsProducer) Directory(org.apache.lucene.store.Directory)

Example 12 with FieldsProducer

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

the class BasePostingsFormatTestCase method testRandom.

public void testRandom() throws Exception {
    int iters = 5;
    for (int iter = 0; iter < iters; iter++) {
        Path path = createTempDir("testPostingsFormat");
        Directory dir = newFSDirectory(path);
        boolean indexPayloads = random().nextBoolean();
        // TODO test thread safety of buildIndex too
        FieldsProducer fieldsProducer = postingsTester.buildIndex(getCodec(), dir, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, indexPayloads, false);
        postingsTester.testFields(fieldsProducer);
        // NOTE: you can also test "weaker" index options than
        // you indexed with:
        postingsTester.testTerms(fieldsProducer, EnumSet.allOf(RandomPostingsTester.Option.class), IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, false);
        fieldsProducer.close();
        fieldsProducer = null;
        dir.close();
    }
}
Also used : Path(java.nio.file.Path) FieldsProducer(org.apache.lucene.codecs.FieldsProducer) Directory(org.apache.lucene.store.Directory)

Example 13 with FieldsProducer

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

the class LuceneVarGapDocFreqInterval 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 14 with FieldsProducer

use of org.apache.lucene.codecs.FieldsProducer 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 15 with FieldsProducer

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