Search in sources :

Example 6 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class SearchFacadeIT method testDurationConstraint.

@Test
public void testDurationConstraint() {
    Constraint constraint = new Constraint(ConstraintType.Duration, new DataDocument("type", "Work"));
    Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
    String collectionId = createCollection("durationCollection", attribute).getId();
    String id1 = createDocument(collectionId, "5w3d").getId();
    String id2 = createDocument(collectionId, "3d4h").getId();
    String id3 = createDocument(collectionId, "2d12h").getId();
    String id4 = createDocument(collectionId, "3d2h5s").getId();
    String id5 = createDocument(collectionId, "ddhmms").getId();
    Query query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.EQUALS, "28h"));
    List<Document> documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id2, id3);
    query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.NOT_EQUALS, "dh19h"));
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id4, id5);
    query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.EQUALS, "5tddd"));
    searchFacade.setLanguage(Language.CS);
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id1);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Query(io.lumeer.api.model.Query) Constraint(io.lumeer.api.model.Constraint) Attribute(io.lumeer.api.model.Attribute) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 7 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class SearchFacadeIT method testChildDocuments.

@Test
public void testChildDocuments() {
    final Document a0 = createDocument(collectionIds.get(0), "a0");
    final Document b1 = createDocument(collectionIds.get(0), "b1", a0.getId());
    final Document b2 = createDocument(collectionIds.get(0), "b2", a0.getId());
    createDocument(collectionIds.get(0), "c1", b1.getId());
    final Document c2 = createDocument(collectionIds.get(0), "c2", b1.getId());
    createDocument(collectionIds.get(0), "c3", b1.getId());
    createDocument(collectionIds.get(0), "d1", b2.getId());
    createDocument(collectionIds.get(0), "d2", b2.getId());
    createDocument(collectionIds.get(0), "d3", b2.getId());
    createDocument(collectionIds.get(0), "e1", c2.getId());
    createDocument(collectionIds.get(0), "e2", c2.getId());
    Query query = new Query(new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.singleton(a0.getId()), Collections.emptyList(), Collections.emptyList()));
    List<Document> documents = searchFacade.searchDocuments(query, true);
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(documents.stream().filter(d -> d.getMetaData() == null || d.getMetaData().get(Document.META_PARENT_ID) == null).count()).isEqualTo(1);
    assertions.assertThat(documents).hasSize(11);
    assertions.assertThat(documents.stream().map(d -> d.getData().getString(DOCUMENT_KEY)).collect(Collectors.toSet())).containsExactlyInAnyOrder("a0", "b1", "b2", "c1", "c2", "c3", "d1", "d2", "d3", "e1", "e2");
    assertions.assertAll();
    query = new Query(new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.singleton(b2.getId()), Collections.emptyList(), Collections.emptyList()));
    documents = searchFacade.searchDocuments(query, true);
    assertions = new SoftAssertions();
    assertions.assertThat(documents).hasSize(4);
    assertions.assertThat(documents.stream().map(d -> d.getData().getString(DOCUMENT_KEY)).collect(Collectors.toSet())).containsExactlyInAnyOrder("b2", "d1", "d2", "d3");
    assertions.assertAll();
    query = new Query(new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.singleton(b1.getId()), Collections.emptyList(), Collections.emptyList()));
    documents = searchFacade.searchDocuments(query, true);
    assertions = new SoftAssertions();
    assertions.assertThat(documents).hasSize(6);
    assertions.assertThat(documents.stream().map(d -> d.getData().getString(DOCUMENT_KEY)).collect(Collectors.toSet())).containsExactlyInAnyOrder("b1", "c1", "c2", "c3", "e1", "e2");
    assertions.assertAll();
}
Also used : Arrays(java.util.Arrays) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) WorkspaceKeeper(io.lumeer.core.WorkspaceKeeper) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) QueryStem(io.lumeer.api.model.QueryStem) Map(java.util.Map) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) Permission(io.lumeer.api.model.Permission) RoleType(io.lumeer.api.model.RoleType) DataDocument(io.lumeer.engine.api.data.DataDocument) ConditionValueType(io.lumeer.api.model.ConditionValueType) Document(io.lumeer.api.model.Document) Set(java.util.Set) PermissionsChecker(io.lumeer.core.auth.PermissionsChecker) Constraint(io.lumeer.api.model.Constraint) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) LinkType(io.lumeer.api.model.LinkType) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) List(java.util.List) Attribute(io.lumeer.api.model.Attribute) ConstraintType(io.lumeer.api.model.ConstraintType) CollectionAttributeFilter(io.lumeer.api.model.CollectionAttributeFilter) UserDao(io.lumeer.storage.api.dao.UserDao) SoftAssertions(org.assertj.core.api.SoftAssertions) RunWith(org.junit.runner.RunWith) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) Language(io.lumeer.api.model.Language) Role(io.lumeer.api.model.Role) DataDao(io.lumeer.storage.api.dao.DataDao) Query(io.lumeer.api.model.Query) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) ConditionType(io.lumeer.api.model.ConditionType) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) Permissions(io.lumeer.api.model.Permissions) Test(org.junit.Test) CollectionPurposeType(io.lumeer.api.model.CollectionPurposeType) Project(io.lumeer.api.model.Project) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) IntegrationTestBase(io.lumeer.engine.IntegrationTestBase) LinkDataDao(io.lumeer.storage.api.dao.LinkDataDao) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Query(io.lumeer.api.model.Query) SoftAssertions(org.assertj.core.api.SoftAssertions) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) QueryStem(io.lumeer.api.model.QueryStem) Test(org.junit.Test)

