forked from meilisearch/meilisearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchResultQueryVectorTest.java
More file actions
56 lines (45 loc) · 1.57 KB
/
SearchResultQueryVectorTest.java
File metadata and controls
56 lines (45 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.meilisearch.sdk;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import com.meilisearch.sdk.model.SearchResult;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class SearchResultQueryVectorTest {
private MockWebServer server;
private Client client;
@BeforeEach
void setup() throws Exception {
server = new MockWebServer();
server.start();
client = new Client(new Config(server.url("/").toString(), "masterKey"));
}
@AfterEach
void teardown() throws Exception {
server.shutdown();
}
@Test
void testQueryVectorDeserialization() throws Exception {
String json =
"""
{
"hits": [],
"queryVector": [1.1, -2.5, 3.14],
"offset": 0,
"limit": 20,
"estimatedTotalHits": 0,
"query": "hello",
"processingTimeMs": 1
}
""";
server.enqueue(new MockResponse().setResponseCode(200).setBody(json));
SearchResult res = client.index("movies").search("hello");
assertThat(res, notNullValue());
assertThat(res.getQueryVector(), hasSize(3));
assertThat(res.getQueryVector().get(0), equalTo(1.1f));
assertThat(res.getQueryVector().get(1), equalTo(-2.5f));
assertThat(res.getQueryVector().get(2), equalTo(3.14f));
}
}