Skip to content
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

Support text-separator setting #740

Merged
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
14 changes: 14 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ update_faceting_settings_1: |-
client.index("books").updateFacetingSettings(newFaceting);
reset_faceting_settings_1: |-
client.index("books").resetFacetingSettings();
get_separator_tokens_1: |-
client.index("articles").getSeparatorTokensSettings();
update_separator_tokens_1: |-
String[] newSeparatorTokens = { "|", "…" };
client.index("articles").updateSeparatorTokensSettings(newSeparatorTokens);
reset_separator_tokens_1: |-
client.index("articles").resetSeparatorTokensSettings();
get_non_separator_tokens_1: |-
client.index("articles").getNonSeparatorTokensSettings();
update_non_separator_tokens_1: |-
String[] newSeparatorTokens = { "@", "#" };
client.index("articles").updateNonSeparatorTokensSettings(newSeparatorTokens);
reset_non_separator_tokens_1: |-
client.index("articles").resetNonSeparatorTokensSettings();
get_dictionary_1: |-
client.index("books").getDictionarySettings();
update_dictionary_1: |-
Expand Down
82 changes: 82 additions & 0 deletions src/main/java/com/meilisearch/sdk/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,88 @@ public TaskInfo resetDictionarySettings() throws MeilisearchException {
return this.settingsHandler.resetDictionarySettings(this.uid);
}

/**
* Gets the separator tokens of the index
*
* @return separator tokens of a given uid as String
* @throws MeilisearchException if an error occurs
* @see <a
* href="https://www.meilisearch.com/docs/reference/api/settings#get-separator-tokens">API
* specification</a>
*/
public String[] getSeparatorTokensSettings() throws MeilisearchException {
return this.settingsHandler.getSeparatorTokensSettings(this.uid);
}

/**
* Updates the separator tokens settings of the index
*
* @param separatorTokens An array of strings that contains the separator tokens.
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
* @see <a
* href="https://www.meilisearch.com/docs/reference/api/settings#update-separator-tokens">API
* specification</a>
*/
public TaskInfo updateSeparatorTokensSettings(String[] separatorTokens)
throws MeilisearchException {
return this.settingsHandler.updateSeparatorTokensSettings(this.uid, separatorTokens);
}

/**
* Resets the separator tokens settings of the index
*
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
* @see <a
* href="https://www.meilisearch.com/docs/reference/api/settings#reset-separator-tokens">API
* specification</a>
*/
public TaskInfo resetSeparatorTokensSettings() throws MeilisearchException {
return this.settingsHandler.resetSeparatorTokensSettings(this.uid);
}

/**
* Gets the non-separator tokens of the index
*
* @return non-separator tokens of a given uid as String
* @throws MeilisearchException if an error occurs
* @see <a
* href="https://www.meilisearch.com/docs/reference/api/settings#get-non-separator-tokens">API
* specification</a>
*/
public String[] getNonSeparatorTokensSettings() throws MeilisearchException {
return this.settingsHandler.getNonSeparatorTokensSettings(this.uid);
}

/**
* Updates the non-separator tokens settings of the index
*
* @param separatorTokens An array of strings that contains the non-separator tokens.
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
* @see <a
* href="https://www.meilisearch.com/docs/reference/api/settings#update-non-separator-tokens">API
* specification</a>
*/
public TaskInfo updateNonSeparatorTokensSettings(String[] separatorTokens)
throws MeilisearchException {
return this.settingsHandler.updateNonSeparatorTokensSettings(this.uid, separatorTokens);
}

/**
* Resets the non-separator tokens settings of the index
*
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
* @see <a
* href="https://www.meilisearch.com/docs/reference/api/settings#reset-non-separator-tokens">API
* specification</a>
*/
public TaskInfo resetNonSeparatorTokensSettings() throws MeilisearchException {
return this.settingsHandler.resetNonSeparatorTokensSettings(this.uid);
}

/**
* Gets the proximity precision level of the index
*
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/com/meilisearch/sdk/SettingsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,84 @@ TaskInfo resetSearchCutoffMsSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("search-cutoff-ms").getURL(), TaskInfo.class);
}

/**
* Gets the separator tokens of the index
*
* @param uid Index identifier
* @return separator tokens of a given uid as String
* @throws MeilisearchException if an error occurs
*/
public String[] getSeparatorTokensSettings(String uid) {
return httpClient.get(
settingsPath(uid).addSubroute("separator-tokens").getURL(), String[].class);
}

