From 05f69c221873d4b8e000ab7f75e5a8b2f0816e4e Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Mon, 29 Aug 2022 19:59:46 +0200 Subject: [PATCH 1/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 170c5bb3..412b1606 100644 --- a/README.md +++ b/README.md @@ -330,7 +330,7 @@ requestFactory.create(HttpMethod.GET, "/health", Collections.emptyMap(), {"id":" ## 🤖 Compatibility with Meilisearch -This package only guarantees compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0). +This package only guarantees compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0). ## 💡 Learn More From ecc083986917f3ed23faf009fe2b99b22193b72b Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 2 Feb 2023 17:26:13 +0100 Subject: [PATCH 2/7] Add changes for compatibility with v0.29.0 --- .github/workflows/tests.yml | 4 ++-- .../com/meilisearch/sdk/SearchRequest.java | 10 ++++++++++ .../com/meilisearch/integration/KeysTest.java | 20 +++++++++++++++++++ .../meilisearch/integration/SearchTest.java | 17 ++++++++++++++++ .../meilisearch/sdk/SearchRequestTest.java | 3 ++- 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6b59e0e9..848b885a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,8 +26,8 @@ jobs: cache: gradle - name: Grant execute permission for gradlew run: chmod +x gradlew - - name: Meilisearch (v0.28.1 version) setup with Docker - run: docker run -d -p 7700:7700 getmeili/meilisearch:v0.28.1 meilisearch --no-analytics --master-key='masterKey' + - name: Meilisearch (v0.29.3 version) setup with Docker + run: docker run -d -p 7700:7700 getmeili/meilisearch:v0.29.3 meilisearch --no-analytics --master-key='masterKey' - name: Build and run unit and integration tests run: ./gradlew build integrationTest - name: Archive test report diff --git a/src/main/java/com/meilisearch/sdk/SearchRequest.java b/src/main/java/com/meilisearch/sdk/SearchRequest.java index a6a0f4b2..769fbbf3 100644 --- a/src/main/java/com/meilisearch/sdk/SearchRequest.java +++ b/src/main/java/com/meilisearch/sdk/SearchRequest.java @@ -19,6 +19,7 @@ public class SearchRequest { private String cropMarker; private String highlightPreTag; private String highlightPostTag; + private String matchingStrategy; private String[] attributesToHighlight; private String[] filter; private String[][] filterArray; @@ -132,6 +133,7 @@ public SearchRequest( null, null, null, + null, attributesToHighlight, filter, null, @@ -184,6 +186,7 @@ public SearchRequest( cropMarker, highlightPreTag, highlightPostTag, + null, attributesToHighlight, filter, null, @@ -230,6 +233,7 @@ public SearchRequest( null, null, null, + null, attributesToHighlight, null, filterArray, @@ -250,6 +254,7 @@ public SearchRequest( * @param cropMarker String to customize default crop marker, default value: … * @param highlightPreTag String to customize highlight tag before every highlighted query terms * @param highlightPostTag String to customize highlight tag after every highlighted query terms + * @param matchingStrategy String to defines the strategy used to match query terms in documents * @param attributesToHighlight Attributes whose values will contain highlighted matching terms * @param filterArray String array that can take multiple nested filters * @param showMatchesPosition Defines whether an object that contains information about the @@ -267,6 +272,7 @@ public SearchRequest( String cropMarker, String highlightPreTag, String highlightPostTag, + String matchingStrategy, String[] attributesToHighlight, String[][] filterArray, boolean showMatchesPosition, @@ -282,6 +288,7 @@ public SearchRequest( cropMarker, highlightPreTag, highlightPostTag, + matchingStrategy, attributesToHighlight, null, filterArray, @@ -300,6 +307,7 @@ private SearchRequest( String cropMarker, String highlightPreTag, String highlightPostTag, + String matchingStrategy, String[] attributesToHighlight, String[] filter, String[][] filterArray, @@ -315,6 +323,7 @@ private SearchRequest( this.cropMarker = cropMarker; this.highlightPreTag = highlightPreTag; this.highlightPostTag = highlightPostTag; + this.matchingStrategy = matchingStrategy; this.attributesToHighlight = attributesToHighlight; this.setFilter(filter); this.setFilterArray(filterArray); @@ -352,6 +361,7 @@ public String toString() { .put("cropMarker", this.cropMarker) .put("highlightPreTag", this.highlightPreTag) .put("highlightPostTag", this.highlightPostTag) + .put("matchingStrategy", this.matchingStrategy) .put("showMatchesPosition", this.showMatchesPosition) .put("facets", this.facets) .put("sort", this.sort) diff --git a/src/test/java/com/meilisearch/integration/KeysTest.java b/src/test/java/com/meilisearch/integration/KeysTest.java index a2c3d4b6..18a071cb 100644 --- a/src/test/java/com/meilisearch/integration/KeysTest.java +++ b/src/test/java/com/meilisearch/integration/KeysTest.java @@ -222,6 +222,26 @@ public void testClientCreateKeyWithExpirationDate() throws Exception { assertNotNull(key.getUpdatedAt()); } + /** Test Create an API Key with wildcarded action */ + @Test + public void testClientCreateKeyWithWilcardedAction() throws Exception { + Key keyInfo = new Key(); + keyInfo.setIndexes(new String[] {"*"}); + keyInfo.setActions(new String[] {"documents.*"}); + keyInfo.setExpiresAt(null); + + Key key = client.createKey(keyInfo); + + assertTrue(key instanceof Key); + assertNotNull(key.getKey()); + assertEquals("documents.*", key.getActions()[0]); + assertEquals("*", key.getIndexes()[0]); + assertNull(key.getDescription()); + assertNull(key.getExpiresAt()); + assertNotNull(key.getCreatedAt()); + assertNotNull(key.getUpdatedAt()); + } + /** Test Update an API Key */ @Test public void testClientUpdateKey() throws Exception { diff --git a/src/test/java/com/meilisearch/integration/SearchTest.java b/src/test/java/com/meilisearch/integration/SearchTest.java index 6ef50659..f6a97bfc 100644 --- a/src/test/java/com/meilisearch/integration/SearchTest.java +++ b/src/test/java/com/meilisearch/integration/SearchTest.java @@ -457,6 +457,7 @@ public void testSearchMatches() throws Exception { assertEquals(20, searchResult.getHits().size()); } + /** Test place holder search */ @Test public void testPlaceHolder() throws Exception { @@ -486,4 +487,20 @@ public void testPlaceHolderWithLimit() throws Exception { assertEquals(10, searchResult.getHits().size()); } + + /** Test search matchingStrategy */ + @Test + public void testSearchMatchingStrategy() throws Exception { + String indexUid = "SearchMatchingStrategy"; + Index index = client.index(indexUid); + + TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); + TaskInfo task = index.addDocuments(testData.getRaw()); + + index.waitForTask(task.getTaskUid()); + SearchRequest searchRequest = new SearchRequest("and").setMatchingStrategy("all"); + SearchResult searchResult = index.search(searchRequest); + + assertEquals(20, searchResult.getHits().size()); + } } diff --git a/src/test/java/com/meilisearch/sdk/SearchRequestTest.java b/src/test/java/com/meilisearch/sdk/SearchRequestTest.java index fd741fa2..e5e48b9e 100644 --- a/src/test/java/com/meilisearch/sdk/SearchRequestTest.java +++ b/src/test/java/com/meilisearch/sdk/SearchRequestTest.java @@ -92,6 +92,7 @@ void toStringEveryParametersWithArray() { "123", "abc", "zyx", + "789", new String[] {"highlight"}, new String[][] { new String[] {"test='test'"}, new String[] {"test1='test1'"} @@ -117,7 +118,7 @@ void toStringEveryParametersWithArray() { assertEquals("sort", classToTest.getSort()[0]); assertEquals(900, classToTest.getCropLength()); assertEquals( - "{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"sort\":[\"sort\"],\"highlightPreTag\":\"abc\",\"facets\":[\"facets\"],\"filter\":[[\"test='test'\"],[\"test1='test1'\"]],\"q\":\"This is a Test\",\"showMatchesPosition\":true,\"limit\":900,\"cropLength\":900,\"highlightPostTag\":\"zyx\",\"attributesToHighlight\":[\"highlight\"],\"attributesToCrop\":[\"crop\"]}", + "{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"sort\":[\"sort\"],\"highlightPreTag\":\"abc\",\"facets\":[\"facets\"],\"filter\":[[\"test='test'\"],[\"test1='test1'\"]],\"q\":\"This is a Test\",\"matchingStrategy\":\"789\",\"showMatchesPosition\":true,\"limit\":900,\"cropLength\":900,\"highlightPostTag\":\"zyx\",\"attributesToHighlight\":[\"highlight\"],\"attributesToCrop\":[\"crop\"]}", classToTest.toString()); } } From d1275fb1236eb780c6bbdad983fd879f32527040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Wed, 8 Feb 2023 15:35:22 +0100 Subject: [PATCH 3/7] Update src/test/java/com/meilisearch/integration/KeysTest.java Co-authored-by: Bruno Casali --- src/test/java/com/meilisearch/integration/KeysTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/meilisearch/integration/KeysTest.java b/src/test/java/com/meilisearch/integration/KeysTest.java index 18a071cb..e116bc26 100644 --- a/src/test/java/com/meilisearch/integration/KeysTest.java +++ b/src/test/java/com/meilisearch/integration/KeysTest.java @@ -232,7 +232,6 @@ public void testClientCreateKeyWithWilcardedAction() throws Exception { Key key = client.createKey(keyInfo); - assertTrue(key instanceof Key); assertNotNull(key.getKey()); assertEquals("documents.*", key.getActions()[0]); assertEquals("*", key.getIndexes()[0]); From 12c9bac4d640bb8658888c8fab550c5ee5b5e918 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 8 Feb 2023 16:39:36 +0100 Subject: [PATCH 4/7] Add enum for matchingStretegy --- .../meilisearch/sdk/model/MatchingStrategy.java | 16 ++++++++++++++++ .../com/meilisearch/integration/SearchTest.java | 4 +++- .../com/meilisearch/sdk/SearchRequestTest.java | 6 ++++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/meilisearch/sdk/model/MatchingStrategy.java diff --git a/src/main/java/com/meilisearch/sdk/model/MatchingStrategy.java b/src/main/java/com/meilisearch/sdk/model/MatchingStrategy.java new file mode 100644 index 00000000..5b157a93 --- /dev/null +++ b/src/main/java/com/meilisearch/sdk/model/MatchingStrategy.java @@ -0,0 +1,16 @@ +package com.meilisearch.sdk.model; + +public enum MatchingStrategy { + ALL("all"), + LAST("Last"); + + public final String matchingStrategy; + + private MatchingStrategy(String matchingStrategy) { + this.matchingStrategy = matchingStrategy; + } + + public String toString() { + return this.matchingStrategy; + } +} diff --git a/src/test/java/com/meilisearch/integration/SearchTest.java b/src/test/java/com/meilisearch/integration/SearchTest.java index f6a97bfc..a685a750 100644 --- a/src/test/java/com/meilisearch/integration/SearchTest.java +++ b/src/test/java/com/meilisearch/integration/SearchTest.java @@ -9,6 +9,7 @@ import com.meilisearch.sdk.Index; import com.meilisearch.sdk.SearchRequest; import com.meilisearch.sdk.json.GsonJsonHandler; +import com.meilisearch.sdk.model.MatchingStrategy; import com.meilisearch.sdk.model.SearchResult; import com.meilisearch.sdk.model.Settings; import com.meilisearch.sdk.model.TaskInfo; @@ -498,7 +499,8 @@ public void testSearchMatchingStrategy() throws Exception { TaskInfo task = index.addDocuments(testData.getRaw()); index.waitForTask(task.getTaskUid()); - SearchRequest searchRequest = new SearchRequest("and").setMatchingStrategy("all"); + SearchRequest searchRequest = + new SearchRequest("and").setMatchingStrategy(MatchingStrategy.ALL.toString()); SearchResult searchResult = index.search(searchRequest); assertEquals(20, searchResult.getHits().size()); diff --git a/src/test/java/com/meilisearch/sdk/SearchRequestTest.java b/src/test/java/com/meilisearch/sdk/SearchRequestTest.java index e5e48b9e..4c45c749 100644 --- a/src/test/java/com/meilisearch/sdk/SearchRequestTest.java +++ b/src/test/java/com/meilisearch/sdk/SearchRequestTest.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import com.meilisearch.sdk.model.MatchingStrategy; import org.junit.jupiter.api.Test; class SearchRequestTest { @@ -92,7 +93,7 @@ void toStringEveryParametersWithArray() { "123", "abc", "zyx", - "789", + MatchingStrategy.ALL.toString(), new String[] {"highlight"}, new String[][] { new String[] {"test='test'"}, new String[] {"test1='test1'"} @@ -106,6 +107,7 @@ void toStringEveryParametersWithArray() { assertEquals(900, classToTest.getLimit()); assertEquals("123", classToTest.getCropMarker()); assertEquals("abc", classToTest.getHighlightPreTag()); + assertEquals(MatchingStrategy.ALL.toString(), classToTest.getMatchingStrategy()); assertEquals("zyx", classToTest.getHighlightPostTag()); assertEquals("bubble", classToTest.getAttributesToRetrieve()[0]); assertEquals("highlight", classToTest.getAttributesToHighlight()[0]); @@ -118,7 +120,7 @@ void toStringEveryParametersWithArray() { assertEquals("sort", classToTest.getSort()[0]); assertEquals(900, classToTest.getCropLength()); assertEquals( - "{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"sort\":[\"sort\"],\"highlightPreTag\":\"abc\",\"facets\":[\"facets\"],\"filter\":[[\"test='test'\"],[\"test1='test1'\"]],\"q\":\"This is a Test\",\"matchingStrategy\":\"789\",\"showMatchesPosition\":true,\"limit\":900,\"cropLength\":900,\"highlightPostTag\":\"zyx\",\"attributesToHighlight\":[\"highlight\"],\"attributesToCrop\":[\"crop\"]}", + "{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"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\"],\"attributesToCrop\":[\"crop\"]}", classToTest.toString()); } } From a603c5bd2f447571b3ab1131f2644695bd9e6f66 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 8 Feb 2023 18:49:48 +0100 Subject: [PATCH 5/7] Improve matchingStretegy field --- src/main/java/com/meilisearch/sdk/Search.java | 2 +- .../java/com/meilisearch/sdk/SearchRequest.java | 17 ++++++++++++----- .../meilisearch/sdk/model/MatchingStrategy.java | 3 ++- .../com/meilisearch/integration/SearchTest.java | 2 +- .../com/meilisearch/sdk/SearchRequestTest.java | 4 ++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/meilisearch/sdk/Search.java b/src/main/java/com/meilisearch/sdk/Search.java index 3ba0d573..82fe347d 100644 --- a/src/main/java/com/meilisearch/sdk/Search.java +++ b/src/main/java/com/meilisearch/sdk/Search.java @@ -102,7 +102,7 @@ String rawSearch( */ String rawSearch(String uid, SearchRequest sr) throws MeilisearchException { String requestQuery = "/indexes/" + uid + "/search"; - return httpClient.post(requestQuery, sr, String.class); + return httpClient.post(requestQuery, sr.toString(), String.class); } /** diff --git a/src/main/java/com/meilisearch/sdk/SearchRequest.java b/src/main/java/com/meilisearch/sdk/SearchRequest.java index 769fbbf3..c7851c35 100644 --- a/src/main/java/com/meilisearch/sdk/SearchRequest.java +++ b/src/main/java/com/meilisearch/sdk/SearchRequest.java @@ -1,5 +1,6 @@ package com.meilisearch.sdk; +import com.meilisearch.sdk.model.MatchingStrategy; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -19,7 +20,7 @@ public class SearchRequest { private String cropMarker; private String highlightPreTag; private String highlightPostTag; - private String matchingStrategy; + private MatchingStrategy matchingStrategy; private String[] attributesToHighlight; private String[] filter; private String[][] filterArray; @@ -254,7 +255,8 @@ public SearchRequest( * @param cropMarker String to customize default crop marker, default value: … * @param highlightPreTag String to customize highlight tag before every highlighted query terms * @param highlightPostTag String to customize highlight tag after every highlighted query terms - * @param matchingStrategy String to defines the strategy used to match query terms in documents + * @param matchingStrategy MatchingStrategy to defines the strategy used to match query terms in + * documents * @param attributesToHighlight Attributes whose values will contain highlighted matching terms * @param filterArray String array that can take multiple nested filters * @param showMatchesPosition Defines whether an object that contains information about the @@ -272,7 +274,7 @@ public SearchRequest( String cropMarker, String highlightPreTag, String highlightPostTag, - String matchingStrategy, + MatchingStrategy matchingStrategy, String[] attributesToHighlight, String[][] filterArray, boolean showMatchesPosition, @@ -307,7 +309,7 @@ private SearchRequest( String cropMarker, String highlightPreTag, String highlightPostTag, - String matchingStrategy, + MatchingStrategy matchingStrategy, String[] attributesToHighlight, String[] filter, String[][] filterArray, @@ -361,7 +363,11 @@ public String toString() { .put("cropMarker", this.cropMarker) .put("highlightPreTag", this.highlightPreTag) .put("highlightPostTag", this.highlightPostTag) - .put("matchingStrategy", this.matchingStrategy) + .put( + "matchingStrategy", + this.matchingStrategy == null + ? null + : this.matchingStrategy.toString()) .put("showMatchesPosition", this.showMatchesPosition) .put("facets", this.facets) .put("sort", this.sort) @@ -370,6 +376,7 @@ public String toString() { .putOpt("filter", this.filter) .putOpt("filter", this.filterArray); + System.out.println("SearchRequest: " + jsonObject.toString()); return jsonObject.toString(); } } diff --git a/src/main/java/com/meilisearch/sdk/model/MatchingStrategy.java b/src/main/java/com/meilisearch/sdk/model/MatchingStrategy.java index 5b157a93..a2144e0e 100644 --- a/src/main/java/com/meilisearch/sdk/model/MatchingStrategy.java +++ b/src/main/java/com/meilisearch/sdk/model/MatchingStrategy.java @@ -2,7 +2,7 @@ public enum MatchingStrategy { ALL("all"), - LAST("Last"); + LAST("last"); public final String matchingStrategy; @@ -10,6 +10,7 @@ private MatchingStrategy(String matchingStrategy) { this.matchingStrategy = matchingStrategy; } + @Override public String toString() { return this.matchingStrategy; } diff --git a/src/test/java/com/meilisearch/integration/SearchTest.java b/src/test/java/com/meilisearch/integration/SearchTest.java index a685a750..8ce9d7bc 100644 --- a/src/test/java/com/meilisearch/integration/SearchTest.java +++ b/src/test/java/com/meilisearch/integration/SearchTest.java @@ -500,7 +500,7 @@ public void testSearchMatchingStrategy() throws Exception { index.waitForTask(task.getTaskUid()); SearchRequest searchRequest = - new SearchRequest("and").setMatchingStrategy(MatchingStrategy.ALL.toString()); + new SearchRequest("and").setMatchingStrategy(MatchingStrategy.ALL); SearchResult searchResult = index.search(searchRequest); assertEquals(20, searchResult.getHits().size()); diff --git a/src/test/java/com/meilisearch/sdk/SearchRequestTest.java b/src/test/java/com/meilisearch/sdk/SearchRequestTest.java index 4c45c749..baf1eec3 100644 --- a/src/test/java/com/meilisearch/sdk/SearchRequestTest.java +++ b/src/test/java/com/meilisearch/sdk/SearchRequestTest.java @@ -93,7 +93,7 @@ void toStringEveryParametersWithArray() { "123", "abc", "zyx", - MatchingStrategy.ALL.toString(), + MatchingStrategy.ALL, new String[] {"highlight"}, new String[][] { new String[] {"test='test'"}, new String[] {"test1='test1'"} @@ -107,7 +107,7 @@ void toStringEveryParametersWithArray() { assertEquals(900, classToTest.getLimit()); assertEquals("123", classToTest.getCropMarker()); assertEquals("abc", classToTest.getHighlightPreTag()); - assertEquals(MatchingStrategy.ALL.toString(), classToTest.getMatchingStrategy()); + assertEquals(MatchingStrategy.ALL, classToTest.getMatchingStrategy()); assertEquals("zyx", classToTest.getHighlightPostTag()); assertEquals("bubble", classToTest.getAttributesToRetrieve()[0]); assertEquals("highlight", classToTest.getAttributesToHighlight()[0]); From dd3e2f1fb231de81ed2f46f2710280ba52d5c5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Mon, 13 Feb 2023 11:35:50 +0100 Subject: [PATCH 6/7] Update src/main/java/com/meilisearch/sdk/SearchRequest.java Co-authored-by: Bruno Casali --- src/main/java/com/meilisearch/sdk/SearchRequest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/SearchRequest.java b/src/main/java/com/meilisearch/sdk/SearchRequest.java index c7851c35..105a90ea 100644 --- a/src/main/java/com/meilisearch/sdk/SearchRequest.java +++ b/src/main/java/com/meilisearch/sdk/SearchRequest.java @@ -376,7 +376,6 @@ public String toString() { .putOpt("filter", this.filter) .putOpt("filter", this.filterArray); - System.out.println("SearchRequest: " + jsonObject.toString()); return jsonObject.toString(); } } From ea8548e0ade92b1cb2107cebc4d5fec4d8b3950f Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 13 Feb 2023 19:09:25 +0100 Subject: [PATCH 7/7] Modify tests for matching strategy --- .../meilisearch/integration/SearchTest.java | 18 -------- .../meilisearch/sdk/SearchRequestTest.java | 44 +++++++++++++++++++ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/meilisearch/integration/SearchTest.java b/src/test/java/com/meilisearch/integration/SearchTest.java index 8ce9d7bc..c34d17f3 100644 --- a/src/test/java/com/meilisearch/integration/SearchTest.java +++ b/src/test/java/com/meilisearch/integration/SearchTest.java @@ -9,7 +9,6 @@ import com.meilisearch.sdk.Index; import com.meilisearch.sdk.SearchRequest; import com.meilisearch.sdk.json.GsonJsonHandler; -import com.meilisearch.sdk.model.MatchingStrategy; import com.meilisearch.sdk.model.SearchResult; import com.meilisearch.sdk.model.Settings; import com.meilisearch.sdk.model.TaskInfo; @@ -488,21 +487,4 @@ public void testPlaceHolderWithLimit() throws Exception { assertEquals(10, searchResult.getHits().size()); } - - /** Test search matchingStrategy */ - @Test - public void testSearchMatchingStrategy() throws Exception { - String indexUid = "SearchMatchingStrategy"; - Index index = client.index(indexUid); - - TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - TaskInfo task = index.addDocuments(testData.getRaw()); - - index.waitForTask(task.getTaskUid()); - SearchRequest searchRequest = - new SearchRequest("and").setMatchingStrategy(MatchingStrategy.ALL); - SearchResult searchResult = index.search(searchRequest); - - assertEquals(20, searchResult.getHits().size()); - } } diff --git a/src/test/java/com/meilisearch/sdk/SearchRequestTest.java b/src/test/java/com/meilisearch/sdk/SearchRequestTest.java index baf1eec3..17e0ace8 100644 --- a/src/test/java/com/meilisearch/sdk/SearchRequestTest.java +++ b/src/test/java/com/meilisearch/sdk/SearchRequestTest.java @@ -123,4 +123,48 @@ void toStringEveryParametersWithArray() { "{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"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\"],\"attributesToCrop\":[\"crop\"]}", classToTest.toString()); } + + @Test + void toStringEveryParametersWithArrayMatchingStrategyNull() { + SearchRequest classToTest = + new SearchRequest( + "This is a Test", + 200, + 900, + new String[] {"bubble"}, + new String[] {"crop"}, + 900, + "123", + "abc", + "zyx", + null, + new String[] {"highlight"}, + new String[][] { + new String[] {"test='test'"}, new String[] {"test1='test1'"} + }, + true, + new String[] {"facets"}, + new String[] {"sort"}); + + assertEquals("This is a Test", classToTest.getQ()); + assertEquals(200, classToTest.getOffset()); + assertEquals(900, classToTest.getLimit()); + assertEquals("123", classToTest.getCropMarker()); + assertEquals("abc", classToTest.getHighlightPreTag()); + assertEquals(null, classToTest.getMatchingStrategy()); + assertEquals("zyx", classToTest.getHighlightPostTag()); + assertEquals("bubble", classToTest.getAttributesToRetrieve()[0]); + assertEquals("highlight", classToTest.getAttributesToHighlight()[0]); + assertEquals("crop", classToTest.getAttributesToCrop()[0]); + assertEquals(null, classToTest.getFilter()); + assertEquals(2, classToTest.getFilterArray().length); + assertEquals("test='test'", classToTest.getFilterArray()[0][0]); + assertEquals("test1='test1'", classToTest.getFilterArray()[1][0]); + assertEquals("facets", classToTest.getFacets()[0]); + assertEquals("sort", classToTest.getSort()[0]); + assertEquals(900, classToTest.getCropLength()); + assertEquals( + "{\"attributesToRetrieve\":[\"bubble\"],\"offset\":200,\"cropMarker\":\"123\",\"sort\":[\"sort\"],\"highlightPreTag\":\"abc\",\"facets\":[\"facets\"],\"filter\":[[\"test='test'\"],[\"test1='test1'\"]],\"q\":\"This is a Test\",\"showMatchesPosition\":true,\"limit\":900,\"cropLength\":900,\"highlightPostTag\":\"zyx\",\"attributesToHighlight\":[\"highlight\"],\"attributesToCrop\":[\"crop\"]}", + classToTest.toString()); + } }