Search in sources :

Example 1 with MatchQuery

use of com.couchbase.client.java.search.queries.MatchQuery 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);
    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"));
}
Also used : SearchQuery(com.couchbase.client.java.search.SearchQuery) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) CouchbaseKeyValueConfiguration(org.jnosql.diana.couchbase.key.CouchbaseKeyValueConfiguration) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) Collectors(java.util.stream.Collectors) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Arrays.asList(java.util.Arrays.asList) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) BucketManager(org.jnosql.diana.api.key.BucketManager) CouchbaseUtil(org.jnosql.diana.couchbase.CouchbaseUtil) BucketManagerFactory(org.jnosql.diana.api.key.BucketManagerFactory) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SearchQuery(com.couchbase.client.java.search.SearchQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) Test(org.junit.jupiter.api.Test)

Example 2 with MatchQuery

use of com.couchbase.client.java.search.queries.MatchQuery in project jnosql-diana-driver by eclipse.

the class SearchQueryTest method shouldSearchElement2.

@Test
public void shouldSearchElement2() {
    MatchQuery match = SearchQuery.match("Brazil");
    SearchQuery query = new SearchQuery("index-diana", match);
    List<DocumentEntity> entities = entityManager.search(query);
    assertEquals(3, 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", "Rio de Janeiro", "Manaus"));
}
Also used : SearchQuery(com.couchbase.client.java.search.SearchQuery) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) CouchbaseKeyValueConfiguration(org.jnosql.diana.couchbase.key.CouchbaseKeyValueConfiguration) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) Collectors(java.util.stream.Collectors) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Arrays.asList(java.util.Arrays.asList) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) BucketManager(org.jnosql.diana.api.key.BucketManager) CouchbaseUtil(org.jnosql.diana.couchbase.CouchbaseUtil) BucketManagerFactory(org.jnosql.diana.api.key.BucketManagerFactory) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SearchQuery(com.couchbase.client.java.search.SearchQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) Test(org.junit.jupiter.api.Test)

Example 3 with MatchQuery

use of com.couchbase.client.java.search.queries.MatchQuery 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);
    assertEquals(1, entities.size());
    assertEquals(Document.of("name", "São Paulo"), entities.get(0).find("name").get());
}
Also used : SearchQuery(com.couchbase.client.java.search.SearchQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) Test(org.junit.jupiter.api.Test)

Aggregations

SearchQuery (com.couchbase.client.java.search.SearchQuery)3 MatchQuery (com.couchbase.client.java.search.queries.MatchQuery)3 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)3 Test (org.junit.jupiter.api.Test)3 Arrays (java.util.Arrays)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)2 Document (org.jnosql.diana.api.document.Document)2 BucketManager (org.jnosql.diana.api.key.BucketManager)2 BucketManagerFactory (org.jnosql.diana.api.key.BucketManagerFactory)2 CouchbaseUtil (org.jnosql.diana.couchbase.CouchbaseUtil)2 CouchbaseKeyValueConfiguration (org.jnosql.diana.couchbase.key.CouchbaseKeyValueConfiguration)2 AfterAll (org.junit.jupiter.api.AfterAll)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2