-
Notifications
You must be signed in to change notification settings - Fork 131
Add features of meilisearch 1.18 (queryVector and index renaming) #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yamiSukehiro2907
wants to merge
9
commits into
meilisearch:main
Choose a base branch
from
yamiSukehiro2907:feat/support-meilisearch-1.18
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
75ee2cc
feat: support Meilisearch 1.18 (queryVector, rename index, swap-indexβ¦
yamiSukehiro2907 a6bf507
feat: support Meilisearch 1.18 (queryVector + rename index + swap index)
yamiSukehiro2907 2a5ec2f
fix: refactor index rename and swap tests to use SDK public API
yamiSukehiro2907 9a991c4
fix: add comprehensive assertions to index rename and swap tests
yamiSukehiro2907 9d142b3
Merge branch 'main' into feat/support-meilisearch-1.18
yamiSukehiro2907 baf7c67
Merge branch 'main' into feat/support-meilisearch-1.18
yamiSukehiro2907 4f253e1
prog: deleted data.ms
yamiSukehiro2907 eb7f772
prog: Fixed tests for IndexRename and SwapIndexRename
yamiSukehiro2907 d0df797
prog: changed the parameters from indexUid to uid
yamiSukehiro2907 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1.26.0 |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| e67555e1-d1ac-4ecb-adae-00d5687bbea3 |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package com.meilisearch.sdk; | ||
|
|
||
| import com.meilisearch.sdk.model.TaskInfo; | ||
| import okhttp3.mockwebserver.MockResponse; | ||
| import okhttp3.mockwebserver.MockWebServer; | ||
| import okhttp3.mockwebserver.RecordedRequest; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.*; | ||
|
|
||
| public class IndexRenameTest { | ||
|
|
||
| private MockWebServer mockServer; | ||
| private Config config; | ||
| private IndexesHandler handler; | ||
|
|
||
| @BeforeEach | ||
| void setUp() throws IOException { | ||
| mockServer = new MockWebServer(); | ||
| mockServer.start(); | ||
|
|
||
| String baseUrl = mockServer.url("").toString(); | ||
| if (baseUrl.endsWith("/")) { | ||
| baseUrl = baseUrl.substring(0, baseUrl.length() - 1); | ||
| } | ||
| config = new Config(baseUrl, "masterKey"); | ||
| handler = new IndexesHandler(config); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() throws IOException { | ||
| mockServer.shutdown(); | ||
| } | ||
|
|
||
| @Test | ||
| void testRenameIndex() throws Exception { | ||
| String responseJson = "{\"taskUid\":123,\"indexUid\":\"indexB\",\"status\":\"enqueued\",\"type\":\"indexUpdate\",\"enqueuedAt\":\"2024-01-01T00:00:00Z\"}"; | ||
| mockServer.enqueue(new MockResponse() | ||
| .setResponseCode(202) | ||
| .setBody(responseJson) | ||
| .addHeader("Content-Type", "application/json")); | ||
|
|
||
| TaskInfo result = handler.updateIndexUid("indexA", "indexB"); | ||
|
|
||
| assertThat(result, is(notNullValue())); | ||
| assertThat(result.getTaskUid(), is(equalTo(123))); | ||
|
|
||
| RecordedRequest request = mockServer.takeRequest(); | ||
| assertThat(request.getMethod(), equalTo("PATCH")); | ||
| assertThat(request.getPath(), equalTo("/indexes/indexA")); | ||
| assertThat(request.getHeader("Authorization"), equalTo("Bearer masterKey")); | ||
|
|
||
| String requestBody = request.getBody().readUtf8(); | ||
| assertThat(requestBody, containsString("\"indexUid\":\"indexB\"")); | ||
| } | ||
|
|
||
| @Test | ||
| void testRenameIndexWithDifferentNames() throws Exception { | ||
| String responseJson = "{\"taskUid\":456,\"indexUid\":\"newIndex\",\"status\":\"enqueued\",\"type\":\"indexUpdate\",\"enqueuedAt\":\"2024-01-02T00:00:00Z\"}"; | ||
| mockServer.enqueue(new MockResponse() | ||
| .setResponseCode(202) | ||
| .setBody(responseJson) | ||
| .addHeader("Content-Type", "application/json")); | ||
|
|
||
| TaskInfo result = handler.updateIndexUid("oldIndex", "newIndex"); | ||
|
|
||
| assertThat(result, is(notNullValue())); | ||
| assertThat(result.getTaskUid(), is(equalTo(456))); | ||
|
|
||
| RecordedRequest request = mockServer.takeRequest(); | ||
| assertThat(request.getPath(), equalTo("/indexes/oldIndex")); | ||
|
|
||
| String requestBody = request.getBody().readUtf8(); | ||
| assertThat(requestBody, containsString("\"indexUid\":\"newIndex\"")); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/test/java/com/meilisearch/sdk/SearchResultQueryVectorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.meilisearch.sdk; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.*; | ||
|
|
||
| import com.meilisearch.sdk.json.GsonJsonHandler; | ||
| import com.meilisearch.sdk.model.SearchResult; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class SearchResultQueryVectorTest { | ||
|
|
||
| @Test | ||
| void testQueryVectorIsMapped() throws Exception { | ||
| String json = | ||
| "{" | ||
| + "\"hits\": []," | ||
| + "\"processingTimeMs\": 1," | ||
| + "\"query\": \"hello\"," | ||
| + "\"queryVector\": [0.1, 0.2, 0.3]" | ||
| + "}"; | ||
|
|
||
| GsonJsonHandler handler = new GsonJsonHandler(); | ||
| SearchResult result = handler.decode(json, SearchResult.class); | ||
|
|
||
| assertThat(result, is(notNullValue())); | ||
| assertThat(result.getQueryVector(), is(notNullValue())); | ||
| assertThat(result.getQueryVector().size(), is(3)); | ||
| assertThat(result.getQueryVector().get(0), equalTo(0.1F)); | ||
| assertThat(result.getQueryVector().get(1), equalTo(0.2F)); | ||
| assertThat(result.getQueryVector().get(2), equalTo(0.3F)); | ||
| } | ||
| } |
133 changes: 133 additions & 0 deletions
133
src/test/java/com/meilisearch/sdk/SwapIndexesRenameTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| package com.meilisearch.sdk; | ||
|
|
||
| import com.meilisearch.sdk.model.SwapIndexesParams; | ||
| import com.meilisearch.sdk.model.TaskInfo; | ||
| import okhttp3.mockwebserver.MockResponse; | ||
| import okhttp3.mockwebserver.MockWebServer; | ||
| import okhttp3.mockwebserver.RecordedRequest; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.*; | ||
|
|
||
| public class SwapIndexesRenameTest { | ||
|
|
||
| private MockWebServer mockServer; | ||
| private Config config; | ||
| private Client client; | ||
|
|
||
| @BeforeEach | ||
| void setUp() throws IOException { | ||
| mockServer = new MockWebServer(); | ||
| mockServer.start(); | ||
|
|
||
| String baseUrl = mockServer.url("").toString(); | ||
| if (baseUrl.endsWith("/")) { | ||
| baseUrl = baseUrl.substring(0, baseUrl.length() - 1); | ||
| } | ||
| config = new Config(baseUrl, "masterKey"); | ||
| client = new Client(config); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() throws IOException { | ||
| mockServer.shutdown(); | ||
| } | ||
|
|
||
| @Test | ||
| void testSwapIndexesWithRename() throws Exception { | ||
| String responseJson = "{\"taskUid\":789,\"status\":\"enqueued\",\"type\":\"indexSwap\",\"enqueuedAt\":\"2024-01-01T00:00:00Z\"}"; | ||
| mockServer.enqueue(new MockResponse() | ||
| .setResponseCode(202) | ||
| .setBody(responseJson) | ||
| .addHeader("Content-Type", "application/json")); | ||
|
|
||
| SwapIndexesParams[] params = { | ||
| new SwapIndexesParams() | ||
| .setIndexes(new String[]{"indexA", "indexB"}) | ||
| .setRename(true) | ||
| }; | ||
|
|
||
| TaskInfo result = client.swapIndexes(params); | ||
|
|
||
| assertThat(result, is(notNullValue())); | ||
| assertThat(result.getTaskUid(), is(equalTo(789))); | ||
|
|
||
| RecordedRequest request = mockServer.takeRequest(); | ||
| assertThat(request.getMethod(), equalTo("POST")); | ||
| assertThat(request.getPath(), equalTo("/swap-indexes")); | ||
| assertThat(request.getHeader("Authorization"), equalTo("Bearer masterKey")); | ||
|
|
||
| String requestBody = request.getBody().readUtf8(); | ||
| assertThat(requestBody, containsString("\"rename\":true")); | ||
| assertThat(requestBody, containsString("\"indexes\"")); | ||
| assertThat(requestBody, containsString("\"indexA\"")); | ||
| assertThat(requestBody, containsString("\"indexB\"")); | ||
| } | ||
|
|
||
| @Test | ||
| void testSwapIndexesWithoutRename() throws Exception { | ||
| String responseJson = "{\"taskUid\":790,\"status\":\"enqueued\",\"type\":\"indexSwap\",\"enqueuedAt\":\"2024-01-02T00:00:00Z\"}"; | ||
| mockServer.enqueue(new MockResponse() | ||
| .setResponseCode(202) | ||
| .setBody(responseJson) | ||
| .addHeader("Content-Type", "application/json")); | ||
|
|
||
| SwapIndexesParams[] params = { | ||
| new SwapIndexesParams() | ||
| .setIndexes(new String[]{"indexC", "indexD"}) | ||
| .setRename(false) | ||
| }; | ||
|
|
||
| TaskInfo result = client.swapIndexes(params); | ||
|
|
||
| assertThat(result, is(notNullValue())); | ||
| assertThat(result.getTaskUid(), is(equalTo(790))); | ||
|
|
||
| RecordedRequest request = mockServer.takeRequest(); | ||
| assertThat(request.getMethod(), equalTo("POST")); | ||
| assertThat(request.getPath(), equalTo("/swap-indexes")); | ||
|
|
||
| String requestBody = request.getBody().readUtf8(); | ||
| assertThat(requestBody, containsString("\"rename\":false")); | ||
| assertThat(requestBody, containsString("\"indexC\"")); | ||
| assertThat(requestBody, containsString("\"indexD\"")); | ||
| } | ||
|
|
||
| @Test | ||
| void testSwapMultipleIndexPairs() throws Exception { | ||
| String responseJson = "{\"taskUid\":791,\"status\":\"enqueued\",\"type\":\"indexSwap\",\"enqueuedAt\":\"2024-01-03T00:00:00Z\"}"; | ||
| mockServer.enqueue(new MockResponse() | ||
| .setResponseCode(202) | ||
| .setBody(responseJson) | ||
| .addHeader("Content-Type", "application/json")); | ||
|
|
||
| SwapIndexesParams[] params = { | ||
| new SwapIndexesParams() | ||
| .setIndexes(new String[]{"indexA", "indexB"}) | ||
| .setRename(true), | ||
| new SwapIndexesParams() | ||
| .setIndexes(new String[]{"indexC", "indexD"}) | ||
| .setRename(false) | ||
| }; | ||
|
|
||
| TaskInfo result = client.swapIndexes(params); | ||
|
|
||
| assertThat(result, is(notNullValue())); | ||
| assertThat(result.getTaskUid(), is(equalTo(791))); | ||
|
|
||
| RecordedRequest request = mockServer.takeRequest(); | ||
| String requestBody = request.getBody().readUtf8(); | ||
|
|
||
| assertThat(requestBody, containsString("\"indexA\"")); | ||
| assertThat(requestBody, containsString("\"indexB\"")); | ||
| assertThat(requestBody, containsString("\"indexC\"")); | ||
| assertThat(requestBody, containsString("\"indexD\"")); | ||
| assertThat(requestBody, startsWith("[")); | ||
| assertThat(requestBody, endsWith("]")); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.