Skip to content

Commit

Permalink
Add changes for compatibility with v0.29.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alallema committed Feb 2, 2023
1 parent 4a66d96 commit 1201de5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/com/meilisearch/sdk/SearchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,6 +133,7 @@ public SearchRequest(
null,
null,
null,
null,
attributesToHighlight,
filter,
null,
Expand Down Expand Up @@ -184,6 +186,7 @@ public SearchRequest(
cropMarker,
highlightPreTag,
highlightPostTag,
null,
attributesToHighlight,
filter,
null,
Expand Down Expand Up @@ -230,6 +233,7 @@ public SearchRequest(
null,
null,
null,
null,
attributesToHighlight,
null,
filterArray,
Expand All @@ -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
Expand All @@ -267,6 +272,7 @@ public SearchRequest(
String cropMarker,
String highlightPreTag,
String highlightPostTag,
String matchingStrategy,
String[] attributesToHighlight,
String[][] filterArray,
boolean showMatchesPosition,
Expand All @@ -282,6 +288,7 @@ public SearchRequest(
cropMarker,
highlightPreTag,
highlightPostTag,
matchingStrategy,
attributesToHighlight,
null,
filterArray,
Expand All @@ -300,6 +307,7 @@ private SearchRequest(
String cropMarker,
String highlightPreTag,
String highlightPostTag,
String matchingStrategy,
String[] attributesToHighlight,
String[] filter,
String[][] filterArray,
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/meilisearch/integration/KeysTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/meilisearch/integration/SearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ public void testSearchMatches() throws Exception {

assertEquals(20, searchResult.getHits().size());
}

/** Test place holder search */
@Test
public void testPlaceHolder() throws Exception {
Expand Down Expand Up @@ -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<Movie> 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());
}
}
3 changes: 2 additions & 1 deletion src/test/java/com/meilisearch/sdk/SearchRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void toStringEveryParametersWithArray() {
"123",
"abc",
"zyx",
"789",
new String[] {"highlight"},
new String[][] {
new String[] {"test='test'"}, new String[] {"test1='test1'"}
Expand All @@ -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());
}
}

0 comments on commit 1201de5

Please sign in to comment.