Skip to content

Commit 15a56a2

Browse files
meili-bors[bot]mesutgk15dependabot[bot]
authored
Merge #689 #695
689: Support user-dictionary loading #660 r=brunoocasali a=mesutgk15 # Pull Request ## Related issue Fixes #660 ## What does this PR do? - Add a new setting as dictionary and get, update, reset methods for this setting ## 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! 695: Bump org.junit:junit-bom from 5.10.0 to 5.10.1 r=brunoocasali a=dependabot[bot] Bumps [org.junit:junit-bom](https://github.com/junit-team/junit5) from 5.10.0 to 5.10.1. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/junit-team/junit5/releases">org.junit:junit-bom's releases</a>.</em></p> <blockquote> <p>JUnit 5.10.1 = Platform 1.10.1 + Jupiter 5.10.1 + Vintage 5.10.1</p> <p>See <a href="http://junit.org/junit5/docs/5.10.1/release-notes/">Release Notes</a>.</p> <p><strong>Full Changelog</strong>: <a href="https://github.com/junit-team/junit5/compare/r5.10.0...r5.10.1">https://github.com/junit-team/junit5/compare/r5.10.0...r5.10.1</a></p> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/junit-team/junit5/commit/e5f50d8720741623915979ac154b65bcbcd6a577"><code>e5f50d8</code></a> Release 5.10.1</li> <li><a href="https://github.com/junit-team/junit5/commit/ac86d18e9b15dbebe046e82743ac7f9534a17582"><code>ac86d18</code></a> Fix typo in AfterAll documentation</li> <li><a href="https://github.com/junit-team/junit5/commit/388c5beaf42944961ab5b455c900d958a6e15588"><code>388c5be</code></a> Harmonize application of method and field filters in search algorithms</li> <li><a href="https://github.com/junit-team/junit5/commit/f82dd1e716f8717e012152b1d1d5cc0da10d33cd"><code>f82dd1e</code></a> Apply field predicate before searching type hierarchy</li> <li><a href="https://github.com/junit-team/junit5/commit/1d1eb8571552bbf28e578241965010de6c8ee779"><code>1d1eb85</code></a> Polishing</li> <li><a href="https://github.com/junit-team/junit5/commit/5ce280eff69b43759a3cb0c176207abe0a41b579"><code>5ce280e</code></a> Update picocli to 4.7.5 and enable help width computation</li> <li><a href="https://github.com/junit-team/junit5/commit/fea05c3aa80de76686f326b5ce26ddf7f153ff5a"><code>fea05c3</code></a> Fix ConsoleLauncherTests and StandaloneTests</li> <li><a href="https://github.com/junit-team/junit5/commit/c5567354c2556e772f8a0035ef7647161011d1c0"><code>c556735</code></a> Use same expected files for all JDK versions</li> <li><a href="https://github.com/junit-team/junit5/commit/808493ab09b30970b506a48fda3d616ac1ba4fff"><code>808493a</code></a> Run StandaloneTests for Java 8 under Java 8</li> <li><a href="https://github.com/junit-team/junit5/commit/9ec57661c78c3889db004ab6a89416e56a2fb2e0"><code>9ec5766</code></a> Unify messages about exit codes in StandaloneTests</li> <li>Additional commits viewable in <a href="https://github.com/junit-team/junit5/compare/r5.10.0...r5.10.1">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=org.junit:junit-bom&package-manager=gradle&previous-version=5.10.0&new-version=5.10.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) You can trigger a rebase of this PR by commenting ``@dependabot` rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - ``@dependabot` rebase` will rebase this PR - ``@dependabot` recreate` will recreate this PR, overwriting any edits that have been made to it - ``@dependabot` merge` will merge this PR after your CI passes on it - ``@dependabot` squash and merge` will squash and merge this PR after your CI passes on it - ``@dependabot` cancel merge` will cancel a previously requested merge and block automerging - ``@dependabot` reopen` will reopen this PR if it is closed - ``@dependabot` close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - ``@dependabot` show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - ``@dependabot` ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - ``@dependabot` ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - ``@dependabot` ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Co-authored-by: mesut <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
3 parents 77f894d + 9ffa4a1 + 740adf4 commit 15a56a2

