Search in sources :

Example 1 with NonUniqueIndexSampler

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

the class NonUniqueDatabaseIndexPopulatingUpdaterTest method changedNodePropertiesIncludedInSample.

@Test
public void changedNodePropertiesIncludedInSample() throws Exception {
    NonUniqueIndexSampler sampler = newSampler();
    NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater(sampler);
    updater.process(add(1, SCHEMA_DESCRIPTOR, "initial1"));
    updater.process(add(2, SCHEMA_DESCRIPTOR, "initial2"));
    updater.process(add(3, SCHEMA_DESCRIPTOR, "new2"));
    updater.process(change(1, SCHEMA_DESCRIPTOR, "initial1", "new1"));
    updater.process(change(1, SCHEMA_DESCRIPTOR, "initial2", "new2"));
    verifySamplingResult(sampler, 3, 2, 3);
}
Also used : NonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler) DefaultNonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler) Test(org.junit.Test)

Example 2 with NonUniqueIndexSampler

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

the class NonUniqueDatabaseIndexPopulatingUpdaterTest method changedNodeCompositePropertiesIncludedInSample.

@Test
public void changedNodeCompositePropertiesIncludedInSample() throws Exception {
    NonUniqueIndexSampler sampler = newSampler();
    NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater(sampler);
    updater.process(add(1, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "initial1"));
    updater.process(add(2, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "initial2"));
    updater.process(add(3, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "new2"));
    updater.process(change(1, COMPOSITE_SCHEMA_DESCRIPTOR, new Object[] { "bit", "initial1" }, new Object[] { "bit", "new1" }));
    updater.process(change(1, COMPOSITE_SCHEMA_DESCRIPTOR, new Object[] { "bit", "initial2" }, new Object[] { "bit", "new2" }));
    verifySamplingResult(sampler, 3, 2, 3);
}
Also used : NonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler) DefaultNonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler) Test(org.junit.Test)

Example 3 with NonUniqueIndexSampler

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

the class NonUniqueDatabaseIndexPopulatingUpdaterTest method addedNodePropertiesIncludedInSample.

@Test
public void addedNodePropertiesIncludedInSample() throws Exception {
    NonUniqueIndexSampler sampler = newSampler();
    NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater(sampler);
    updater.process(add(1, SCHEMA_DESCRIPTOR, "foo"));
    updater.process(add(2, SCHEMA_DESCRIPTOR, "bar"));
    updater.process(add(3, SCHEMA_DESCRIPTOR, "baz"));
    updater.process(add(4, SCHEMA_DESCRIPTOR, "bar"));
    verifySamplingResult(sampler, 4, 3, 4);
}
Also used : NonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler) DefaultNonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler) Test(org.junit.Test)

Example 4 with NonUniqueIndexSampler

use of org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler 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)

Example 5 with NonUniqueIndexSampler

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

the class NonUniqueDatabaseIndexPopulatingUpdaterTest method nodeCompositePropertyUpdatesIncludedInSample.

@Test
public void nodeCompositePropertyUpdatesIncludedInSample() throws Exception {
    NonUniqueIndexSampler sampler = newSampler();
    NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater(sampler);
    updater.process(add(1, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "foo"));
    updater.process(change(1, COMPOSITE_SCHEMA_DESCRIPTOR, new Object[] { "bit", "foo" }, new Object[] { "bit", "newFoo1" }));
    updater.process(add(2, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar"));
    updater.process(remove(2, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar"));
    updater.process(change(1, COMPOSITE_SCHEMA_DESCRIPTOR, new Object[] { "bit", "newFoo1" }, new Object[] { "bit", "newFoo2" }));
    updater.process(add(42, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "qux"));
    updater.process(add(3, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar"));
    updater.process(add(4, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "baz"));
    updater.process(add(5, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar"));
    updater.process(remove(42, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "qux"));
    verifySamplingResult(sampler, 4, 3, 4);
}
Also used : NonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler) DefaultNonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler) Test(org.junit.Test)

Aggregations

DefaultNonUniqueIndexSampler (org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler)9 NonUniqueIndexSampler (org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler)9 Test (org.junit.Test)8 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