use of org.neo4j.kernel.api.impl.schema.reader.SortedIndexReader in project neo4j-apoc-procedures by neo4j-contrib.
the class SchemaIndex method distinctTermsCount.
private Map<String, Integer> distinctTermsCount(@Name("label") String label, @Name("key") String key) {
try {
SortedIndexReader sortedIndexReader = getSortedIndexReader(label, key, 0, Sort.INDEXORDER);
Fields fields = MultiFields.getFields(sortedIndexReader.getIndexSearcher().getIndexReader());
Map<String, Integer> values = new HashMap<>();
TermsEnum termsEnum;
Terms terms = fields.terms("string");
if (terms != null) {
termsEnum = terms.iterator();
while ((termsEnum.next()) != null) {
values.put(termsEnum.term().utf8ToString(), termsEnum.docFreq());
}
}
return values;
} catch (Exception e) {
throw new RuntimeException("Error collecting distinct terms of label: " + label + " and key: " + key, e);
}
}
use of org.neo4j.kernel.api.impl.schema.reader.SortedIndexReader in project neo4j-apoc-procedures by neo4j-contrib.
the class SchemaIndex method orderedByText.
@Procedure
@Description("apoc.index.orderedByText(label,key,operator,value,sort-relevance,limit) yield node - schema string search which keeps index order and adds limit, operator is 'STARTS WITH' or 'CONTAINS'")
public Stream<NodeResult> orderedByText(@Name("label") String label, @Name("key") String key, @Name("operator") String operator, @Name("value") String value, @Name("relevance") boolean relevance, @Name("limit") long limit) throws SchemaRuleNotFoundException, IndexNotFoundKernelException, DuplicateSchemaRuleException {
SortedIndexReader sortedIndexReader = getSortedIndexReader(label, key, limit, getSort(value, value, relevance));
PrimitiveLongIterator it = queryForString(sortedIndexReader, operator, value);
return Util.toLongStream(it).mapToObj(id -> new NodeResult(db.getNodeById(id)));
}
use of org.neo4j.kernel.api.impl.schema.reader.SortedIndexReader 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