/**
* Updates the separator tokens settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
public TaskInfo updateSeparatorTokensSettings(String uid, String[] separatorTokens) {
return httpClient.put(
settingsPath(uid).addSubroute("separator-tokens").getURL(),
separatorTokens == null
? httpClient.jsonHandler.encode(separatorTokens)
: separatorTokens,
TaskInfo.class);
}

/**
* Resets the separator tokens settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
public TaskInfo resetSeparatorTokensSettings(String uid) {
return httpClient.delete(
settingsPath(uid).addSubroute("separator-tokens").getURL(), TaskInfo.class);
}

/**
* Gets the non-separator tokens of the index
*
* @param uid Index identifier
* @return non-separator tokens of a given uid as String
* @throws MeilisearchException if an error occurs
*/
public String[] getNonSeparatorTokensSettings(String uid) {
return httpClient.get(
settingsPath(uid).addSubroute("non-separator-tokens").getURL(), String[].class);
}

/**
* Updates the non-separator tokens settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
public TaskInfo updateNonSeparatorTokensSettings(String uid, String[] separatorTokens) {
return httpClient.put(
settingsPath(uid).addSubroute("non-separator-tokens").getURL(),
separatorTokens == null
? httpClient.jsonHandler.encode(separatorTokens)
: separatorTokens,
TaskInfo.class);
}

/**
* Resets the non-separator tokens settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
public TaskInfo resetNonSeparatorTokensSettings(String uid) {
return httpClient.delete(
settingsPath(uid).addSubroute("non-separator-tokens").getURL(), TaskInfo.class);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/meilisearch/sdk/model/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Settings {
protected String[] dictionary;
protected String proximityPrecision;
protected Integer searchCutoffMs;
protected String[] separatorTokens;
protected String[] nonSeparatorTokens;

public Settings() {}
}
127 changes: 127 additions & 0 deletions src/test/java/com/meilisearch/integration/SettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1194,4 +1194,131 @@ private Index createIndex(String indexUid) throws Exception {

return index;
}

/** Tests of the separator tokens setting methods */
@Test
@DisplayName("Test get separator tokens settings by uid")
public void testGetSeparatorTokensSettings() throws Exception {
Index index = createIndex("testGetSeparatorTokensSettings");
Settings initialSettings = index.getSettings();
String[] initialSeparatorTokens = index.getSeparatorTokensSettings();

assertThat(
initialSeparatorTokens,
is(arrayWithSize(initialSettings.getSeparatorTokens().length)));
assertThat(initialSeparatorTokens, is(equalTo(initialSettings.getSeparatorTokens())));
}

@Test
@DisplayName("Test update separator tokens settings")
public void testUpdateSeparatorTokensSettings() throws Exception {
Index index = createIndex("testUpdateSeparatorTokensSettings");
String[] initialSeparatorTokens = index.getSeparatorTokensSettings();

String[] newSeparatorTokens = {"|", "&hellip;"};

index.waitForTask(index.updateSeparatorTokensSettings(newSeparatorTokens).getTaskUid());
String[] updatedSeparatorTokens = index.getSeparatorTokensSettings();

Arrays.sort(newSeparatorTokens);
Arrays.sort(updatedSeparatorTokens);

assertThat(updatedSeparatorTokens, is(arrayWithSize(newSeparatorTokens.length)));
assertThat(updatedSeparatorTokens, is(equalTo(newSeparatorTokens)));
assertThat(updatedSeparatorTokens, is(not(arrayWithSize(initialSeparatorTokens.length))));
}

