diff --git a/src/main/java/com/meilisearch/sdk/Client.java b/src/main/java/com/meilisearch/sdk/Client.java index 1ca76f31..33d624a7 100644 --- a/src/main/java/com/meilisearch/sdk/Client.java +++ b/src/main/java/com/meilisearch/sdk/Client.java @@ -109,6 +109,17 @@ public String getRawIndexes() throws MeilisearchException { return this.indexesHandler.getRawIndexes(); } + /** + * Gets all indexes https://docs.meilisearch.com/reference/api/indexes.html#list-all-indexes + * + * @param params query parameters accepted by the get indexes route + * @return List of indexes from the Meilisearch API as String + * @throws MeilisearchException if an error occurs + */ + public String getRawIndexes(IndexesQuery params) throws MeilisearchException { + return this.indexesHandler.getRawIndexes(params); + } + /** * Creates a local reference to an index identified by `uid`, without doing an HTTP call. * Calling this method doesn't create an index by itself, but grants access to all the other diff --git a/src/main/java/com/meilisearch/sdk/IndexesHandler.java b/src/main/java/com/meilisearch/sdk/IndexesHandler.java index d999f39d..c61c3edc 100644 --- a/src/main/java/com/meilisearch/sdk/IndexesHandler.java +++ b/src/main/java/com/meilisearch/sdk/IndexesHandler.java @@ -76,7 +76,7 @@ Results getIndexes() throws MeilisearchException { /** * Gets indexes in the current Meilisearch instance * - * @param query parameters accepted by the indexes route + * @param params parameters accepted by the indexes route * @return Results containing a list of indexes * @throws MeilisearchException if an error occurs */ @@ -95,6 +95,17 @@ String getRawIndexes() throws MeilisearchException { return httpClient.get(indexesPath().getURL(), String.class); } + /** + * Gets indexes in the current Meilisearch instance + * + * @param params parameters accepted by the indexes route + * @return List of indexes as String + * @throws MeilisearchException if an error occurs + */ + String getRawIndexes(IndexesQuery params) throws MeilisearchException { + return httpClient.get(indexesPath().addQuery(params.toQuery()).getURL(), String.class); + } + /** * Updates the primary key of an index in the Meilisearch instance * diff --git a/src/test/java/com/meilisearch/integration/ClientTest.java b/src/test/java/com/meilisearch/integration/ClientTest.java index a9561e36..d867f152 100644 --- a/src/test/java/com/meilisearch/integration/ClientTest.java +++ b/src/test/java/com/meilisearch/integration/ClientTest.java @@ -190,6 +190,25 @@ public void testGetRawIndexes() throws Exception { .contains(jsonIndexArray.get(1).getAsJsonObject().get("uid").getAsString())); } + /** Test getRawIndexes with limits */ + @Test + public void testGetRawIndexesLimit() throws Exception { + int limit = 1; + String[] indexUids = {"GetRawIndexes", "GetRawIndexes2"}; + createEmptyIndex(indexUids[0]); + createEmptyIndex(indexUids[1], this.primaryKey); + IndexesQuery query = new IndexesQuery().setLimit(limit); + + String indexes = client.getRawIndexes(query); + JsonObject jsonIndexObject = JsonParser.parseString(indexes).getAsJsonObject(); + JsonArray jsonIndexArray = jsonIndexObject.getAsJsonArray("results"); + + assertEquals(limit, jsonIndexArray.size()); + assertEquals(limit, jsonIndexObject.get("limit").getAsInt()); + assert (Arrays.asList(indexUids) + .contains(jsonIndexArray.get(0).getAsJsonObject().get("uid").getAsString())); + } + /** Test deleteIndex */ @Test public void testDeleteIndex() throws Exception {