Skip to content

Commit

Permalink
Merge #463
Browse files Browse the repository at this point in the history
463: Implement attributesToSearchOn r=brunoocasali a=SKeeneCode

# Pull Request

## Related issue
Fixes #457

## What does this PR do?
- Implements AttributesToSearchOn in SearchQuery

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: Sam Keene <[email protected]>
Co-authored-by: Sam Keene <[email protected]>
  • Loading branch information
3 people authored Sep 1, 2023
2 parents ec12ad5 + 5be4e54 commit b886e8b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ search_parameter_guide_show_matches_position_1: |-
{
ShowMatchesPosition = True,
});
search_parameter_guide_attributes_to_search_on_1: |-
var searchQuery = new SearchQuery
{
AttributesToSearchOn = new[] { "overview" }
};
await client.Index("movies").SearchAsync<Movie>("adventure", searchQuery);
documents_guide_add_movie_1: |-
var movie = new[]
{
Expand Down
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MEILISEARCH_VERSION=v1.2.0
MEILISEARCH_VERSION=v1.3.0
PROXIED_MEILISEARCH=http://nginx/api/
MEILISEARCH_URL=http://meilisearch:7700
6 changes: 6 additions & 0 deletions src/Meilisearch/SearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public class SearchQuery
[JsonPropertyName("attributesToCrop")]
public IEnumerable<string> AttributesToCrop { get; set; }

/// <summary>
/// Gets or sets attributes to search on.
/// </summary>
[JsonPropertyName("attributesToSearchOn")]
public IEnumerable<string> AttributesToSearchOn { get; set; }

/// <summary>
/// Gets or sets length used to crop field values.
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions tests/Meilisearch.Tests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,38 @@ public async Task CustomSearchWithMultipleOptions()
Assert.Null(firstHit._Formatted.Genre);
}

[Fact]
public async Task CustomSearchWithAttributesToSearchOn()
{
var movies = await _basicIndex.SearchAsync<FormattedMovie>(
"Harry",
new SearchQuery
{
AttributesToSearchOn = new[] { "name" },
});
var firstHit = movies.Hits.First();

Assert.NotEmpty(movies.Hits);
Assert.Single(movies.Hits);
Assert.NotEmpty(firstHit.Name);
Assert.NotEmpty(firstHit.Id);
Assert.NotEmpty(firstHit.Genre);
}

[Fact]
public async Task CustomSearchWithAttributesToSearchOnNoResults()
{
var movies = await _basicIndex.SearchAsync<FormattedMovie>(
"Harry",
new SearchQuery
{
AttributesToSearchOn = new[] { "genre" },
});
var firstHit = movies.Hits.FirstOrDefault();

Assert.Null(firstHit);
}

[Fact]
public async Task CustomSearchWithFilter()
{
Expand Down

0 comments on commit b886e8b

Please sign in to comment.