Search in sources :

Example 1 with CollectionSearchAttributeFilter

use of io.lumeer.storage.api.filter.CollectionSearchAttributeFilter in project engine by Lumeer.

the class MongoDataDaoTest method testSearchDataByAllConditions.

@Test
public void testSearchDataByAllConditions() {
    Collection collection = collectionDao.getCollectionById(COLLECTION_ID);
    String id1 = createDocument(KEY1, "lumeerko");
    String id2 = createDocument(KEY2, "something lala");
    String id3 = createDocument(KEY3, "lol nieco");
    String id4 = createDocument(KEY2, "lumeerko");
    CollectionSearchAttributeFilter filter = new CollectionSearchAttributeFilter(COLLECTION_ID, ConditionType.EQUALS, KEY1, "lumeerko");
    SearchQueryStem stem = SearchQueryStem.createBuilder(COLLECTION_ID).filters(Collections.singleton(filter)).documentIds(new HashSet<>(Arrays.asList(id1, id2, id3, id4))).fulltexts(Collections.singleton("full")).build();
    List<DataDocument> data = dataDao.searchData(stem, null, collection);
    assertThat(data).extracting(DataDocument::getId).containsOnly(id1);
    filter = new CollectionSearchAttributeFilter(COLLECTION_ID, ConditionType.EQUALS, KEY2, "lumeerko");
    stem = SearchQueryStem.createBuilder(COLLECTION_ID).filters(Collections.singleton(filter)).documentIds(new HashSet<>(Arrays.asList(id1, id2, id3))).fulltexts(new HashSet<>(Arrays.asList("erko", "lumee"))).build();
    data = dataDao.searchData(stem, null, collection);
    assertThat(data).extracting(DataDocument::getId).isEmpty();
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) SearchQueryStem(io.lumeer.storage.api.query.SearchQueryStem) CollectionSearchAttributeFilter(io.lumeer.storage.api.filter.CollectionSearchAttributeFilter) MongoCollection(com.mongodb.client.MongoCollection) Collection(io.lumeer.api.model.Collection) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with CollectionSearchAttributeFilter

use of io.lumeer.storage.api.filter.CollectionSearchAttributeFilter in project engine by Lumeer.

the class MongoDataDaoTest method testSearchDataByFilters.

@Test
public void testSearchDataByFilters() {
    Collection collection = collectionDao.getCollectionById(COLLECTION_ID);
    String id1 = createDocument(KEY1, "4");
    createDocument(KEY1, "8");
    createDocument(KEY1, "13");
    String id4 = createDocument(KEY1, "mama");
    CollectionSearchAttributeFilter filter = new CollectionSearchAttributeFilter(COLLECTION_ID, ConditionType.EQUALS, KEY1, "4");
    SearchQueryStem stem = SearchQueryStem.createBuilder(COLLECTION_ID).filters(Collections.singleton(filter)).build();
    List<DataDocument> data = dataDao.searchData(stem, null, collection);
    assertThat(data).extracting(DataDocument::getId).containsOnly(id1);
    filter = new CollectionSearchAttributeFilter(COLLECTION_ID, ConditionType.EQUALS, KEY1, "mama");
    stem = SearchQueryStem.createBuilder(COLLECTION_ID).filters(Collections.singleton(filter)).build();
    data = dataDao.searchData(stem, null, collection);
    assertThat(data).extracting(DataDocument::getId).containsOnly(id4);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) SearchQueryStem(io.lumeer.storage.api.query.SearchQueryStem) CollectionSearchAttributeFilter(io.lumeer.storage.api.filter.CollectionSearchAttributeFilter) MongoCollection(com.mongodb.client.MongoCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Aggregations

MongoCollection (com.mongodb.client.MongoCollection)2 Collection (io.lumeer.api.model.Collection)2 DataDocument (io.lumeer.engine.api.data.DataDocument)2 CollectionSearchAttributeFilter (io.lumeer.storage.api.filter.CollectionSearchAttributeFilter)2 SearchQueryStem (io.lumeer.storage.api.query.SearchQueryStem)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1