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);
}
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();
}
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();
}
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);
}
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);
}
Aggregations