Skip to content

Commit f331526

Browse files
Merge #740
740: Support text-separator setting r=curquiza a=the-sinner # Pull Request ## Related issue Fixes #659 ## What does this PR do? - Support text-separator customization ## 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: Shalabh Agarwal <[email protected]>
2 parents be299c4 + 8495893 commit f331526

File tree

5 files changed

+305
-0
lines changed

5 files changed

+305
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,20 @@ update_faceting_settings_1: |-
286286
client.index("books").updateFacetingSettings(newFaceting);
287287
reset_faceting_settings_1: |-
288288
client.index("books").resetFacetingSettings();
289+
get_separator_tokens_1: |-
290+
client.index("articles").getSeparatorTokensSettings();
291+
update_separator_tokens_1: |-
292+
String[] newSeparatorTokens = { "|", "&hellip;" };
293+
client.index("articles").updateSeparatorTokensSettings(newSeparatorTokens);
294+
reset_separator_tokens_1: |-
295+
client.index("articles").resetSeparatorTokensSettings();
296+
get_non_separator_tokens_1: |-
297+
client.index("articles").getNonSeparatorTokensSettings();
298+
update_non_separator_tokens_1: |-
299+
String[] newSeparatorTokens = { "@", "#" };
300+
client.index("articles").updateNonSeparatorTokensSettings(newSeparatorTokens);
301+
reset_non_separator_tokens_1: |-
302+
client.index("articles").resetNonSeparatorTokensSettings();
289303
get_dictionary_1: |-
290304
client.index("books").getDictionarySettings();
291305
update_dictionary_1: |-

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,88 @@ public TaskInfo resetDictionarySettings() throws MeilisearchException {
947947
return this.settingsHandler.resetDictionarySettings(this.uid);
948948
}
949949

