use of org.neo4j.kernel.api.impl.schema.reader.SimpleIndexReader 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;
}
}
use of org.neo4j.kernel.api.impl.schema.reader.SimpleIndexReader in project neo4j-apoc-procedures by neo4j-contrib.
the class SchemaIndex method distinctTerms.
private List<Object> distinctTerms(@Name("label") String label, @Name("key") String key) throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IOException, DuplicateSchemaRuleException {
SimpleIndexReader reader = getLuceneIndexReader(label, key);
SortedIndexReader sortedIndexReader = new SortedIndexReader(reader, 0, Sort.INDEXORDER);
Set<Object> values = new LinkedHashSet<>(100);
TermsEnum termsEnum;
Fields fields = MultiFields.getFields(sortedIndexReader.getIndexSearcher().getIndexReader());
Terms terms = fields.terms("string");
if (terms != null) {
termsEnum = terms.iterator();
while ((termsEnum.next()) != null) {
values.add(termsEnum.term().utf8ToString());
}
}
return new ArrayList<>(values);
}
Aggregations