@Test
@DisplayName("Test reset separator tokens settings")
public void testResetSeparatorTokensSettings() throws Exception {
Index index = createIndex("testResetSeparatorTokensSettings");
String[] initialSeparatorTokens = index.getSeparatorTokensSettings();
String[] newSeparatorTokens = {"|", "&hellip;"};

index.waitForTask(index.updateSeparatorTokensSettings(newSeparatorTokens).getTaskUid());
String[] updatedSeparatorTokens = index.getSeparatorTokensSettings();

index.waitForTask(index.resetSeparatorTokensSettings().getTaskUid());
String[] separatorTokensAfterReset = index.getSeparatorTokensSettings();

Arrays.sort(initialSeparatorTokens);
Arrays.sort(newSeparatorTokens);
Arrays.sort(updatedSeparatorTokens);
Arrays.sort(separatorTokensAfterReset);

assertThat(updatedSeparatorTokens, is(arrayWithSize(newSeparatorTokens.length)));
assertThat(updatedSeparatorTokens, is(equalTo(newSeparatorTokens)));
assertThat(updatedSeparatorTokens, is(not(arrayWithSize(initialSeparatorTokens.length))));
assertThat(
separatorTokensAfterReset, is(not(arrayWithSize(updatedSeparatorTokens.length))));
assertThat(separatorTokensAfterReset, is(arrayWithSize(initialSeparatorTokens.length)));
assertThat(separatorTokensAfterReset, is(equalTo(initialSeparatorTokens)));
}

/** Tests of the non-separator tokens setting methods */
@Test
@DisplayName("Test get non-separator tokens settings by uid")
public void testGetNonSeparatorTokensSettings() throws Exception {
Index index = createIndex("testGetNonSeparatorTokensSettings");
Settings initialSettings = index.getSettings();
String[] initialNonSeparatorTokens = index.getNonSeparatorTokensSettings();

assertThat(
initialNonSeparatorTokens,
is(arrayWithSize(initialSettings.getNonSeparatorTokens().length)));
assertThat(initialNonSeparatorTokens, is(equalTo(initialSettings.getNonSeparatorTokens())));
}

@Test
@DisplayName("Test update non-separator tokens settings")
public void testUpdateNonSeparatorTokensSettings() throws Exception {
Index index = createIndex("testUpdateNonSeparatorTokensSettings");
String[] initialNonSeparatorTokens = index.getNonSeparatorTokensSettings();
String[] newNonSeparatorTokens = {"@", "#"};

index.waitForTask(
index.updateNonSeparatorTokensSettings(newNonSeparatorTokens).getTaskUid());
String[] updatedNonSeparatorTokens = index.getNonSeparatorTokensSettings();

Arrays.sort(newNonSeparatorTokens);
Arrays.sort(updatedNonSeparatorTokens);

assertThat(updatedNonSeparatorTokens, is(arrayWithSize(newNonSeparatorTokens.length)));
assertThat(updatedNonSeparatorTokens, is(equalTo(newNonSeparatorTokens)));
assertThat(
updatedNonSeparatorTokens,
is(not(arrayWithSize(initialNonSeparatorTokens.length))));
}

@Test
@DisplayName("Test reset non-separator tokens settings")
public void testResetNonSeparatorTokensSettings() throws Exception {
Index index = createIndex("testResetNonSeparatorTokensSettings");
String[] initialNonSeparatorTokens = index.getNonSeparatorTokensSettings();
String[] newNonSeparatorTokens = {"@", "#"};

index.waitForTask(
index.updateNonSeparatorTokensSettings(newNonSeparatorTokens).getTaskUid());
String[] updatedNonSeparatorTokens = index.getNonSeparatorTokensSettings();

index.waitForTask(index.resetNonSeparatorTokensSettings().getTaskUid());
String[] nonSeparatorTokensAfterReset = index.getNonSeparatorTokensSettings();

Arrays.sort(initialNonSeparatorTokens);
Arrays.sort(newNonSeparatorTokens);
Arrays.sort(updatedNonSeparatorTokens);
Arrays.sort(nonSeparatorTokensAfterReset);

assertThat(updatedNonSeparatorTokens, is(arrayWithSize(newNonSeparatorTokens.length)));
assertThat(updatedNonSeparatorTokens, is(equalTo(newNonSeparatorTokens)));
assertThat(
updatedNonSeparatorTokens,
is(not(arrayWithSize(initialNonSeparatorTokens.length))));
assertThat(
nonSeparatorTokensAfterReset,
is(not(arrayWithSize(updatedNonSeparatorTokens.length))));
assertThat(
nonSeparatorTokensAfterReset, is(arrayWithSize(initialNonSeparatorTokens.length)));
assertThat(nonSeparatorTokensAfterReset, is(equalTo(initialNonSeparatorTokens)));
}
}
Loading