Example 8 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class SearchFacadeIT method testSearchTasks.

@Test
public void testSearchTasks() {
    Collection taskCollection = createTaskCollectionWithAttributes("taskCollection");
    String taskCollectionId = taskCollection.getId();
    Attribute stateAttribute = taskCollection.getAttributes().stream().filter(a -> a.getId().equals("a1")).findFirst().get();
    String stateAttributeId = stateAttribute.getId();
    Attribute assigneeAttribute = taskCollection.getAttributes().stream().filter(a -> a.getId().equals("a2")).findFirst().get();
    String assigneeAttributeId = assigneeAttribute.getId();
    String otherCollectionId = createCollection("otherCollection", stateAttribute, assigneeAttribute).getId();
    String id1 = createDocument(taskCollectionId, Map.of(stateAttributeId, "a", assigneeAttributeId, USER)).getId();
    createDocument(taskCollectionId, Collections.singletonMap(stateAttributeId, "b"));
    String id3 = createDocument(taskCollectionId, Collections.singletonMap(stateAttributeId, "c")).getId();
    String id4 = createDocument(taskCollectionId, Collections.singletonMap(stateAttributeId, "d")).getId();
    String id5 = createDocument(taskCollectionId, Map.of(stateAttributeId, Arrays.asList("a", "b"), assigneeAttributeId, USER)).getId();
    String id6 = createDocument(taskCollectionId, Collections.singletonMap(stateAttributeId, Arrays.asList("b", "c"))).getId();
    String id7 = createDocument(taskCollectionId, Collections.singletonMap(stateAttributeId, Arrays.asList("c", "d"))).getId();
    String id8 = createDocument(taskCollectionId, Collections.singletonMap(stateAttributeId, Arrays.asList("d", "a"))).getId();
    createDocument(otherCollectionId, Collections.singletonMap(stateAttributeId, "a"));
    createDocument(otherCollectionId, Collections.singletonMap(stateAttributeId, "b"));
    createDocument(otherCollectionId, Collections.singletonMap(stateAttributeId, "c"));
    createDocument(otherCollectionId, Collections.singletonMap(stateAttributeId, "d"));
    Query query = new Query();
    List<Document> documents = searchFacade.searchTasksDocumentsAndLinks(query, true).getFirst();
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id5);
    query = createSimpleQueryWithAttributeFilter(taskCollectionId, CollectionAttributeFilter.createFromValues(taskCollectionId, stateAttributeId, ConditionType.HAS_SOME, Arrays.asList("a", "c", "d")));
    documents = searchFacade.searchTasksDocumentsAndLinks(query, true).getFirst();
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id3, id4, id5, id6, id7, id8);
    query = createSimpleQueryWithAttributeFilter(otherCollectionId, CollectionAttributeFilter.createFromValues(otherCollectionId, stateAttributeId, ConditionType.HAS_SOME, Arrays.asList("a", "c", "d")));
    documents = searchFacade.searchTasksDocumentsAndLinks(query, true).getFirst();
    assertThat(documents).extracting(Document::getId).isEmpty();
}
Also used : Query(io.lumeer.api.model.Query) Attribute(io.lumeer.api.model.Attribute) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 9 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class SearchFacadeIT method testSearchDocumentsByEmptyQuery.

