Search in sources :

Example 1 with SearchQueryStem

use of io.lumeer.storage.api.query.SearchQueryStem 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 SearchQueryStem

use of io.lumeer.storage.api.query.SearchQueryStem 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)

Example 3 with SearchQueryStem

use of io.lumeer.storage.api.query.SearchQueryStem in project engine by Lumeer.

the class MongoDataDaoTest method testSearchDataByDocumenstIds.

@Test
public void testSearchDataByDocumenstIds() {
    Collection collection = collectionDao.getCollectionById(COLLECTION_ID);
    String id1 = createDocument(KEY1, VALUE1);
    String id2 = createDocument(KEY1, VALUE2);
    String id3 = createDocument(KEY1, VALUE1);
    String id4 = createDocument(KEY1, VALUE2);
    SearchQueryStem stem = SearchQueryStem.createBuilder(COLLECTION_ID).documentIds(Collections.singleton(id2)).build();
    List<DataDocument> data = dataDao.searchData(stem, null, collection);
    assertThat(data).extracting(DataDocument::getId).containsOnly(id2);
    SearchQueryStem stem2 = SearchQueryStem.createBuilder(COLLECTION_ID).documentIds(new HashSet<>(Arrays.asList(id1, id3, id4))).build();
    data = dataDao.searchData(stem2, null, collection);
    assertThat(data).extracting(DataDocument::getId).containsOnly(id1, id3, id4);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) SearchQueryStem(io.lumeer.storage.api.query.SearchQueryStem) MongoCollection(com.mongodb.client.MongoCollection) Collection(io.lumeer.api.model.Collection) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with SearchQueryStem

use of io.lumeer.storage.api.query.SearchQueryStem in project engine by Lumeer.

the class MongoLinkInstanceDaoTest method testGetLinkInstancesByLinkTypeIds.

@Test
public void testGetLinkInstancesByLinkTypeIds() {
    String id1 = linkInstanceDao.createLinkInstance(prepareLinkInstance()).getId();
    LinkInstance linkInstance2 = prepareLinkInstance();
    linkInstance2.setLinkTypeId(LINK_TYPE_ID2);
    String id2 = linkInstanceDao.createLinkInstance(linkInstance2).getId();
    LinkInstance linkInstance3 = prepareLinkInstance();
    linkInstance3.setLinkTypeId(LINK_TYPE_ID2);
    String id3 = linkInstanceDao.createLinkInstance(linkInstance3).getId();
    LinkInstance linkInstance4 = prepareLinkInstance();
    linkInstance4.setLinkTypeId(LINK_TYPE_ID3);
    String id4 = linkInstanceDao.createLinkInstance(linkInstance4).getId();
    SearchQueryStem stem1 = SearchQueryStem.createBuilder("Collection").linkTypeIds(Arrays.asList(LINK_TYPE_ID1, LINK_TYPE_ID2)).build();
    SearchQuery query1 = SearchQuery.createBuilder(USER).stems(Collections.singletonList(stem1)).build();
    List<LinkInstance> linkInstances = linkInstanceDao.searchLinkInstances(query1);
    assertThat(linkInstances).extracting("id").containsOnly(id1, id2, id3);
    SearchQueryStem stem2 = SearchQueryStem.createBuilder("Collection").linkTypeIds(Collections.singletonList(LINK_TYPE_ID3)).build();
    SearchQuery query2 = SearchQuery.createBuilder(USER).stems(Collections.singletonList(stem2)).build();
    linkInstances = linkInstanceDao.searchLinkInstances(query2);
    assertThat(linkInstances).extracting("id").containsOnly(id4);
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) SearchQueryStem(io.lumeer.storage.api.query.SearchQueryStem) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 5 with SearchQueryStem

use of io.lumeer.storage.api.query.SearchQueryStem in project engine by Lumeer.

the class MongoLinkInstanceDaoTest method testGetLinkInstancesByDocumentIds.

@Test
public void testGetLinkInstancesByDocumentIds() {
    String id1 = linkInstanceDao.createLinkInstance(prepareLinkInstance()).getId();
    LinkInstance linkInstance2 = prepareLinkInstance();
    linkInstance2.setDocumentIds(Arrays.asList(DOCUMENT_ID2, DOCUMENT_ID3));
    String id2 = linkInstanceDao.createLinkInstance(linkInstance2).getId();
    LinkInstance linkInstance3 = prepareLinkInstance();
    linkInstance3.setDocumentIds(Arrays.asList(DOCUMENT_ID1, DOCUMENT_ID5));
    String id3 = linkInstanceDao.createLinkInstance(linkInstance3).getId();
    LinkInstance linkInstance4 = prepareLinkInstance();
    linkInstance4.setDocumentIds(Arrays.asList(DOCUMENT_ID2, DOCUMENT_ID4));
    String id4 = linkInstanceDao.createLinkInstance(linkInstance4).getId();
    SearchQueryStem stem1 = SearchQueryStem.createBuilder("Collection").documentIds(Collections.singleton(DOCUMENT_ID1)).build();
    SearchQuery query1 = SearchQuery.createBuilder(USER).stems(Collections.singletonList(stem1)).build();
    List<LinkInstance> linkInstances = linkInstanceDao.searchLinkInstances(query1);
    assertThat(linkInstances).extracting("id").containsOnly(id1, id3);
    SearchQueryStem stem2 = SearchQueryStem.createBuilder("Collection").documentIds(Collections.singleton(DOCUMENT_ID2)).build();
    SearchQuery query2 = SearchQuery.createBuilder(USER).stems(Collections.singletonList(stem2)).build();
    linkInstances = linkInstanceDao.searchLinkInstances(query2);
    assertThat(linkInstances).extracting("id").containsOnly(id1, id2, id4);
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) SearchQueryStem(io.lumeer.storage.api.query.SearchQueryStem) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Aggregations

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