use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class LuceneQueryIntegrationTest method selectsFromMultipleNestedIndexes.
@Test
void selectsFromMultipleNestedIndexes() throws Exception {
useRewritePlanner = false;
try (FDBRecordContext context = openContext()) {
openRecordStore(context, metaData -> {
metaData.addIndex(TextIndexTestUtils.COMPLEX_DOC, new Index(nestedDualIndex.toProto()));
metaData.addIndex(TextIndexTestUtils.COMPLEX_DOC, new Index(nestedDualIndex2.toProto()));
});
setupPlanner(null);
QueryComponent filter = new LuceneQueryComponent("text2:test", Arrays.asList("text2"));
RecordQuery rq = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.COMPLEX_DOC).setFilter(filter).build();
final RecordQueryPlan plan = planner.plan(rq);
Set<String> appliedIndexNames = plan.getUsedIndexes();
Assertions.assertEquals(1, appliedIndexNames.size(), "index selection is incorrect");
Assertions.assertTrue(appliedIndexNames.contains(nestedDualIndex2.getName()), "Did not select the correct index");
}
}
use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class LuceneQueryIntegrationTest method selectsFromMultipleIndexes.
@Test
void selectsFromMultipleIndexes() throws Exception {
useRewritePlanner = false;
try (FDBRecordContext context = openContext()) {
openRecordStore(context, metaData -> {
metaData.addIndex(TextIndexTestUtils.COMPLEX_DOC, textIndex);
metaData.addIndex(TextIndexTestUtils.COMPLEX_DOC, text2Index);
});
setupPlanner(null);
QueryComponent filter = new LuceneQueryComponent("text2:test", Arrays.asList("text2"));
RecordQuery rq = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.COMPLEX_DOC).setFilter(filter).build();
final RecordQueryPlan plan = planner.plan(rq);
Set<String> appliedIndexNames = plan.getUsedIndexes();
Assertions.assertEquals(1, appliedIndexNames.size(), "index selection is incorrect");
Assertions.assertTrue(appliedIndexNames.contains(text2Index.getName()), "Did not select the correct index");
}
}
use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method threadedLuceneScanDoesntBreakPlannerAndSearch.
@Test
public void threadedLuceneScanDoesntBreakPlannerAndSearch() throws Exception {
initializeFlat();
CountingThreadFactory threadFactory = new CountingThreadFactory();
executorService = Executors.newFixedThreadPool(10, threadFactory);
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("*:*", Lists.newArrayList("text"), false);
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(filter1).build();
setDeferFetchAfterUnionAndIntersection(false);
RecordQueryPlan plan = planner.plan(query);
List<Long> primaryKeys = recordStore.executeQuery(plan).map(FDBQueriedRecord::getPrimaryKey).map(t -> t.getLong(0)).asList().get();
assertThat(threadFactory.threadCounts, aMapWithSize(greaterThan(0)));
}
}
use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method delayFetchOnOrOfLuceneScanWithFieldFilter.
@ParameterizedTest
@BooleanSource
public void delayFetchOnOrOfLuceneScanWithFieldFilter(boolean shouldDeferFetch) throws Exception {
initializeFlat();
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter1 = new LuceneQueryComponent("civil blood makes civil hands unclean", Lists.newArrayList("text"));
// Query for full records
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(Query.or(filter1, Query.field("doc_id").lessThan(10000L))).build();
setDeferFetchAfterUnionAndIntersection(shouldDeferFetch);
RecordQueryPlan plan = planner.plan(query);
Matcher<RecordQueryPlan> matcher = primaryKeyDistinct(unorderedUnion(indexScan(allOf(indexScan("Complex$text_index"), indexScanType(IndexScanType.BY_LUCENE), bounds(hasTupleString("[[civil blood makes civil hands unclean],[civil blood makes civil hands unclean]]")))), typeFilter(equalTo(Collections.singleton(TextIndexTestUtils.SIMPLE_DOC)), scan(bounds(hasTupleString("([null],[10000])"))))));
assertThat(plan, matcher);
List<Long> primaryKeys = recordStore.executeQuery(plan).map(FDBQueriedRecord::getPrimaryKey).map(t -> t.getLong(0)).asList().get();
assertEquals(ImmutableSet.of(2L, 4L, 0L, 1L, 3L, 5L), ImmutableSet.copyOf(primaryKeys));
if (shouldDeferFetch) {
assertLoadRecord(5, context);
} else {
assertLoadRecord(6, context);
}
}
}
use of com.apple.foundationdb.record.query.expressions.LuceneQueryComponent in project fdb-record-layer by FoundationDB.
the class FDBLuceneQueryTest method assertTermIndexedOrNot.
private void assertTermIndexedOrNot(String term, boolean indexedExpected, boolean shouldDeferFetch) throws Exception {
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
final QueryComponent filter = new LuceneQueryComponent(term, Lists.newArrayList());
// Query for full records
RecordQuery query = RecordQuery.newBuilder().setRecordType(TextIndexTestUtils.SIMPLE_DOC).setFilter(filter).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();
if (indexedExpected) {
assertEquals(ImmutableSet.of(1L), ImmutableSet.copyOf(primaryKeys), "Expected term not indexed");
} else {
assertThat("Unexpected term indexed", primaryKeys.isEmpty());
}
}
}
Aggregations