@Test
public void testSearchDocumentsByEmptyQuery() {
    String id1 = createDocument(collectionIds.get(0), "doc1").getId();
    String id2 = createDocument(collectionIds.get(0), "doc2").getId();
    String id3 = createDocument(collectionIds.get(1), "doc3").getId();
    String id4 = createDocument(collectionIds.get(1), "doc4").getId();
    String id5 = createDocument(collectionIds.get(2), "doc5").getId();
    String id6 = createDocument(collectionIds.get(2), "doc6").getId();
    List<Document> documents = searchFacade.searchDocuments(new Query(), true);
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3, id4, id5, id6);
}
Also used : Query(io.lumeer.api.model.Query) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 10 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class SearchFacadeIT method testSearchDocumentsByFiltersAndFulltexts.

@Test
public void testSearchDocumentsByFiltersAndFulltexts() {
    createDocument(collectionIds.get(0), "word");
    String id2 = createDocument(collectionIds.get(0), "lmr").getId();
    String id3 = createDocument(collectionIds.get(0), "wlmrd").getId();
    String id4 = createDocument(collectionIds.get(0), "lalamr").getId();
    createDocument(collectionIds.get(1), "something fulltext");
    String id6 = createDocument(collectionIds.get(1), "lmr").getId();
    String id7 = createDocument(collectionIds.get(1), "other lmr").getId();
    String id8 = createDocument(collectionIds.get(2), "full wordmr").getId();
    Query query = new Query(Collections.emptyList(), new HashSet<>(Collections.singletonList("mr")), null, null);
    List<Document> documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id2, id3, id4, id6, id7, id8);
    List<CollectionAttributeFilter> filters = Collections.singletonList(CollectionAttributeFilter.createFromValues(collectionIds.get(0), DOCUMENT_KEY, ConditionType.EQUALS, "lmr"));
    QueryStem stem = new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.emptySet(), filters, Collections.emptyList());
    query = new Query(Collections.singletonList(stem), new HashSet<>(Collections.singletonList("mr")), null, null);
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id2);
    filters = Arrays.asList(CollectionAttributeFilter.createFromValues(collectionIds.get(0), DOCUMENT_KEY, ConditionType.EQUALS, "lmr"), CollectionAttributeFilter.createFromValues(collectionIds.get(1), DOCUMENT_KEY, ConditionType.EQUALS, "other lmr"));
    List<QueryStem> stems = Arrays.asList(new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.emptySet(), filters, Collections.emptyList()), new QueryStem(null, collectionIds.get(1), Collections.emptyList(), Collections.emptySet(), filters, Collections.emptyList()));
    query = new Query(stems, new HashSet<>(Collections.singletonList("mr")), null, null);
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id2, id7);
}
Also used : Query(io.lumeer.api.model.Query) CollectionAttributeFilter(io.lumeer.api.model.CollectionAttributeFilter) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) QueryStem(io.lumeer.api.model.QueryStem) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Query (io.lumeer.api.model.Query)43 Document (io.lumeer.api.model.Document)28 Test (org.junit.Test)26 DataDocument (io.lumeer.engine.api.data.DataDocument)24 QueryStem (io.lumeer.api.model.QueryStem)22 Collection (io.lumeer.api.model.Collection)15 Attribute (io.lumeer.api.model.Attribute)14 Constraint (io.lumeer.api.model.Constraint)10 LinkInstance (io.lumeer.api.model.LinkInstance)10 Role (io.lumeer.api.model.Role)10 LinkType (io.lumeer.api.model.LinkType)9 View (io.lumeer.api.model.View)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 Permission (io.lumeer.api.model.Permission)7 Permissions (io.lumeer.api.model.Permissions)7 List (java.util.List)7 Project (io.lumeer.api.model.Project)6 User (io.lumeer.api.model.User)6 CollectionAttributeFilter (io.lumeer.api.model.CollectionAttributeFilter)5