use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method delayFetchOnLuceneComplexStringOr.
@ParameterizedTest
@BooleanSource
public void delayFetchOnLuceneComplexStringOr(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("the continuance OR grudge", Lists.newArrayList());
// Query for full records
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(filter1).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
RecordQueryPlan plan = planner.plan(query);
Matcher<RecordQueryPlan> matcher = indexScan(allOf(indexScanType(IndexScanType.BY_LUCENE_FULL_TEXT), indexName("Complex$text_index"), bounds(hasTupleString("[[the continuance OR grudge],[the continuance OR grudge]]"))));
assertThat(plan, matcher);
List<Long> primaryKeys = recordStore.executeQuery(plan).map(FDBQueriedRecord::getPrimaryKey).map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(4L, 5L, 2L), ImmutableSet.copyOf(primaryKeys));
if (shouldDeferFetch) {
assertLoadRecord(3, context);
} else {
assertLoadRecord(4, context);
}
}
}
use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method simpleLuceneScans.
@ParameterizedTest
@BooleanSource
public void simpleLuceneScans(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("civil blood makes civil hands unclean", Lists.newArrayList());
// Query for full records
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(filter1).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
Matcher<RecordQueryPlan> matcher = indexScan(allOf(indexScan("Complex$text_index"), indexScanType(IndexScanType.BY_LUCENE), bounds(hasTupleString("[[civil blood makes civil hands unclean],[civil blood makes civil hands unclean]]"))));
RecordQueryPlan plan = planner.plan(query);
// assertThat(plan, matcher);
RecordCursor<FDBQueriedRecord<Message>> fdbQueriedRecordRecordCursor = recordStore.executeQuery(plan);
RecordCursor<Tuple> map = fdbQueriedRecordRecordCursor.map(FDBQueriedRecord::getPrimaryKey);
List<Long> primaryKeys = map.map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(2L, 4L), ImmutableSet.copyOf(primaryKeys));
}
}
use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method testThenExpressionBeforeFieldExpression.
@ParameterizedTest
@BooleanSource
public void testThenExpressionBeforeFieldExpression(boolean shouldDeferFetch) throws Exception {
initializeNestedWithField();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("*:*", Lists.newArrayList("doc_id"));
RecordQuery query = RecordQuery.newBuilder().setRecordType(MAP_DOC).setFilter(filter1).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
RecordQueryPlan plan = planner.plan(query);
RecordCursor<FDBQueriedRecord<Message>> fdbQueriedRecordRecordCursor = recordStore.executeQuery(plan);
RecordCursor<Tuple> map = fdbQueriedRecordRecordCursor.map(FDBQueriedRecord::getPrimaryKey);
List<Long> primaryKeys = map.map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(0L, 1L, 2L), ImmutableSet.copyOf(primaryKeys));
}
}
use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method misMatchQueryShouldReturnNoResult.
@ParameterizedTest
@BooleanSource
public void misMatchQueryShouldReturnNoResult(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("doesNotExist", Lists.newArrayList("text"), true);
// Query for full records
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(filter1).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
RecordQueryPlan plan = planner.plan(query);
Matcher<RecordQueryPlan> matcher = indexScan(allOf(indexScan("Complex$text_index"), indexScanType(IndexScanType.BY_LUCENE_FULL_TEXT), bounds(hasTupleString("[[doesNotExist],[doesNotExist]]"))));
assertThat(plan, matcher);
List<Long> primaryKeys = recordStore.executeQuery(plan).map(FDBQueriedRecord::getPrimaryKey).map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(), ImmutableSet.copyOf(primaryKeys));
if (shouldDeferFetch) {
assertLoadRecord(3, context);
} else {
assertLoadRecord(4, context);
}
}
}
use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method delayFetchOnAndOfLuceneAndFieldFilter.
@ParameterizedTest
@BooleanSource
public void delayFetchOnAndOfLuceneAndFieldFilter(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("civil blood makes civil hands unclean", Lists.newArrayList());
// Query for full records
QueryComponent filter2 = Query.field("doc_id").equalsValue(2L);
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(Query.and(filter2, filter1)).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
RecordQueryPlan plan = planner.plan(query);
Matcher<RecordQueryPlan> scanMatcher = fetch(filter(filter2, coveringIndexScan(indexScan(allOf(indexScanType(IndexScanType.BY_LUCENE_FULL_TEXT), indexScan("Complex$text_index"), bounds(hasTupleString("[[civil blood makes civil hands unclean],[civil blood makes civil hands unclean]]")))))));
assertThat(plan, scanMatcher);
RecordCursor<FDBQueriedRecord<Message>> primaryKeys;
primaryKeys = recordStore.executeQuery(plan);
final List<Long> keys = primaryKeys.map(FDBQueriedRecord::getPrimaryKey).map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(2L), ImmutableSet.copyOf(keys));
if (shouldDeferFetch) {
assertLoadRecord(3, context);
} else {
assertLoadRecord(4, context);
}
}
}
Aggregations