Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/com/meilisearch/sdk/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/meilisearch/sdk/IndexesHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Results<Index> 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
*/
Expand All @@ -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
*
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/meilisearch/integration/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down