950+
/**
951+
* Gets the separator tokens of the index
952+
*
953+
* @return separator tokens of a given uid as String
954+
* @throws MeilisearchException if an error occurs
955+
* @see <a
956+
* href="https://www.meilisearch.com/docs/reference/api/settings#get-separator-tokens">API
957+
* specification</a>
958+
*/
959+
public String[] getSeparatorTokensSettings() throws MeilisearchException {
960+
return this.settingsHandler.getSeparatorTokensSettings(this.uid);
961+
}
962+
963+
/**
964+
* Updates the separator tokens settings of the index
965+
*
966+
* @param separatorTokens An array of strings that contains the separator tokens.
967+
* @return TaskInfo instance
968+
* @throws MeilisearchException if an error occurs
969+
* @see <a
970+
* href="https://www.meilisearch.com/docs/reference/api/settings#update-separator-tokens">API
971+
* specification</a>
972+
*/
973+
public TaskInfo updateSeparatorTokensSettings(String[] separatorTokens)
974+
throws MeilisearchException {
975+
return this.settingsHandler.updateSeparatorTokensSettings(this.uid, separatorTokens);
976+
}
977+
978+
/**
979+
* Resets the separator tokens settings of the index
980+
*
981+
* @return TaskInfo instance
982+
* @throws MeilisearchException if an error occurs
983+
* @see <a
984+
* href="https://www.meilisearch.com/docs/reference/api/settings#reset-separator-tokens">API
985+
* specification</a>
986+
*/
987+
public TaskInfo resetSeparatorTokensSettings() throws MeilisearchException {
988+
return this.settingsHandler.resetSeparatorTokensSettings(this.uid);
989+
}
990+
991+
/**
992+
* Gets the non-separator tokens of the index
993+
*
994+
* @return non-separator tokens of a given uid as String
995+
* @throws MeilisearchException if an error occurs
996+
* @see <a
997+
* href="https://www.meilisearch.com/docs/reference/api/settings#get-non-separator-tokens">API
998+
* specification</a>
999+
*/
1000+
public String[] getNonSeparatorTokensSettings() throws MeilisearchException {
1001+
return this.settingsHandler.getNonSeparatorTokensSettings(this.uid);
1002+
}
1003+
1004+
/**
1005+
* Updates the non-separator tokens settings of the index
1006+
*
1007+
* @param separatorTokens An array of strings that contains the non-separator tokens.
1008+
* @return TaskInfo instance
1009+
* @throws MeilisearchException if an error occurs
1010+
* @see <a
1011+
* href="https://www.meilisearch.com/docs/reference/api/settings#update-non-separator-tokens">API
1012+
* specification</a>
1013+
*/
1014+
public TaskInfo updateNonSeparatorTokensSettings(String[] separatorTokens)
1015+
throws MeilisearchException {
1016+
return this.settingsHandler.updateNonSeparatorTokensSettings(this.uid, separatorTokens);
1017+
}
1018+
1019+
/**
1020+
* Resets the non-separator tokens settings of the index
1021+
*
1022+
* @return TaskInfo instance
1023+
* @throws MeilisearchException if an error occurs
1024+
* @see <a
1025+
* href="https://www.meilisearch.com/docs/reference/api/settings#reset-non-separator-tokens">API
1026+
* specification</a>
1027+
*/
1028+
public TaskInfo resetNonSeparatorTokensSettings() throws MeilisearchException {
1029+
return this.settingsHandler.resetNonSeparatorTokensSettings(this.uid);
1030+
}
1031+
9501032
/**
9511033
* Gets the proximity precision level of the index
9521034
*

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,84 @@ TaskInfo resetSearchCutoffMsSettings(String uid) throws MeilisearchException {
644644
return httpClient.delete(
645645
settingsPath(uid).addSubroute("search-cutoff-ms").getURL(), TaskInfo.class);
646646
}
647+
648+
/**
649+
* Gets the separator tokens of the index
650+
*
651+
* @param uid Index identifier
652+
* @return separator tokens of a given uid as String
653+
* @throws MeilisearchException if an error occurs
654+
*/
655+
public String[] getSeparatorTokensSettings(String uid) {
656+
return httpClient.get(
657+
settingsPath(uid).addSubroute("separator-tokens").getURL(), String[].class);
658+
}
659+
660+
/**
661+
* Updates the separator tokens settings of the index
662+
*
663+
* @param uid Index identifier
664+
* @return TaskInfo instance
665+
* @throws MeilisearchException if an error occurs
666+
*/
667+
public TaskInfo updateSeparatorTokensSettings(String uid, String[] separatorTokens) {
668+
return httpClient.put(
669+
settingsPath(uid).addSubroute("separator-tokens").getURL(),
670+
separatorTokens == null
671+
? httpClient.jsonHandler.encode(separatorTokens)
672+
: separatorTokens,
673+
TaskInfo.class);
674+
}
675+
676+
/**
677+
* Resets the separator tokens settings of the index
678+
*
679+
* @param uid Index identifier
680+
* @return TaskInfo instance
681+
* @throws MeilisearchException if an error occurs
682+
*/
683+
public TaskInfo resetSeparatorTokensSettings(String uid) {
684+
return httpClient.delete(
685+
settingsPath(uid).addSubroute("separator-tokens").getURL(), TaskInfo.class);
686+
}
687+
688+
/**
689+
* Gets the non-separator tokens of the index
690+
*
691+
* @param uid Index identifier
692+
* @return non-separator tokens of a given uid as String
693+
* @throws MeilisearchException if an error occurs
694+
*/
695+
public String[] getNonSeparatorTokensSettings(String uid) {
696+
return httpClient.get(
697+
settingsPath(uid).addSubroute("non-separator-tokens").getURL(), String[].class);
698+
}
699+
700+
/**
701+
* Updates the non-separator tokens settings of the index
702+
*
703+
* @param uid Index identifier
704+
* @return TaskInfo instance
705+
* @throws MeilisearchException if an error occurs
706+
*/
707+
public TaskInfo updateNonSeparatorTokensSettings(String uid, String[] separatorTokens) {
708+
return httpClient.put(
709+
settingsPath(uid).addSubroute("non-separator-tokens").getURL(),
710+
separatorTokens == null
711+
? httpClient.jsonHandler.encode(separatorTokens)
712+
: separatorTokens,
713+
TaskInfo.class);
714+
}
715+
716+
/**
717+
* Resets the non-separator tokens settings of the index
718+
*
719+
* @param uid Index identifier
720+
* @return TaskInfo instance
721+
* @throws MeilisearchException if an error occurs
722+
*/
723+
public TaskInfo resetNonSeparatorTokensSettings(String uid) {
724+
return httpClient.delete(
725+
settingsPath(uid).addSubroute("non-separator-tokens").getURL(), TaskInfo.class);
726+
}
647727
}

