Search in sources :

Example 1 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema.LabelSchemaDescriptor in project neo4j-apoc-procedures by neo4j-contrib.

the class SchemaIndex method getLuceneIndexReader.

private SimpleIndexReader getLuceneIndexReader(String label, String key) throws SchemaRuleNotFoundException, IndexNotFoundKernelException, DuplicateSchemaRuleException {
    try (KernelStatement stmt = (KernelStatement) tx.acquireStatement()) {
        ReadOperations reads = stmt.readOperations();
        LabelSchemaDescriptor labelSchemaDescriptor = new LabelSchemaDescriptor(reads.labelGetForName(label), reads.propertyKeyGetForName(key));
        IndexDescriptor descriptor = reads.indexGetForSchema(labelSchemaDescriptor);
        IndexReader indexReader = stmt.getStoreStatement().getIndexReader(descriptor);
        if (indexReader.getClass().getName().endsWith("FusionIndexReader")) {
            try {
                Field field = indexReader.getClass().getDeclaredField("luceneReader");
                field.setAccessible(true);
                return (SimpleIndexReader) field.get(indexReader);
            } catch (IllegalAccessException | NoSuchFieldException e) {
                throw new RuntimeException("Error accessing index reader", e);
            }
        }
        return (SimpleIndexReader) indexReader;
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Field(java.lang.reflect.Field) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) SimpleIndexReader(org.neo4j.kernel.api.impl.schema.reader.SimpleIndexReader) SimpleIndexReader(org.neo4j.kernel.api.impl.schema.reader.SimpleIndexReader) SortedIndexReader(org.neo4j.kernel.api.impl.schema.reader.SortedIndexReader) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) LabelSchemaDescriptor(org.neo4j.kernel.api.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.kernel.api.schema.index.IndexDescriptor)

Aggregations

Field (java.lang.reflect.Field)1 ReadOperations (org.neo4j.kernel.api.ReadOperations)1 SimpleIndexReader (org.neo4j.kernel.api.impl.schema.reader.SimpleIndexReader)1 SortedIndexReader (org.neo4j.kernel.api.impl.schema.reader.SortedIndexReader)1 LabelSchemaDescriptor (org.neo4j.kernel.api.schema.LabelSchemaDescriptor)1 IndexDescriptor (org.neo4j.kernel.api.schema.index.IndexDescriptor)1 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)1 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)1