use of org.neo4j.internal.kernel.api.IndexQueryConstraints in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldPerformNumericRangeSearch.
@Test
void shouldPerformNumericRangeSearch() throws Exception {
// given
boolean needsValues = indexParams.indexProvidesNumericValues();
IndexQueryConstraints constraints = unordered(needsValues);
int prop = token.propertyKey(PROP_NAME);
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
IndexValueCapability numberCapability = index.reference().getCapability().valueCapability(ValueCategory.NUMBER);
try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
MutableLongSet uniqueIds = new LongHashSet();
// when
entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.range(prop, 5, true, 12, true));
// then
assertFoundEntitiesAndValue(cursor, uniqueIds, numberCapability, needsValues, num5, num6, num12a, num12b);
// when
entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.range(prop, 5, true, 12, false));
// then
assertFoundEntitiesAndValue(cursor, uniqueIds, numberCapability, needsValues, num5, num6);
// when
entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.range(prop, 5, false, 12, true));
// then
assertFoundEntitiesAndValue(cursor, uniqueIds, numberCapability, needsValues, num6, num12a, num12b);
// when
entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.range(prop, 5, false, 12, false));
// then
assertFoundEntitiesAndValue(cursor, uniqueIds, numberCapability, needsValues, num6);
}
}
use of org.neo4j.internal.kernel.api.IndexQueryConstraints in project neo4j by neo4j.
the class FulltextIndexProgressorTest method mustSkipAndLimitEntriesPerConstraints.
@Test
void mustSkipAndLimitEntriesPerConstraints() {
StubValuesIterator iterator = new StubValuesIterator();
iterator.add(1, 1.0f);
iterator.add(2, 2.0f);
iterator.add(3, 3.0f);
iterator.add(4, 4.0f);
IndexQueryConstraints constraints = unconstrained().skip(1).limit(2);
StubEntityValueClient client = new StubEntityValueClient();
FulltextIndexProgressor progressor = new FulltextIndexProgressor(iterator, client, constraints);
boolean keepGoing;
do {
keepGoing = progressor.next();
} while (keepGoing);
assertThat(client.entityIds).containsExactly(2L, 3L);
assertThat(client.scores).containsExactly(2.0f, 3.0f);
}
use of org.neo4j.internal.kernel.api.IndexQueryConstraints in project neo4j by neo4j.
the class FulltextProcedures method queryConstraints.
protected static IndexQueryConstraints queryConstraints(Map<String, Object> options) {
IndexQueryConstraints constraints = unconstrained();
Object skip;
if ((skip = options.get("skip")) != null && skip instanceof Number) {
constraints = constraints.skip(((Number) skip).longValue());
}
Object limit;
if ((limit = options.get("limit")) != null && limit instanceof Number) {
constraints = constraints.limit(((Number) limit).longValue());
}
return constraints;
}
use of org.neo4j.internal.kernel.api.IndexQueryConstraints in project neo4j by neo4j.
the class FulltextProcedures method queryFulltextForNodes.
@SystemProcedure
@Description("Query the given full-text index. Returns the matching nodes, and their Lucene query score, ordered by score. " + "Valid keys for the options map are: 'skip' to skip the top N results; 'limit' to limit the number of results returned.")
@Procedure(name = "db.index.fulltext.queryNodes", mode = READ)
public Stream<NodeOutput> queryFulltextForNodes(@Name("indexName") String name, @Name("queryString") String query, @Name(value = "options", defaultValue = "{}") Map<String, Object> options) throws Exception {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
IndexDescriptor indexReference = getValidIndex(name);
awaitOnline(indexReference);
EntityType entityType = indexReference.schema().entityType();
if (entityType != NODE) {
throw new IllegalArgumentException("The '" + name + "' index (" + indexReference + ") is an index on " + entityType + ", so it cannot be queried for nodes.");
}
NodeValueIndexCursor cursor = tx.cursors().allocateNodeValueIndexCursor(tx.cursorContext(), tx.memoryTracker());
IndexReadSession indexSession = tx.dataRead().indexReadSession(indexReference);
IndexQueryConstraints constraints = queryConstraints(options);
tx.dataRead().nodeIndexSeek(indexSession, cursor, constraints, PropertyIndexQuery.fulltextSearch(query));
Spliterator<NodeOutput> spliterator = new SpliteratorAdaptor<>() {
@Override
public boolean tryAdvance(Consumer<? super NodeOutput> action) {
while (cursor.next()) {
long nodeReference = cursor.nodeReference();
float score = cursor.score();
NodeOutput nodeOutput = NodeOutput.forExistingEntityOrNull(transaction, nodeReference, score);
if (nodeOutput != null) {
action.accept(nodeOutput);
return true;
}
}
cursor.close();
return false;
}
};
Stream<NodeOutput> stream = StreamSupport.stream(spliterator, false);
return stream.onClose(cursor::close);
}
use of org.neo4j.internal.kernel.api.IndexQueryConstraints in project neo4j by neo4j.
the class TokenIndexAccessorTest method assertReaderFindsExpected.
private static void assertReaderFindsExpected(TokenIndexReader reader, IndexOrder indexOrder, long tokenId, LongList expectedIds, ThrowingConsumer<TokenIndexReader, Exception> innerCalling) throws Exception {
if (indexOrder.equals(IndexOrder.DESCENDING)) {
expectedIds = expectedIds.toReversed();
}
try (CollectingEntityTokenClient collectingEntityTokenClient = new CollectingEntityTokenClient(tokenId)) {
IndexQueryConstraints constraint = IndexQueryConstraints.constrained(indexOrder, false);
TokenPredicate query = new TokenPredicate((int) tokenId);
reader.query(collectingEntityTokenClient, constraint, query, NULL);
// Then
int count = 0;
while (collectingEntityTokenClient.next()) {
innerCalling.accept(reader);
count++;
}
assertThat(count).isEqualTo(expectedIds.size());
assertThat(collectingEntityTokenClient.actualIds).isEqualTo(expectedIds);
}
}
Aggregations