File tree

6 files changed

+131
-1
lines changed

6 files changed

+131
-1
lines changed

.code-samples.meilisearch.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ update_faceting_settings_1: |-
280280
client.index("books").updateFacetingSettings(newFaceting);
281281
reset_faceting_settings_1: |-
282282
client.index("books").resetFacetingSettings();
283+
get_dictionary_1: |-
284+
client.index("books").getDictionarySettings();
285+
update_dictionary_1: |-
286+
client.index("books").updateDictionarySettings(new String[] {"J. R. R.", "W. E. B."});
287+
reset_dictionary_1: |-
288+
client.index("books").resetDictionarySettings();
283289
get_index_stats_1: |-
284290
client.index("movies").getStats();
285291
get_indexes_stats_1: |-

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies {
5656
api 'com.squareup.okhttp3:okhttp:[4.10.0,5.0.0)'
5757

5858
// Use JUnit test framework
59-
testImplementation(platform('org.junit:junit-bom:5.10.0'))
59+
testImplementation(platform('org.junit:junit-bom:5.10.1'))
6060
testImplementation('org.junit.jupiter:junit-jupiter:5.10.0')
6161
// https://mvnrepository.com/artifact/org.mockito/mockito-core
6262
testImplementation 'org.mockito:mockito-core:4.9.0'

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,43 @@ public TaskInfo resetFacetingSettings() throws MeilisearchException {
832832
return this.settingsHandler.resetFacetingSettings(this.uid);
833833
}
834834

835+
/**
836+
* Gets the dictionary settings of the index
837+
*
838+
* @return dictionary of a given uid as String
839+
* @throws MeilisearchException if an error occurs
840+
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#get-dictionary">API
841+
* specification</a>
842+
*/
843+
public String[] getDictionarySettings() throws MeilisearchException {
844+
return this.settingsHandler.getDictionarySettings(this.uid);
845+
}
846+
847+
/**
848+
* Updates the dictionary settings of the index
849+
*
850+
* @param dictionary An array of strings that contains the dictionary.
851+
* @return TaskInfo instance
852+
* @throws MeilisearchException if an error occurs
853+
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#update-dictionary">API
854+
* specification</a>
855+
*/
856+
public TaskInfo updateDictionarySettings(String[] dictionary) throws MeilisearchException {
857+
return this.settingsHandler.updateDictionarySettings(this.uid, dictionary);
858+
}
859+
860+
/**
861+
* Resets the dictionary settings of the index
862+
*
863+
* @return TaskInfo instance
864+
* @throws MeilisearchException if an error occurs
865+
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#reset-dictionary">API
866+
* specification</a>
867+
*/
868+
public TaskInfo resetDictionarySettings() throws MeilisearchException {
869+
return this.settingsHandler.resetDictionarySettings(this.uid);
870+
}
871+
835872
/**
836873
* Gets extended information and metrics about indexes and the Meilisearch database
837874
*

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,44 @@ TaskInfo resetFacetingSettings(String uid) throws MeilisearchException {
515515
settingsPath(uid).addSubroute("faceting").getURL(), TaskInfo.class);
516516
}
517517

518+
/**
519+
* Gets the dictionary settings of the index
520+
*
521+
* @param uid Index identifier
522+
* @return an array of strings that contains the dictionary
523+
* @throws MeilisearchException if an error occurs
524+
*/
525+
String[] getDictionarySettings(String uid) throws MeilisearchException {
526+
return httpClient.get(settingsPath(uid).addSubroute("dictionary").getURL(), String[].class);
527+
}
528+
529+
/**
530+
* Updates the dictionary settings of the index
531+
*
532+
* @param uid Index identifier
533+
* @param dictionary an array of strings that contains the new dictionary settings
534+
* @return TaskInfo instance
535+
* @throws MeilisearchException if an error occurs
536+
*/
537+
TaskInfo updateDictionarySettings(String uid, String[] dictionary) throws MeilisearchException {
538+
return httpClient.put(
539+
settingsPath(uid).addSubroute("dictionary").getURL(),
540+
dictionary == null ? httpClient.jsonHandler.encode(dictionary) : dictionary,
541+
TaskInfo.class);
542+
}
543+
544+
/**
545+
* Resets the dictionary settings of the index
546+
*
547+
* @param uid Index identifier
548+
* @return TaskInfo instance
549+
* @throws MeilisearchException if an error occurs
550+
*/
551+
TaskInfo resetDictionarySettings(String uid) throws MeilisearchException {
552+
return httpClient.delete(
553+
settingsPath(uid).addSubroute("dictionary").getURL(), TaskInfo.class);
554+
}
555+
518556
/** Creates an URLBuilder for the constant route settings */
519557
private URLBuilder settingsPath(String uid) {
520558
return new URLBuilder("/indexes").addSubroute(uid).addSubroute("/settings");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class Settings {
2626
protected TypoTolerance typoTolerance;
2727
protected Pagination pagination;
2828
protected Faceting faceting;
29+
protected String[] dictionary;
2930

3031
public Settings() {}
3132
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,54 @@ public void testResetFacetingSettings() throws Exception {
10571057
assertThat(facetingAfterReset.getMaxValuesPerFacet(), is(equalTo(100)));
10581058
}
10591059

1060+
/** Tests of the dictionary setting methods */
1061+
@Test
1062+
@DisplayName("Test get dictionary settings by uid")
1063+
public void testGetDictionarySettings() throws Exception {
1064+
Index index = createIndex("testGetDictionarySettings");
1065+
Settings initialSettings = index.getSettings();
1066+
String[] initialDictionary = index.getDictionarySettings();
1067+
1068+
assertThat(initialDictionary, is(arrayWithSize(initialSettings.getDictionary().length)));
1069+
assertThat(initialDictionary, is(equalTo(initialSettings.getDictionary())));
1070+
}
1071+
1072+
@Test
1073+
@DisplayName("Test update dictionary settings")
1074+
public void testUpdateDictionarySettings() throws Exception {
1075+
Index index = createIndex("testUpdateDictionarySettings");
1076+
String[] initialDictionary = index.getDictionarySettings();
1077+
String[] newDictionary = {"J. R. R.", "W. E. B."};
1078+
1079+
index.waitForTask(index.updateDictionarySettings(newDictionary).getTaskUid());
1080+
String[] updatedDictionarySettings = index.getDictionarySettings();
1081+
1082+
assertThat(updatedDictionarySettings, is(arrayWithSize(newDictionary.length)));
1083+
assertThat(updatedDictionarySettings, is(equalTo(newDictionary)));
1084+
assertThat(updatedDictionarySettings, is(not(arrayWithSize(initialDictionary.length))));
1085+
}
1086+
1087+
@Test
1088+
@DisplayName("Test reset dictionary settings")
1089+
public void testResetDictionarySettings() throws Exception {
1090+
Index index = createIndex("testResetDictionarySettings");
1091+
String[] initialDictionary = index.getDictionarySettings();
1092+
String[] newDictionary = {"J. R. R.", "W. E. B."};
1093+
1094+
index.waitForTask(index.updateDictionarySettings(newDictionary).getTaskUid());
1095+
String[] updatedDictionarySettings = index.getDictionarySettings();
1096+
1097+
index.waitForTask(index.resetDictionarySettings().getTaskUid());
1098+
String[] dictionaryAfterReset = index.getDictionarySettings();
1099+
1100+
assertThat(updatedDictionarySettings, is(arrayWithSize(newDictionary.length)));
1101+
assertThat(updatedDictionarySettings, is(equalTo(newDictionary)));
1102+
assertThat(updatedDictionarySettings, is(not(arrayWithSize(initialDictionary.length))));
1103+
assertThat(dictionaryAfterReset, is(not(arrayWithSize(updatedDictionarySettings.length))));
1104+
assertThat(dictionaryAfterReset, is(arrayWithSize(initialDictionary.length)));
1105+
assertThat(dictionaryAfterReset, is(equalTo(initialDictionary)));
1106+
}
1107+
10601108
private Index createIndex(String indexUid) throws Exception {
10611109
Index index = client.index(indexUid);
10621110
TaskInfo updateInfo = index.addDocuments(testData.getRaw());

0 commit comments

Comments
 (0)