-
Notifications
You must be signed in to change notification settings - Fork 124
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 all commits
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,8 @@ | ||
package com.meilisearch.sdk; | ||
|
||
import com.meilisearch.sdk.exceptions.MeilisearchException; | ||
import com.meilisearch.sdk.model.IndexesQuery; | ||
import com.meilisearch.sdk.model.Results; | ||
import com.meilisearch.sdk.model.TaskInfo; | ||
import java.util.HashMap; | ||
|
||
|
@@ -25,23 +27,23 @@ class IndexesHandler { | |
/** | ||
* Creates an index with a unique identifier | ||
* | ||
* @param uid Unique identifier to create the index with | ||
* @return Meilisearch API response | ||
* @param uid Unique identifier of the index | ||
* @return Meilisearch API response as TaskInfo | ||
* @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); | ||
} | ||
|
||
/** | ||
* Creates an index with a unique identifier | ||
* | ||
* @param uid Unique identifier to create the index with | ||
* @param uid Unique identifier of the index | ||
* @param primaryKey Field to use as the primary key for documents in that index | ||
* @return Meilisearch API response | ||
* @return Meilisearch API response as TaskInfo | ||
* @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); | ||
|
@@ -53,21 +55,41 @@ TaskInfo create(String uid, String primaryKey) throws MeilisearchException { | |
* Gets an index from its uid | ||
* | ||
* @param uid Unique identifier of the index to get | ||
* @return Meilisearch API response | ||
* @return Meilisearch API response as Index instance | ||
* @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 { | ||
return httpClient.get(new IndexesQuery().toQuery(uid), Index.class); | ||
} | ||
|
||
/** | ||
* Gets all indexes in the current Meilisearch instance | ||
* Gets indexes in the current Meilisearch instance | ||
* | ||
* @return Meilisearch API response | ||
* @return Results containing a list of indexes | ||
* @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 query parameters accepted by the indexes route | ||
* @return Results containing a list of indexes | ||
* @throws MeilisearchException if an error occurs | ||
*/ | ||
Results<Index> getIndexes(IndexesQuery params) throws MeilisearchException { | ||
return httpClient.get(params.toQuery(params), Results.class, Index.class); | ||
} | ||
|
||
/** | ||
* Gets indexes in the current Meilisearch instance | ||
* | ||
* @return List of indexes as String | ||
* @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); | ||
} | ||
|
||
|
@@ -76,26 +98,24 @@ String getAll() throws MeilisearchException { | |
* | ||
* @param uid Unique identifier of the index to update | ||
* @param primaryKey New primary key field to use for documents in that index | ||
* @return Meilisearch API response | ||
* @return Meilisearch API response as TaskInfo | ||
* @throws MeilisearchException if an error occurs | ||
*/ | ||
TaskInfo updatePrimaryKey(String uid, String primaryKey) throws MeilisearchException { | ||
HashMap<String, String> index = new HashMap<String, String>(); | ||
index.put("primaryKey", primaryKey); | ||
|
||
String requestQuery = "/indexes/" + uid; | ||
return httpClient.patch(requestQuery, index, TaskInfo.class); | ||
return httpClient.patch(new IndexesQuery().toQuery(uid), index, TaskInfo.class); | ||
} | ||
|
||
/** | ||
* Deletes an index in the Meilisearch instance | ||
* | ||
* @param uid Unique identifier of the index to delete | ||
* @return Meilisearch API response | ||
* @return Meilisearch API response as TaskInfo | ||
* @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 { | ||
return httpClient.delete(new IndexesQuery().toQuery(uid), TaskInfo.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.meilisearch.sdk.model; | ||
|
||
import com.meilisearch.sdk.http.URLBuilder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
|
||
/** | ||
* Data structure of the query parameters when fetching indexes | ||
* | ||
* <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() {} | ||
|
||
public String toQuery(String uid) { | ||
URLBuilder urlb = new URLBuilder(); | ||
urlb.addSubroute("indexes").addSubroute(uid); | ||
return urlb.getURL(); | ||
} | ||
|
||
public String toQuery(IndexesQuery param) { | ||
URLBuilder urlb = new URLBuilder(); | ||
urlb.addSubroute("indexes") | ||
.addParameter("limit", param.getLimit()) | ||
.addParameter("offset", param.getOffset()); | ||
return urlb.getURL(); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.