Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Add document:search#77

Merged
jenow merged 31 commits into
3-devfrom
KZL-1350-document-search
Apr 22, 2020
Merged

Add document:search#77
jenow merged 31 commits into
3-devfrom
KZL-1350-document-search

Conversation

@y-abs
Copy link
Copy Markdown
Contributor

@y-abs y-abs commented Mar 19, 2020

What does this PR do ?

This PR adds document:search with its units tests and the SearchResult class.

Sample code :

import io.kuzzle.sdk.*;
import io.kuzzle.sdk.CoreClasses.Responses.Response;
import io.kuzzle.sdk.CoreClasses.SearchResult;
import io.kuzzle.sdk.Options.DocumentOptions;
import io.kuzzle.sdk.Options.KuzzleOptions;
import io.kuzzle.sdk.Options.Protocol.WebSocketOptions;
import io.kuzzle.sdk.Options.SearchOptions;
import io.kuzzle.sdk.Protocol.WebSocket;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;

public class searchDocument {
    private static Kuzzle kuzzle;

    public static void main(String[] args) {
        WebSocketOptions opts = new WebSocketOptions();
        opts.setAutoReconnect(true).setConnectionTimeout(42000);

        try {
            WebSocket ws = new WebSocket("localhost", opts);

            kuzzle = new Kuzzle(ws, (KuzzleOptions) null);
            kuzzle.connect();
            ConcurrentHashMap<String, Object> doc = new ConcurrentHashMap<>();
            doc.put("Hello", "Clarisse");
            for(int i = 0; i < 200; i+=1) {
                kuzzle.getDocumentController().create("nyc-open-data", "yellow-taxi", doc).get();
            }

            SearchOptions ops = new SearchOptions();
            ops.setFrom(0);
            ops.setSize(50);
            
            ConcurrentHashMap<String, Object> searchQuery = new ConcurrentHashMap<>();
            ConcurrentHashMap<String, Object> query = new ConcurrentHashMap<>();
            ConcurrentHashMap<String, Object> match = new ConcurrentHashMap<>();
            match.put("category", "suv");
            query.put("match", match);
            searchQuery.put("query", query);

            SearchResult result = kuzzle.getDocumentController().search("nyc-open-data", "yellow-taxi", searchQuery, ops);

            for (; result != null; result = result.next().get()) {
                System.out.println(result.hits);
            }
        }  catch (Exception e) {
            e.printStackTrace();
        }
        kuzzle.disconnect();
    }
};

How should this be manually tested?

  • Step 1 :
  • Step 2 :
  • Step 3 :
    ...

Other changes

Correct how refresh option is passed and adapt tests

Boyscout

@y-abs y-abs self-assigned this Mar 19, 2020
@y-abs y-abs changed the title Kzl 1350 document search Add document:search Mar 19, 2020
@y-abs y-abs removed the wip label Apr 8, 2020

Searches document.

There is a limit to how many documents can be returned by a single search query.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this should be a warning

Comment thread doc/3/controllers/document/search/index.md Outdated
Comment thread doc/3/controllers/document/search/index.md Outdated
Comment thread doc/3/core-classes/search-options/index.md Outdated
Comment thread doc/3/core-classes/search-result/introduction/index.md Outdated
| `documents` | ArrayList<ConcurrentHashMap<String, Object>> | An array of instantiated Document objects | get |
| `fetched` | Integer | The number of fetched documents so far | get/set |
| `options` | SearchOptions | The arguments of the search/scroll request | get |
| `filters` | object | The filters of the search request | get |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this a ConcurrentHashMap?

## Arguments

```java
next();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete signature

Comment thread doc/3/core-classes/search-result/next/snippets/scroll.java Outdated
return nextRequest;
}

public SearchResult next() throws NotConnectedException, InternalException, ExecutionException, InterruptedException {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calls to next() are not async?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it, its now async

@y-abs y-abs requested a review from Aschen April 15, 2020 14:02
Copy link
Copy Markdown
Contributor

@Aschen Aschen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

public CompletableFuture<SearchResult> next() throws NotConnectedException, InternalException, ExecutionException, InterruptedException {
System.out.println("fetched: " + this.fetched + " total: " + this.total);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug leftover

@jenow jenow merged commit 4085b37 into 3-dev Apr 22, 2020
@jenow jenow deleted the KZL-1350-document-search branch April 22, 2020 13:47
@jenow jenow mentioned this pull request May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants