Skip to content

Commit

Permalink
Add support to nested fields
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoocasali committed May 5, 2022
1 parent 4619205 commit 0b3848d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/Meilisearch.Tests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Meilisearch.Tests
public abstract class SearchTests<TFixture> : IAsyncLifetime where TFixture : IndexFixture
{
private Index _basicIndex;
private Index _nestedIndex;
private Index _indexForFaceting;
private Index _indexWithIntId;

Expand All @@ -26,6 +27,7 @@ public async Task InitializeAsync()
_basicIndex = await _fixture.SetUpBasicIndex("BasicIndex-SearchTests");
_indexForFaceting = await _fixture.SetUpIndexForFaceting("IndexForFaceting-SearchTests");
_indexWithIntId = await _fixture.SetUpBasicIndexWithIntId("IndexWithIntId-SearchTests");
_nestedIndex = await _fixture.SetUpIndexForNestedSearch("IndexForNestedDocs-SearchTests");
}

public Task DisposeAsync() => Task.CompletedTask;
Expand Down Expand Up @@ -311,5 +313,47 @@ public async Task CustomSearchWithSort()
Assert.Equal(2, movies.Hits.Count());
Assert.Equal("14", movies.Hits.First().Id);
}

[Fact]
public async Task CustomSearchWithinNestedDocuments()
{
var movies = await _nestedIndex.SearchAsync<MovieWithInfo>("wizard");

Assert.NotEmpty(movies.Hits);
Assert.Equal(movies.Hits.First().Name, "Harry Potter");
Assert.Equal(movies.Hits.First().Id, "13");
Assert.Equal(movies.Hits.First().Info.Comment, "a movie about a wizard boy");
}

[Fact]
public async Task CustomSearchWithinNestedDocumentsWithSearchableAttributesSettings()
{
var task = await _nestedIndex.UpdateSearchableAttributesAsync(new string[] { "name", "info.comment" });
await _nestedIndex.WaitForTaskAsync(task.Uid);

var movies = await _nestedIndex.SearchAsync<MovieWithInfo>("rich");

Assert.NotEmpty(movies.Hits);
Assert.Equal(movies.Hits.First().Name, "Iron Man");
Assert.Equal(movies.Hits.First().Id, "14");
Assert.Equal(movies.Hits.First().Info.Comment, "a movie about a rich man");
}

[Fact]
public async Task CustomSearchWithinNestedDocumentsWithSearchableAndSortableAttributesSettings()
{
var searchTask = await _nestedIndex.UpdateSearchableAttributesAsync(new string[] { "name", "info.comment" });
await _nestedIndex.WaitForTaskAsync(searchTask.Uid);
var sortTask = await _nestedIndex.UpdateSortableAttributesAsync(new string[] { "info.reviewNb" });
await _nestedIndex.WaitForTaskAsync(sortTask.Uid);

var query = new SearchQuery { Sort = new string[] { "info.reviewNb:desc" } };
var movies = await _nestedIndex.SearchAsync<MovieWithInfo>("", query);

Assert.NotEmpty(movies.Hits);
Assert.Equal(movies.Hits.First().Name, "Interstellar");
Assert.Equal(movies.Hits.First().Id, "11");
Assert.Equal(movies.Hits.First().Info.ReviewNb, 1000);
}
}
}

0 comments on commit 0b3848d

Please sign in to comment.