Search in sources :

Example 1 with SearchResult

use of com.couchbase.client.java.search.result.SearchResult in project couchbase-jvm-clients by couchbase.

the class SearchTest method alltimeouts.

@Test
void alltimeouts() throws ExecutionException, InterruptedException, IOException {
    InputStream json = getClass().getClassLoader().getResourceAsStream("sdk-testcases/search/alltimeouts.json");
    SearchResult result = SearchMock.loadSearchTestCase(json);
    assertEquals(6, result.metaData().errors().size());
    assertEquals(6, result.metaData().metrics().errorPartitionCount());
    assertEquals(6, result.metaData().metrics().totalPartitionCount());
    assertEquals(0, result.metaData().metrics().successPartitionCount());
}
Also used : InputStream(java.io.InputStream) SearchResult(com.couchbase.client.java.search.result.SearchResult) Test(org.junit.jupiter.api.Test)

Example 2 with SearchResult

use of com.couchbase.client.java.search.result.SearchResult in project couchbase-jvm-clients by couchbase.

the class SearchIntegrationTest method simpleSearch.

@Test
void simpleSearch() throws Throwable {
    String docId = UUID.randomUUID().toString();
    MutationResult insertResult = collection.insert(docId, mapOf("name", "michael"));
    try {
        // should not have to retry here, but newly-created index is flaky
        runWithRetry(Duration.ofSeconds(30), () -> {
            SearchResult result = cluster.searchQuery(indexName, queryString("michael"), searchOptions().consistentWith(MutationState.from(insertResult.mutationToken().get())));
            List<String> actualDocIds = result.rows().stream().map(SearchRow::id).collect(toList());
            // make assertion inside the retry, because newly-created index sometimes returns
            // no rows even though we specified mutation tokens for consistency :-/
            assertEquals(listOf(docId), actualDocIds);
        });
    } finally {
        collection.remove(docId);
    }
}
Also used : SearchResult(com.couchbase.client.java.search.result.SearchResult) SearchQuery.queryString(com.couchbase.client.java.search.SearchQuery.queryString) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with SearchResult

use of com.couchbase.client.java.search.result.SearchResult in project couchbase-jvm-clients by couchbase.

the class SearchIntegrationTest method searchMatchOperatorOr.

@Test
void searchMatchOperatorOr() throws Throwable {
    String docId1 = UUID.randomUUID().toString();
    String docId2 = UUID.randomUUID().toString();
    MutationResult insertResult1 = collection.insert(docId1, mapOf("name", "milly"));
    MutationResult insertResult2 = collection.insert(docId2, mapOf("name", "tilly"));
    try {
        runWithRetry(Duration.ofSeconds(30), () -> {
            SearchResult result = cluster.searchQuery(indexName, match("milly tilly").operator(MatchOperator.OR), searchOptions().consistentWith(MutationState.from(insertResult1.mutationToken().get(), insertResult2.mutationToken().get())));
            List<String> actualDocIds = result.rows().stream().map(SearchRow::id).collect(toList());
            assertEquals(listOf(docId1, docId2), actualDocIds);
        });
    } finally {
        collection.remove(docId1);
        collection.remove(docId2);
    }
}
Also used : SearchResult(com.couchbase.client.java.search.result.SearchResult) SearchQuery.queryString(com.couchbase.client.java.search.SearchQuery.queryString) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with SearchResult

use of com.couchbase.client.java.search.result.SearchResult in project spring-data-couchbase by spring-projects.

the class JavaIntegrationTests method createFtsCollectionIndex.

public static void createFtsCollectionIndex(Cluster cluster, String indexName, String bucketName, String scopeName, String collectionName) {
    SearchIndex searchIndex = new SearchIndex(indexName, bucketName);
    if (scopeName != null) {
        // searchIndex = searchIndex.forScopeCollection(scopeName, collectionName);
        throw new RuntimeException("forScopeCollection not implemented in current java client version");
    }
    cluster.searchIndexes().upsertIndex(searchIndex, UpsertSearchIndexOptions.upsertSearchIndexOptions().timeout(Duration.ofSeconds(60)));
    int maxTries = 5;
    for (int i = 0; i < maxTries; i++) {
        try {
            SearchResult result = cluster.searchQuery(indexName, SearchQuery.queryString("junk"));
            break;
        } catch (CouchbaseException | IllegalStateException ex) {
            // this is a pretty dirty hack to avoid a race where we don't know if the index is ready yet
            if (i < (maxTries - 1) && (ex.getMessage().contains("no planPIndexes for indexName") || ex.getMessage().contains("pindex_consistency mismatched partition") || ex.getMessage().contains("pindex not available"))) {
                sleepMs(1000);
                continue;
            }
            throw ex;
        }
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) SearchResult(com.couchbase.client.java.search.result.SearchResult)

Example 5 with SearchResult

use of com.couchbase.client.java.search.result.SearchResult in project couchbase-jvm-clients by couchbase.

the class RateLimitingIntegrationTest method searchRateLimitMaxIngress.

@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchRateLimitMaxIngress() throws Exception {
    String username = "searchRateLimitIngress";
    Limits limits = new Limits();
    limits.searchLimits = new SearchLimits(10, 100, 1, 10);
    createRateLimitedUser(username, limits);
    adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits-ingress", config().bucketname()));
    Cluster cluster = createTestCluster(username);
    try {
        cluster.waitUntilReady(Duration.ofSeconds(10));
        String content = repeatString(1024 * 1024, "a");
        RateLimitedException ex = assertThrows(RateLimitedException.class, () -> {
            for (int i = 0; i < 10; i++) {
                try {
                    SearchResult res = cluster.searchQuery("ratelimits-ingress", QueryStringQuery.match(content), SearchOptions.searchOptions().timeout(Duration.ofSeconds(10)).limit(1));
                } catch (TimeoutException e) {
                // continue
                } catch (CouchbaseException e) {
                    if (e.getMessage().contains("no planPIndexes")) {
                        continue;
                    }
                    throw e;
                }
            }
        });
        assertTrue(ex.getMessage().contains("ingress_mib_per_min"));
    } finally {
        cluster.disconnect();
        adminCluster.users().dropUser(username);
        adminCluster.searchIndexes().dropIndex("ratelimits-ingress");
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) SearchResult(com.couchbase.client.java.search.result.SearchResult) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) TimeoutException(com.couchbase.client.core.error.TimeoutException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

SearchResult (com.couchbase.client.java.search.result.SearchResult)9 Test (org.junit.jupiter.api.Test)7 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)6 MutationResult (com.couchbase.client.java.kv.MutationResult)5 SearchQuery.queryString (com.couchbase.client.java.search.SearchQuery.queryString)5 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)2 SearchIndex (com.couchbase.client.java.manager.search.SearchIndex)2 Core (com.couchbase.client.core.Core)1 CoreContext (com.couchbase.client.core.CoreContext)1 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)1 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)1 DefaultFullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest)1 DefaultHttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse)1 DefaultLastHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent)1 HttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpContent)1 HttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse)1 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)1 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)1 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)1 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)1