Skip to content

Commit

Permalink
added parameter tests for builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Barabasbalazs committed Oct 31, 2024
1 parent f7476f5 commit 7207d2f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
28 changes: 15 additions & 13 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -423,19 +423,6 @@ search_parameter_guide_show_ranking_score_details_1: |-
search_parameter_reference_ranking_score_threshold_1: |-
SearchRequest searchRequest = SearchRequest.builder().q("badman").rankingScoreThreshold(0.2).build();
client.index("INDEX_NAME").search(searchRequest);
search_parameter_reference_locales_1: |-
SearchRequest searchRequest = SearchRequest.builder().q("進撃の巨人").locales(new String[]{"jpn"}).build();
client.index("INDEX_NAME").search(searchRequest);
get_localized_attribute_settings_1: |-
client.index("INDEX_NAME").getLocalizedAttributesSettings();
update_localized_attribute_settings_1: |-
client.index("INDEX_NAME").updateLocalizedAttributesSettings(
new LocalizedAttributes[] {
//this contructor not yet working
}
);
reset_localized_attribute_settings_1: |-
client.index("INDEX_NAME").resetLocalizedAttributesSettings();
synonyms_guide_1: |-
HashMap<String, String[]> synonyms = new HashMap<String, String[]>();
synonyms.put("great", new String[] {"fantastic"});
Expand Down Expand Up @@ -840,3 +827,18 @@ get_similar_post_1:
.setId("143")
.setEmbedder("manual");
client.index("movies").searchSimilarDocuments(query)
search_parameter_reference_locales_1: |-
SearchRequest searchRequest = SearchRequest.builder().q("進撃の巨人").locales(new String[]{"jpn"}).build();
client.index("INDEX_NAME").search(searchRequest);
get_localized_attribute_settings_1: |-
client.index("INDEX_NAME").getLocalizedAttributesSettings();
update_localized_attribute_settings_1: |-
LocalizedAttribute attribute = new LocalizedAttribute();
attribute.setAttributePatterns(new String[] {"jpn"});
attribute.setLocales(new String[] {"*_ja"});
client.index("INDEX_NAME").updateLocalizedAttributesSettings(
new LocalizedAttributes[] {attribute}
);
reset_localized_attribute_settings_1: |-
client.index("INDEX_NAME").resetLocalizedAttributesSettings();
4 changes: 1 addition & 3 deletions src/test/java/com/meilisearch/integration/SettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,7 @@ public void testUpdateLocalizedAttributeSettingsUsingNull() throws Exception {
index.waitForTask(index.updateLocalizedAttributesSettings(null).getTaskUid());
LocalizedAttribute[] resetLocalizedAttributes = index.getLocalizedAttributesSettings();

assertThat(
updatedLocalizedAttributes,
is(not(equalTo(initialLocalizedAttributes))));
assertThat(updatedLocalizedAttributes, is(not(equalTo(initialLocalizedAttributes))));
assertThat(
resetLocalizedAttributes,
is(not(arrayWithSize(updatedLocalizedAttributes.length))));
Expand Down
16 changes: 12 additions & 4 deletions src/test/java/com/meilisearch/sdk/SearchRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ void toStringEveryParameters() {
.setFacets(new String[] {"facets"})
.setSort(new String[] {"sort"})
.setPage(10)
.setHitsPerPage(2);
.setHitsPerPage(2)
.setLocales(new String[] {"eng"});

assertThat(classToTest.getQ(), is(equalTo("This is a Test")));
assertThat(classToTest.getOffset(), is(equalTo(200)));
Expand All @@ -153,6 +154,7 @@ void toStringEveryParameters() {
assertThat(classToTest.getCropLength(), is(equalTo(900)));
assertThat(classToTest.getPage(), is(equalTo(10)));
assertThat(classToTest.getHitsPerPage(), is(equalTo(2)));
assertThat(classToTest.getLocales()[0], is(equalTo("eng")));
}

@Test
Expand All @@ -172,6 +174,7 @@ void toStringEveryParametersWithBuilder() {
.sort(new String[] {"sort"})
.page(10)
.hitsPerPage(2)
.locales(new String[] {"eng"})
.build();

assertThat(classToTest.getQ(), is(equalTo("This is a Test")));
Expand All @@ -192,6 +195,7 @@ void toStringEveryParametersWithBuilder() {
assertThat(classToTest.getCropLength(), is(equalTo(900)));
assertThat(classToTest.getPage(), is(equalTo(10)));
assertThat(classToTest.getHitsPerPage(), is(equalTo(2)));
assertThat(classToTest.getLocales()[0], is(equalTo("eng")));
}

@Test
Expand All @@ -217,9 +221,10 @@ void toStringEveryParametersWithArray() {
.setFacets(new String[] {"facets"})
.setSort(new String[] {"sort"})
.setPage(0)
.setHitsPerPage(0);
.setHitsPerPage(0)
.setLocales(new String[] {"eng"});
String expectedToString =
"{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"hitsPerPage\":0,\"attributesToSearchOn\":[\"searchOn\"],\"sort\":[\"sort\"],\"highlightPreTag\":\"abc\",\"facets\":[\"facets\"],\"filter\":[[\"test='test'\"],[\"test1='test1'\"]],\"q\":\"This is a Test\",\"matchingStrategy\":\"all\",\"showMatchesPosition\":true,\"limit\":900,\"cropLength\":900,\"highlightPostTag\":\"zyx\",\"attributesToHighlight\":[\"highlight\"],\"page\":0,\"attributesToCrop\":[\"crop\"]}";
"{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"hitsPerPage\":0,\"attributesToSearchOn\":[\"searchOn\"],\"sort\":[\"sort\"],\"highlightPreTag\":\"abc\",\"facets\":[\"facets\"],\"filter\":[[\"test='test'\"],[\"test1='test1'\"]],\"q\":\"This is a Test\",\"locales\":[\"eng\"],\"matchingStrategy\":\"all\",\"showMatchesPosition\":true,\"limit\":900,\"cropLength\":900,\"highlightPostTag\":\"zyx\",\"attributesToHighlight\":[\"highlight\"],\"page\":0,\"attributesToCrop\":[\"crop\"]}";

assertThat(classToTest.getQ(), is(equalTo("This is a Test")));
assertThat(classToTest.getOffset(), is(equalTo(200)));
Expand All @@ -241,6 +246,7 @@ void toStringEveryParametersWithArray() {
assertThat(classToTest.getCropLength(), is(equalTo(900)));
assertThat(classToTest.getPage(), is(equalTo(0)));
assertThat(classToTest.getHitsPerPage(), is(equalTo(0)));
assertThat(classToTest.getLocales()[0], is(equalTo("eng")));
assertThat(classToTest.toString(), is(equalTo(expectedToString)));
}

Expand Down Expand Up @@ -269,9 +275,10 @@ void toStringEveryParametersWithArrayWithBuilder() {
.sort(new String[] {"sort"})
.page(0)
.hitsPerPage(0)
.locales(new String[] {"eng"})
.build();
String expectedToString =
"{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"hitsPerPage\":0,\"attributesToSearchOn\":[\"searchOn\"],\"sort\":[\"sort\"],\"highlightPreTag\":\"abc\",\"facets\":[\"facets\"],\"filter\":[[\"test='test'\"],[\"test1='test1'\"]],\"q\":\"This is a Test\",\"matchingStrategy\":\"all\",\"showMatchesPosition\":true,\"limit\":900,\"cropLength\":900,\"highlightPostTag\":\"zyx\",\"attributesToHighlight\":[\"highlight\"],\"page\":0,\"attributesToCrop\":[\"crop\"]}";
"{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"hitsPerPage\":0,\"attributesToSearchOn\":[\"searchOn\"],\"sort\":[\"sort\"],\"highlightPreTag\":\"abc\",\"facets\":[\"facets\"],\"filter\":[[\"test='test'\"],[\"test1='test1'\"]],\"q\":\"This is a Test\",\"locales\":[\"eng\"],\"matchingStrategy\":\"all\",\"showMatchesPosition\":true,\"limit\":900,\"cropLength\":900,\"highlightPostTag\":\"zyx\",\"attributesToHighlight\":[\"highlight\"],\"page\":0,\"attributesToCrop\":[\"crop\"]}";

assertThat(classToTest.getQ(), is(equalTo("This is a Test")));
assertThat(classToTest.getOffset(), is(equalTo(200)));
Expand All @@ -293,6 +300,7 @@ void toStringEveryParametersWithArrayWithBuilder() {
assertThat(classToTest.getCropLength(), is(equalTo(900)));
assertThat(classToTest.getPage(), is(equalTo(0)));
assertThat(classToTest.getHitsPerPage(), is(equalTo(0)));
assertThat(classToTest.getLocales()[0], is(equalTo("eng")));
assertThat(classToTest.toString(), is(equalTo(expectedToString)));
}

Expand Down

0 comments on commit 7207d2f

Please sign in to comment.