-
Notifications
You must be signed in to change notification settings - Fork 128
Add support for export API #882
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
Open
ernestorbemx
wants to merge
2
commits into
meilisearch:main
Choose a base branch
from
ernestorbemx:feat/add-export-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.meilisearch.sdk; | ||
|
||
import lombok.*; | ||
import org.json.JSONObject; | ||
|
||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
@NoArgsConstructor(access = AccessLevel.PACKAGE) | ||
@Getter | ||
@Setter | ||
public class ExportIndexFilter { | ||
private String filter; | ||
@Builder.Default private boolean overrideSettings = false; | ||
|
||
/** | ||
* Method that returns the JSON String of the ExportIndexFilter | ||
* | ||
* @return JSON String of the ExportIndexFilter query | ||
*/ | ||
@Override | ||
public String toString() { | ||
JSONObject jsonObject = new JSONObject(); | ||
if (this.filter != null) { | ||
jsonObject.put("filter", this.filter); | ||
} | ||
if (this.overrideSettings) { | ||
jsonObject.put("overrideSettings", true); | ||
} | ||
|
||
return jsonObject.toString(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.meilisearch.sdk; | ||
|
||
import java.util.Map; | ||
import lombok.*; | ||
import org.json.JSONObject; | ||
|
||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
@NoArgsConstructor(access = AccessLevel.PACKAGE) | ||
@Getter | ||
@Setter | ||
public class ExportRequest { | ||
private String url; | ||
private String apiKey; | ||
private String payloadSize; | ||
private Map<String, ExportIndexFilter> indexes; | ||
|
||
/** | ||
* Method that returns the JSON String of the ExportRequest | ||
* | ||
* @return JSON String of the ExportRequest query | ||
*/ | ||
@Override | ||
public String toString() { | ||
JSONObject jsonObject = | ||
new JSONObject() | ||
.put("url", this.url) | ||
.putOpt("apiKey", this.apiKey) | ||
.putOpt("payloadSize", this.payloadSize) | ||
.putOpt("indexes", this.indexes); | ||
return jsonObject.toString(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/test/java/com/meilisearch/sdk/ExportRequestTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.meilisearch.sdk; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ExportRequestTest { | ||
|
||
@Test | ||
void toStringSimpleExportIndexFilter() { | ||
ExportIndexFilter filter = ExportIndexFilter.builder().build(); | ||
String expected = "{\"overrideSettings\":false}"; | ||
assertThat(filter.toString(), is(equalTo(expected))); | ||
assertThat(filter.getFilter(), is(nullValue())); | ||
assertThat(filter.isOverrideSettings(), is(false)); | ||
} | ||
|
||
@Test | ||
void toStringExportIndexFilterWithOverride() { | ||
ExportIndexFilter filter = ExportIndexFilter.builder().overrideSettings(true).build(); | ||
String expected = "{\"overrideSettings\":true}"; | ||
assertThat(filter.toString(), is(equalTo(expected))); | ||
assertThat(filter.isOverrideSettings(), is(true)); | ||
} | ||
|
||
@Test | ||
void toStringExportIndexFilterWithFilter() { | ||
ExportIndexFilter filter = ExportIndexFilter.builder().filter("status = 'active'").build(); | ||
String expected = "{\"filter\":\"status = 'active'\",\"overrideSettings\":false}"; | ||
assertThat(filter.toString(), is(equalTo(expected))); | ||
assertThat(filter.getFilter(), is(equalTo("status = 'active'"))); | ||
} | ||
|
||
@Test | ||
void toStringSimpleExportRequest() { | ||
ExportRequest request = | ||
ExportRequest.builder().url("http://localhost:7711").payloadSize("123 MiB").build(); | ||
JSONObject json = new JSONObject(request.toString()); | ||
assertThat(json.getString("url"), is(equalTo("http://localhost:7711"))); | ||
assertThat(json.getString("payloadSize"), is(equalTo("123 MiB"))); | ||
assertThat(json.isNull("apiKey"), is(true)); | ||
assertThat(json.isNull("indexes"), is(true)); | ||
} | ||
|
||
@Test | ||
void toStringExportRequestWithIndexes() { | ||
Map<String, ExportIndexFilter> indexes = new HashMap<>(); | ||
indexes.put("*", ExportIndexFilter.builder().overrideSettings(true).build()); | ||
|
||
ExportRequest request = | ||
ExportRequest.builder() | ||
.url("http://localhost:7711") | ||
.payloadSize("123 MiB") | ||
.indexes(indexes) | ||
.build(); | ||
|
||
String expected = | ||
"{\"url\":\"http://localhost:7711\",\"payloadSize\":\"123 MiB\",\"indexes\":{\"*\":{\"overrideSettings\":true}}}"; | ||
JSONObject expectedJson = new JSONObject(expected); | ||
JSONObject json = new JSONObject(request.toString()); | ||
|
||
assertThat(expectedJson.toString(), is(json.toString())); | ||
|
||
assertThat(json.getString("url"), is(equalTo("http://localhost:7711"))); | ||
assertThat(json.getString("payloadSize"), is(equalTo("123 MiB"))); | ||
assertThat(json.isNull("apiKey"), is(true)); | ||
JSONObject indexesJson = json.getJSONObject("indexes"); | ||
JSONObject starIndex = indexesJson.getJSONObject("*"); | ||
assertThat(starIndex.isNull("filter"), is(true)); | ||
assertThat(starIndex.getBoolean("overrideSettings"), is(true)); | ||
} | ||
|
||
@Test | ||
void gettersExportRequest() { | ||
Map<String, ExportIndexFilter> indexes = new HashMap<>(); | ||
indexes.put( | ||
"myindex", | ||
ExportIndexFilter.builder().filter("id > 10").overrideSettings(false).build()); | ||
|
||
ExportRequest request = | ||
ExportRequest.builder() | ||
.url("http://localhost:7711") | ||
.apiKey("mykey") | ||
.payloadSize("50 MiB") | ||
.indexes(indexes) | ||
.build(); | ||
|
||
assertThat(request.getUrl(), is(equalTo("http://localhost:7711"))); | ||
assertThat(request.getApiKey(), is(equalTo("mykey"))); | ||
assertThat(request.getPayloadSize(), is(equalTo("50 MiB"))); | ||
assertThat(request.getIndexes().get("myindex").getFilter(), is(equalTo("id > 10"))); | ||
assertThat(request.getIndexes().get("myindex").isOverrideSettings(), is(false)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not expose secrets in
toString()
; redactapiKey
.toString()
is frequently logged. Emitting a raw API key is a security risk.Apply this diff to redact the key:
If you need an unredacted JSON string for tests, consider adding a dedicated method like
toJson(boolean redactSecrets)
and update tests accordingly. I can draft that change and the test updates if you want.🤖 Prompt for AI Agents