-
Notifications
You must be signed in to change notification settings - Fork 115
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
Ensure nested field support #374
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
src/test/java/com/meilisearch/integration/SearchNestedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.meilisearch.integration; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.meilisearch.integration.classes.AbstractIT; | ||
import com.meilisearch.integration.classes.TestData; | ||
import com.meilisearch.sdk.Index; | ||
import com.meilisearch.sdk.SearchRequest; | ||
import com.meilisearch.sdk.Settings; | ||
import com.meilisearch.sdk.Task; | ||
import com.meilisearch.sdk.json.GsonJsonHandler; | ||
import com.meilisearch.sdk.utils.Movie; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@Tag("integration") | ||
public class SearchNestedTest extends AbstractIT { | ||
|
||
private TestData<Movie> testData; | ||
|
||
final class Results { | ||
Movie[] hits; | ||
int offset; | ||
int limit; | ||
int nbHits; | ||
boolean exhaustiveNbHits; | ||
int processingTimeMs; | ||
String query; | ||
} | ||
|
||
@BeforeEach | ||
public void initialize() { | ||
cleanup(); | ||
this.setUp(); | ||
if (testData == null) testData = this.getTestData(NESTED_MOVIES, Movie.class); | ||
} | ||
|
||
/** Test basic search in nested fields */ | ||
@Test | ||
public void testBasicSearchInNestedFields() throws Exception { | ||
String indexUid = "SearchOnNestedFields"; | ||
Index index = client.index(indexUid); | ||
GsonJsonHandler jsonGson = new GsonJsonHandler(); | ||
|
||
TestData<Movie> testData = this.getTestData(NESTED_MOVIES, Movie.class); | ||
Task task = index.addDocuments(testData.getRaw()); | ||
index.waitForTask(task.getUid()); | ||
Results searchResultGson = jsonGson.decode(index.rawSearch("An awesome"), Results.class); | ||
|
||
assertEquals(1, searchResultGson.hits.length); | ||
assertEquals("5", searchResultGson.hits[0].getId()); | ||
} | ||
|
||
/** Test search on nested documents with searchable attributes */ | ||
@Test | ||
public void testSearchOnNestedFieldsWithSearchableAttributes() throws Exception { | ||
String indexUid = "SearchOnNestedFields"; | ||
Index index = client.index(indexUid); | ||
GsonJsonHandler jsonGson = new GsonJsonHandler(); | ||
String[] newSearchableAttributes = {"title", "info.comment"}; | ||
|
||
TestData<Movie> testData = this.getTestData(NESTED_MOVIES, Movie.class); | ||
Task task = index.addDocuments(testData.getRaw()); | ||
|
||
index.waitForTask(task.getUid()); | ||
|
||
index.waitForTask( | ||
index.updateSearchableAttributesSettings(newSearchableAttributes).getUid()); | ||
|
||
Results searchResultGson = jsonGson.decode(index.rawSearch("An awesome"), Results.class); | ||
|
||
assertEquals(1, searchResultGson.hits.length); | ||
assertEquals("5", searchResultGson.hits[0].getId()); | ||
} | ||
|
||
/** Test search on nested documents with sortable attributes */ | ||
@Test | ||
public void testSearchOnNestedFieldsWithSortableAttributes() throws Exception { | ||
String indexUid = "SearchOnNestedFields"; | ||
Index index = client.index(indexUid); | ||
GsonJsonHandler jsonGson = new GsonJsonHandler(); | ||
Settings newSettings = new Settings(); | ||
newSettings.setSortableAttributes(new String[] {"info.reviewNb"}); | ||
|
||
TestData<Movie> testData = this.getTestData(NESTED_MOVIES, Movie.class); | ||
Task task = index.addDocuments(testData.getRaw()); | ||
index.waitForTask(task.getUid()); | ||
index.waitForTask(index.updateSettings(newSettings).getUid()); | ||
SearchRequest searchRequest = | ||
new SearchRequest("An Awesome").setSort(new String[] {"info.reviewNb:desc"}); | ||
|
||
Results searchResultGson = jsonGson.decode(index.rawSearch(searchRequest), Results.class); | ||
|
||
assertEquals(1, searchResultGson.hits.length); | ||
assertEquals("5", searchResultGson.hits[0].getId()); | ||
} | ||
|
||
/** Test search on nested documents with sortable and searchable attributes */ | ||
@Test | ||
public void testSearchOnNestedFieldsWithSortableAndSearchableAttributes() throws Exception { | ||
String indexUid = "SearchOnNestedFields"; | ||
Index index = client.index(indexUid); | ||
GsonJsonHandler jsonGson = new GsonJsonHandler(); | ||
Settings newSettings = new Settings(); | ||
newSettings.setSearchableAttributes(new String[] {"title", "info.comment"}); | ||
newSettings.setSortableAttributes(new String[] {"info.reviewNb"}); | ||
|
||
TestData<Movie> testData = this.getTestData(NESTED_MOVIES, Movie.class); | ||
Task task = index.addDocuments(testData.getRaw()); | ||
index.waitForTask(task.getUid()); | ||
index.waitForTask(index.updateSettings(newSettings).getUid()); | ||
SearchRequest searchRequest = | ||
new SearchRequest("An Awesome").setSort(new String[] {"info.reviewNb:desc"}); | ||
Results searchResultGson = jsonGson.decode(index.rawSearch(searchRequest), Results.class); | ||
|
||
assertEquals(1, searchResultGson.hits.length); | ||
assertEquals("5", searchResultGson.hits[0].getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class already exist in other places right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the
SearchTest
file.