Search in sources :

Example 1 with LuceneQueryComponent

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");
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Index(com.apple.foundationdb.record.metadata.Index) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Test(org.junit.jupiter.api.Test)

Example 2 with LuceneQueryComponent

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");
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Test(org.junit.jupiter.api.Test)

Example 3 with LuceneQueryComponent

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)));
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with LuceneQueryComponent

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);
        }
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 5 with LuceneQueryComponent

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());
        }
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) LuceneQueryComponent(com.apple.foundationdb.record.query.expressions.LuceneQueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Tuple(com.apple.foundationdb.tuple.Tuple)

Aggregations

FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)14 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)14 LuceneQueryComponent (com.apple.foundationdb.record.query.expressions.LuceneQueryComponent)14 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)14 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 BooleanSource (com.apple.test.BooleanSource)10 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)4 Tuple (com.apple.foundationdb.tuple.Tuple)3 Test (org.junit.jupiter.api.Test)3 Index (com.apple.foundationdb.record.metadata.Index)1