use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class SearchQueryTest method shouldSearchElement3.
@Test
public void shouldSearchElement3() {
MatchQuery match = SearchQuery.match("Salvador").field("name");
SearchQuery query = new SearchQuery("index-diana", match);
List<DocumentEntity> entities = entityManager.search(query).collect(Collectors.toList());
assertEquals(1, entities.size());
List<String> result = entities.stream().flatMap(e -> e.getDocuments().stream()).filter(d -> "name".equals(d.getName())).map(d -> d.get(String.class)).collect(Collectors.toList());
assertThat(result, containsInAnyOrder("Salvador"));
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class SearchQueryTest method shouldSearchElement.
@Test
public void shouldSearchElement() {
MatchQuery match = SearchQuery.match("Financial");
SearchQuery query = new SearchQuery("index-diana", match);
List<DocumentEntity> entities = entityManager.search(query).collect(Collectors.toList());
assertEquals(1, entities.size());
assertEquals(Document.of("name", "São Paulo"), entities.get(0).find("name").get());
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class DefaultCouchbaseDocumentCollectionManager method select.
@Override
public Stream<DocumentEntity> select(DocumentQuery query) throws NullPointerException {
QueryConverter.QueryConverterResult select = QueryConverter.select(query, database);
Stream<DocumentEntity> idsQuery = Stream.empty();
Stream<DocumentEntity> n1qlQueryStream = Stream.empty();
if (nonNull(select.getStatement())) {
ParameterizedN1qlQuery n1qlQuery = N1qlQuery.parameterized(select.getStatement(), select.getParams());
N1qlQueryResult result = bucket.query(n1qlQuery);
idsQuery = convert(result, database);
}
if (!select.getKeys().isEmpty()) {
idsQuery = convert(select.getKeys().stream(), bucket);
}
return Stream.concat(n1qlQueryStream, idsQuery);
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldShouldDefineLimit.
@Test
public void shouldShouldDefineLimit() {
DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
Document name = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).limit(2L).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertEquals(2, entities.size());
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldFindDocumentByName.
@Test
public void shouldFindDocumentByName() {
DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id4"), Document.of("name", "name3"), Document.of("_key", "person:id4")));
Document name = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
Aggregations