src/main/java/com/meilisearch/sdk/model/Settings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class Settings {
2929
protected String[] dictionary;
3030
protected String proximityPrecision;
3131
protected Integer searchCutoffMs;
32+
protected String[] separatorTokens;
33+
protected String[] nonSeparatorTokens;
3234

3335
public Settings() {}
3436
}

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

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,4 +1194,131 @@ private Index createIndex(String indexUid) throws Exception {
11941194

11951195
return index;
11961196
}
1197+
1198+
/** Tests of the separator tokens setting methods */
1199+
@Test
1200+
@DisplayName("Test get separator tokens settings by uid")
1201+
public void testGetSeparatorTokensSettings() throws Exception {
1202+
Index index = createIndex("testGetSeparatorTokensSettings");
1203+
Settings initialSettings = index.getSettings();
1204+
String[] initialSeparatorTokens = index.getSeparatorTokensSettings();
1205+
1206+
assertThat(
1207+
initialSeparatorTokens,
1208+
is(arrayWithSize(initialSettings.getSeparatorTokens().length)));
1209+
assertThat(initialSeparatorTokens, is(equalTo(initialSettings.getSeparatorTokens())));
1210+
}
1211+
1212+
@Test
1213+
@DisplayName("Test update separator tokens settings")
1214+
public void testUpdateSeparatorTokensSettings() throws Exception {
1215+
Index index = createIndex("testUpdateSeparatorTokensSettings");
1216+
String[] initialSeparatorTokens = index.getSeparatorTokensSettings();
1217+
1218+
String[] newSeparatorTokens = {"|", "&hellip;"};
1219+
1220+
index.waitForTask(index.updateSeparatorTokensSettings(newSeparatorTokens).getTaskUid());
1221+
String[] updatedSeparatorTokens = index.getSeparatorTokensSettings();
1222+
1223+
Arrays.sort(newSeparatorTokens);
1224+
Arrays.sort(updatedSeparatorTokens);
1225+
1226+
assertThat(updatedSeparatorTokens, is(arrayWithSize(newSeparatorTokens.length)));
1227+
assertThat(updatedSeparatorTokens, is(equalTo(newSeparatorTokens)));
1228+
assertThat(updatedSeparatorTokens, is(not(arrayWithSize(initialSeparatorTokens.length))));
1229+
}
1230+
1231+
@Test
1232+
@DisplayName("Test reset separator tokens settings")
1233+
public void testResetSeparatorTokensSettings() throws Exception {
1234+
Index index = createIndex("testResetSeparatorTokensSettings");
1235+
String[] initialSeparatorTokens = index.getSeparatorTokensSettings();
1236+
String[] newSeparatorTokens = {"|", "&hellip;"};
1237+
1238+
index.waitForTask(index.updateSeparatorTokensSettings(newSeparatorTokens).getTaskUid());
1239+
String[] updatedSeparatorTokens = index.getSeparatorTokensSettings();
1240+
1241+
index.waitForTask(index.resetSeparatorTokensSettings().getTaskUid());
1242+
String[] separatorTokensAfterReset = index.getSeparatorTokensSettings();
1243+
1244+
Arrays.sort(initialSeparatorTokens);
1245+
Arrays.sort(newSeparatorTokens);
1246+
Arrays.sort(updatedSeparatorTokens);
1247+
Arrays.sort(separatorTokensAfterReset);
1248+
1249+
assertThat(updatedSeparatorTokens, is(arrayWithSize(newSeparatorTokens.length)));
1250+
assertThat(updatedSeparatorTokens, is(equalTo(newSeparatorTokens)));
1251+
assertThat(updatedSeparatorTokens, is(not(arrayWithSize(initialSeparatorTokens.length))));
1252+
assertThat(
1253+
separatorTokensAfterReset, is(not(arrayWithSize(updatedSeparatorTokens.length))));
1254+
assertThat(separatorTokensAfterReset, is(arrayWithSize(initialSeparatorTokens.length)));
1255+
assertThat(separatorTokensAfterReset, is(equalTo(initialSeparatorTokens)));
1256+
}
1257+
1258+
/** Tests of the non-separator tokens setting methods */
1259+
@Test
1260+
@DisplayName("Test get non-separator tokens settings by uid")
1261+
public void testGetNonSeparatorTokensSettings() throws Exception {
1262+
Index index = createIndex("testGetNonSeparatorTokensSettings");
1263+
Settings initialSettings = index.getSettings();
1264+
String[] initialNonSeparatorTokens = index.getNonSeparatorTokensSettings();
1265+
1266+
assertThat(
1267+
initialNonSeparatorTokens,
1268+
is(arrayWithSize(initialSettings.getNonSeparatorTokens().length)));
1269+
assertThat(initialNonSeparatorTokens, is(equalTo(initialSettings.getNonSeparatorTokens())));
1270+
}
1271+
1272+
@Test
1273+
@DisplayName("Test update non-separator tokens settings")
1274+
public void testUpdateNonSeparatorTokensSettings() throws Exception {
1275+
Index index = createIndex("testUpdateNonSeparatorTokensSettings");
1276+
String[] initialNonSeparatorTokens = index.getNonSeparatorTokensSettings();
1277+
String[] newNonSeparatorTokens = {"@", "#"};
1278+
1279+
index.waitForTask(
1280+
index.updateNonSeparatorTokensSettings(newNonSeparatorTokens).getTaskUid());
1281+
String[] updatedNonSeparatorTokens = index.getNonSeparatorTokensSettings();
1282+
1283+
Arrays.sort(newNonSeparatorTokens);
1284+
Arrays.sort(updatedNonSeparatorTokens);
1285+
1286+
assertThat(updatedNonSeparatorTokens, is(arrayWithSize(newNonSeparatorTokens.length)));
1287+
assertThat(updatedNonSeparatorTokens, is(equalTo(newNonSeparatorTokens)));
1288+
assertThat(
1289+
updatedNonSeparatorTokens,
1290+
is(not(arrayWithSize(initialNonSeparatorTokens.length))));
1291+
}
1292+
1293+
@Test
1294+
@DisplayName("Test reset non-separator tokens settings")
1295+
public void testResetNonSeparatorTokensSettings() throws Exception {
1296+
Index index = createIndex("testResetNonSeparatorTokensSettings");
1297+
String[] initialNonSeparatorTokens = index.getNonSeparatorTokensSettings();
1298+
String[] newNonSeparatorTokens = {"@", "#"};
1299+
1300+
index.waitForTask(
1301+
index.updateNonSeparatorTokensSettings(newNonSeparatorTokens).getTaskUid());
1302+
String[] updatedNonSeparatorTokens = index.getNonSeparatorTokensSettings();
1303+
1304+
index.waitForTask(index.resetNonSeparatorTokensSettings().getTaskUid());
1305+
String[] nonSeparatorTokensAfterReset = index.getNonSeparatorTokensSettings();
1306+
1307+
Arrays.sort(initialNonSeparatorTokens);
1308+
Arrays.sort(newNonSeparatorTokens);
1309+
Arrays.sort(updatedNonSeparatorTokens);
1310+
Arrays.sort(nonSeparatorTokensAfterReset);
1311+
1312+
assertThat(updatedNonSeparatorTokens, is(arrayWithSize(newNonSeparatorTokens.length)));
1313+
assertThat(updatedNonSeparatorTokens, is(equalTo(newNonSeparatorTokens)));
1314+
assertThat(
1315+
updatedNonSeparatorTokens,
1316+
is(not(arrayWithSize(initialNonSeparatorTokens.length))));
1317+
assertThat(
1318+
nonSeparatorTokensAfterReset,
1319+
is(not(arrayWithSize(updatedNonSeparatorTokens.length))));
1320+
assertThat(
1321+
nonSeparatorTokensAfterReset, is(arrayWithSize(initialNonSeparatorTokens.length)));
1322+
assertThat(nonSeparatorTokensAfterReset, is(equalTo(initialNonSeparatorTokens)));
1323+
}
11971324
}

0 commit comments

Comments
 (0)