Search in sources :

Example 1 with DefaultNonUniqueIndexSampler

use of org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler in project neo4j by neo4j.

the class NonUniqueLuceneIndexSampler method performSampling.

@Override
protected IndexSample performSampling() throws IndexNotFoundKernelException {
    NonUniqueIndexSampler sampler = new DefaultNonUniqueIndexSampler(indexSamplingConfig.sampleSizeLimit());
    IndexReader indexReader = indexSearcher.getIndexReader();
    for (LeafReaderContext readerContext : indexReader.leaves()) {
        try {
            Set<String> fieldNames = getFieldNamesToSample(readerContext);
            for (String fieldName : fieldNames) {
                Terms terms = readerContext.reader().terms(fieldName);
                if (terms != null) {
                    TermsEnum termsEnum = LuceneDocumentStructure.originalTerms(terms, fieldName);
                    BytesRef termsRef;
                    while ((termsRef = termsEnum.next()) != null) {
                        sampler.include(termsRef.utf8ToString(), termsEnum.docFreq());
                        checkCancellation();
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return sampler.result(indexReader.numDocs());
}
Also used : DefaultNonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler) NonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler) DefaultNonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler) IndexReader(org.apache.lucene.index.IndexReader) Terms(org.apache.lucene.index.Terms) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) IOException(java.io.IOException) BytesRef(org.apache.lucene.util.BytesRef) TermsEnum(org.apache.lucene.index.TermsEnum)

Aggregations

IOException (java.io.IOException)1 IndexReader (org.apache.lucene.index.IndexReader)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Terms (org.apache.lucene.index.Terms)1 TermsEnum (org.apache.lucene.index.TermsEnum)1 BytesRef (org.apache.lucene.util.BytesRef)1 DefaultNonUniqueIndexSampler (org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler)1 NonUniqueIndexSampler (org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler)1