Skip to content

feat: Support structs as search result #652

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/Meilisearch/ISearchableJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer
/// The json converter for <see cref="ISearchable{T}"/>
/// </summary>
/// <typeparam name="T"></typeparam>
public class ISearchableJsonConverter<T> : JsonConverter<ISearchable<T>> where T : class
public class ISearchableJsonConverter<T> : JsonConverter<ISearchable<T>>
{
/// <inheritdoc/>
public override ISearchable<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Expand Down
8 changes: 8 additions & 0 deletions tests/Meilisearch.Tests/Movie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public class Movie
public string Genre { get; set; }
}

public struct MovieStruct
{
public string Id { get; set; }

public string Name { get; set; }

public string Genre { get; set; }
}
public class MovieInfo
{
public string Comment { get; set; }
Expand Down
22 changes: 22 additions & 0 deletions tests/Meilisearch.Tests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ public async Task BasicSearch()
movies.Hits.ElementAt(1).Name.Should().NotBeEmpty();
}

[Fact]
public async Task BasicSearchWithStruct()
{
var movies = await _basicIndex.SearchAsync<MovieStruct>("man");
movies.Hits.Should().NotBeEmpty();
movies.Hits.First().Name.Should().NotBeEmpty();
movies.Hits.ElementAt(1).Name.Should().NotBeEmpty();
}

[Fact]
public async Task PaginatedSearchWithStruct()
{
var movies = await _basicIndex.SearchAsync<MovieStruct>("man", new SearchQuery()
{
Page = 1,
HitsPerPage = 2,
});
movies.Hits.Should().NotBeEmpty();
movies.Hits.First().Name.Should().NotBeEmpty();
movies.Hits.ElementAt(1).Name.Should().NotBeEmpty();
}

[Fact]
public async Task BasicSearchWithNoQuery()
{
Expand Down
Loading