Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix matching strategy enum usage and add test #561

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/meilisearch/sdk/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ String rawSearch(String uid, String q) throws MeilisearchException {
*/
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);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/meilisearch/integration/SearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -231,6 +232,26 @@ public void testSearchWithCustomizedHighlight() throws Exception {
resGson.hits[0].getFormatted().getTitle());
}

/** Test search with customized highlight */
@Test
public void testSearchWithMatchingStrategy() 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 =
SearchRequest.builder().q("and").matchingStrategy(MatchingStrategy.ALL).build();

SearchResult searchResult = index.search(searchRequest);

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

/** Test search with phrase */
@Test
public void testSearchPhrase() throws Exception {
Expand Down