-
Notifications
You must be signed in to change notification settings - Fork 128
Update Index API for Meilisearch v.28 #516
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
Changes from 1 commit
784e044
e572ed1
6340a55
4b56d07
1372db7
9b43cc7
c9295b1
72fe913
17d0b2f
8560a7b
541cb0b
0d7dbe2
ce1cdb7
317790f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| package com.meilisearch.sdk; | ||
|
|
||
| import com.meilisearch.sdk.exceptions.MeilisearchException; | ||
| import com.meilisearch.sdk.http.URLBuilder; | ||
| import com.meilisearch.sdk.model.IndexesQuery; | ||
| import com.meilisearch.sdk.model.Results; | ||
| import com.meilisearch.sdk.model.TaskInfo; | ||
| import java.util.HashMap; | ||
|
|
||
|
|
@@ -29,8 +32,8 @@ class IndexesHandler { | |
| * @return Meilisearch API response | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| TaskInfo create(String uid) throws MeilisearchException { | ||
| return this.create(uid, null); | ||
| TaskInfo createIndex(String uid) throws MeilisearchException { | ||
| return this.createIndex(uid, null); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -41,7 +44,7 @@ TaskInfo create(String uid) throws MeilisearchException { | |
| * @return Meilisearch API response | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| TaskInfo create(String uid, String primaryKey) throws MeilisearchException { | ||
| TaskInfo createIndex(String uid, String primaryKey) throws MeilisearchException { | ||
| HashMap<String, String> index = new HashMap<String, String>(); | ||
| index.put("uid", uid); | ||
| index.put("primaryKey", primaryKey); | ||
|
|
@@ -56,9 +59,11 @@ TaskInfo create(String uid, String primaryKey) throws MeilisearchException { | |
| * @return Meilisearch API response | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| String get(String uid) throws MeilisearchException { | ||
| String requestQuery = "/indexes/" + uid; | ||
| return httpClient.get(requestQuery, String.class); | ||
| Index getIndex(String uid) throws MeilisearchException { | ||
| URLBuilder urlb = new URLBuilder(); | ||
| urlb.addSubroute("indexes").addSubroute(uid); | ||
| String urlPath = urlb.getURL(); | ||
| return httpClient.get(urlPath, Index.class); | ||
alallema marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -67,7 +72,33 @@ String get(String uid) throws MeilisearchException { | |
| * @return Meilisearch API response | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| String getAll() throws MeilisearchException { | ||
| Results<Index> getIndexes() throws MeilisearchException { | ||
| return httpClient.get("/indexes", Results.class, Index.class); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be nice to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can indeed do this but it means creating a new function that will require resources and complicate the general call such as: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the second option for consistency, but you are maybe right. You can ignore this for the moment but I would like the opinion of @brunoocasali on that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Me too ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My initial conception around In any case, I don't think If the path change in the future, we will have two places to change the tests, |
||
| } | ||
|
|
||
| /** | ||
| * Gets indexes in the current Meilisearch instance | ||
| * | ||
| * @param param accept by the indexes route | ||
alallema marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @return Meilisearch API response | ||
alallema marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| Results<Index> getIndexes(IndexesQuery param) throws MeilisearchException { | ||
| URLBuilder urlb = new URLBuilder(); | ||
| urlb.addSubroute("indexes") | ||
alallema marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .addParameter("limit", param.getLimit()) | ||
| .addParameter("offset", param.getOffset()); | ||
| String urlQuery = urlb.getURL(); | ||
| return httpClient.get(urlQuery, Results.class, Index.class); | ||
| } | ||
|
|
||
| /** | ||
| * Gets all indexes in the current Meilisearch instance | ||
alallema marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @return Meilisearch API response | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| String getRawIndexes() throws MeilisearchException { | ||
bidoubiwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return httpClient.get("/indexes", String.class); | ||
| } | ||
|
|
||
|
|
@@ -83,8 +114,10 @@ TaskInfo updatePrimaryKey(String uid, String primaryKey) throws MeilisearchExcep | |
| HashMap<String, String> index = new HashMap<String, String>(); | ||
| index.put("primaryKey", primaryKey); | ||
|
|
||
| String requestQuery = "/indexes/" + uid; | ||
| return httpClient.patch(requestQuery, index, TaskInfo.class); | ||
| URLBuilder urlb = new URLBuilder(); | ||
| urlb.addSubroute("indexes").addSubroute(uid); | ||
| String urlPath = urlb.getURL(); | ||
| return httpClient.patch(urlPath, index, TaskInfo.class); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -94,8 +127,10 @@ TaskInfo updatePrimaryKey(String uid, String primaryKey) throws MeilisearchExcep | |
| * @return Meilisearch API response | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| TaskInfo delete(String uid) throws MeilisearchException { | ||
| String requestQuery = "/indexes/" + uid; | ||
| return httpClient.delete(requestQuery, TaskInfo.class); | ||
| TaskInfo deleteIndex(String uid) throws MeilisearchException { | ||
| URLBuilder urlb = new URLBuilder(); | ||
| urlb.addSubroute("indexes").addSubroute(uid); | ||
| String urlPath = urlb.getURL(); | ||
| return httpClient.delete(urlPath, TaskInfo.class); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.meilisearch.sdk.model; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import lombok.experimental.Accessors; | ||
|
|
||
| /** | ||
| * Data structure of a query parameter for index route | ||
alallema marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * <p>https://docs.meilisearch.com/reference/api/indexes.html#query-parameters | ||
| */ | ||
| @Setter | ||
| @Getter | ||
| @Accessors(chain = true) | ||
| public class IndexesQuery { | ||
| private int offset = -1; | ||
| private int limit = -1; | ||
|
|
||
bidoubiwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public IndexesQuery() {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,7 +105,8 @@ public static void deleteAllIndexes() { | |
| Client ms = new Client(new Config(getMeilisearchHost(), "masterKey")); | ||
| Results<Index> indexes = ms.getIndexes(); | ||
| for (Index index : indexes.getResults()) { | ||
| ms.deleteIndex(index.getUid()); | ||
| TaskInfo task = ms.deleteIndex(index.getUid()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice change! 👯 |
||
| ms.waitForTask(task.getTaskUid()); | ||
| } | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.