Skip to content

Commit 99da85e

Browse files
bors[bot]oraliahdzalallema
authored
Merge #558
558: Implement `getRawIndexes` with query parameters r=alallema a=oraliahdz # Pull Request ## Related issue Fixes #521 ## What does this PR do? - Implement overload method on getRawIndexes for accepting query parameters - Add test for getRawIndexes with params ## PR checklist Please check if your PR fulfills the following requirements: - [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [X] Have you read the contributing guidelines? - [X] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: oraliahdz <[email protected]> Co-authored-by: Oralia Hernandez <[email protected]> Co-authored-by: Amélie <[email protected]>
2 parents 1c92710 + d54d014 commit 99da85e

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/main/java/com/meilisearch/sdk/Client.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ public String getRawIndexes() throws MeilisearchException {
109109
return this.indexesHandler.getRawIndexes();
110110
}
111111

112+
/**
113+
* Gets all indexes https://docs.meilisearch.com/reference/api/indexes.html#list-all-indexes
114+
*
115+
* @param params query parameters accepted by the get indexes route
116+
* @return List of indexes from the Meilisearch API as String
117+
* @throws MeilisearchException if an error occurs
118+
*/
119+
public String getRawIndexes(IndexesQuery params) throws MeilisearchException {
120+
return this.indexesHandler.getRawIndexes(params);
121+
}
122+
112123
/**
113124
* Creates a local reference to an index identified by `uid`, without doing an HTTP call.
114125
* Calling this method doesn't create an index by itself, but grants access to all the other

src/main/java/com/meilisearch/sdk/IndexesHandler.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Results<Index> getIndexes() throws MeilisearchException {
7676
/**
7777
* Gets indexes in the current Meilisearch instance
7878
*
79-
* @param query parameters accepted by the indexes route
79+
* @param params parameters accepted by the indexes route
8080
* @return Results containing a list of indexes
8181
* @throws MeilisearchException if an error occurs
8282
*/
@@ -95,6 +95,17 @@ String getRawIndexes() throws MeilisearchException {
9595
return httpClient.get(indexesPath().getURL(), String.class);
9696
}
9797

98+
/**
99+
* Gets indexes in the current Meilisearch instance
100+
*
101+
* @param params parameters accepted by the indexes route
102+
* @return List of indexes as String
103+
* @throws MeilisearchException if an error occurs
104+
*/
105+
String getRawIndexes(IndexesQuery params) throws MeilisearchException {
106+
return httpClient.get(indexesPath().addQuery(params.toQuery()).getURL(), String.class);
107+
}
108+
98109
/**
99110
* Updates the primary key of an index in the Meilisearch instance
100111
*

src/test/java/com/meilisearch/integration/ClientTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,25 @@ public void testGetRawIndexes() throws Exception {
190190
.contains(jsonIndexArray.get(1).getAsJsonObject().get("uid").getAsString()));
191191
}
192192

193+
/** Test getRawIndexes with limits */
194+
@Test
195+
public void testGetRawIndexesLimit() throws Exception {
196+
int limit = 1;
197+
String[] indexUids = {"GetRawIndexes", "GetRawIndexes2"};
198+
createEmptyIndex(indexUids[0]);
199+
createEmptyIndex(indexUids[1], this.primaryKey);
200+
IndexesQuery query = new IndexesQuery().setLimit(limit);
201+
202+
String indexes = client.getRawIndexes(query);
203+
JsonObject jsonIndexObject = JsonParser.parseString(indexes).getAsJsonObject();
204+
JsonArray jsonIndexArray = jsonIndexObject.getAsJsonArray("results");
205+
206+
assertEquals(limit, jsonIndexArray.size());
207+
assertEquals(limit, jsonIndexObject.get("limit").getAsInt());
208+
assert (Arrays.asList(indexUids)
209+
.contains(jsonIndexArray.get(0).getAsJsonObject().get("uid").getAsString()));
210+
}
211+
193212
/** Test deleteIndex */
194213
@Test
195214
public void testDeleteIndex() throws Exception {

0 commit comments

Comments
 (0)