From 1201de5e99a72681b46c56e305ec026032e7b351 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 2 Feb 2023 17:26:13 +0100 Subject: [PATCH] Add changes for compatibility with v0.29.0 --- .../com/meilisearch/sdk/SearchRequest.java | 10 ++++++++++ .../com/meilisearch/integration/KeysTest.java | 20 +++++++++++++++++++ .../meilisearch/integration/SearchTest.java | 17 ++++++++++++++++ .../meilisearch/sdk/SearchRequestTest.java | 3 ++- 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/SearchRequest.java b/src/main/java/com/meilisearch/sdk/SearchRequest.java index a6a0f4b24..769fbbf35 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 a2c3d4b6e..18a071cb8 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 6ef50659e..f6a97bfc8 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 fd741fa21..e5e48b9e9 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()); } }