From ddb528b6b7d55c262e202948f8a6ceabb70273df Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 4 Dec 2024 11:35:27 -0600 Subject: [PATCH 1/9] add object classes for facet search --- src/Meilisearch/SearchFacetsQuery.cs | 47 +++++++++++++++++++++++++++ src/Meilisearch/SearchFacetsResult.cs | 47 +++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/Meilisearch/SearchFacetsQuery.cs create mode 100644 src/Meilisearch/SearchFacetsResult.cs diff --git a/src/Meilisearch/SearchFacetsQuery.cs b/src/Meilisearch/SearchFacetsQuery.cs new file mode 100644 index 00000000..7e7fb2fe --- /dev/null +++ b/src/Meilisearch/SearchFacetsQuery.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Meilisearch +{ + /// + /// Wrapper for facet search query + /// + public class SearchFacetsQuery + { + /// + /// Gets or sets the facetName property + /// + [JsonPropertyName("facetName")] + public string FacetName { get; set; } + + /// + /// Gets or sets the facetQuery property + /// + [JsonPropertyName("facetQuery")] + public string FacetQuery { get; set; } + + /// + /// Gets or sets the q property + /// + [JsonPropertyName("q")] + public string Query { get; set; } + + /// + /// Gets or sets the filter property + /// + [JsonPropertyName("filter")] + public string Filter { get; set; } + + /// + /// Gets or sets the matchingStrategy property, can be last, all or frequency. + /// + [JsonPropertyName("matchingStrategy")] + public string MatchingStrategy { get; set; } + + /// + /// Gets or sets the attributesToSearchOn property + /// + [JsonPropertyName("attributesToSearchOn")] + public IEnumerable AttributesToSearchOn { get; set; } + } +} diff --git a/src/Meilisearch/SearchFacetsResult.cs b/src/Meilisearch/SearchFacetsResult.cs new file mode 100644 index 00000000..58ed3044 --- /dev/null +++ b/src/Meilisearch/SearchFacetsResult.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Meilisearch +{ + /// + /// Wrapper for FacetSearchResponse + /// + public class SearchFacetsResult + { + /// + /// Gets or sets the facetHits property + /// + [JsonPropertyName("facetHits")] + public IEnumerable FacetHits { get; set; } + + /// + /// Gets or sets the facet query + /// + [JsonPropertyName("facetQuery")] + public string FacetQuery { get; set; } + + /// + /// Gets or sets the processingTimeMs property + /// + [JsonPropertyName("processingTimeMs")] + public int ProcessingTimeMs { get; set; } + + /// + /// Wrapper for Facet Hit + /// + public class FacetHit + { + /// + /// Gets or sets the value property + /// + [JsonPropertyName("value")] + public string Value { get; set; } + + /// + /// Gets or sets the count property + /// + [JsonPropertyName("count")] + public int Count { get; set; } + } + } +} From 2c2849c8d08cb3410412c776395a263d3774facb Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 4 Dec 2024 11:35:41 -0600 Subject: [PATCH 2/9] add FacetSearchAsync method --- src/Meilisearch/Index.Documents.cs | 31 +++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Meilisearch/Index.Documents.cs b/src/Meilisearch/Index.Documents.cs index ea1648d6..5b868a63 100644 --- a/src/Meilisearch/Index.Documents.cs +++ b/src/Meilisearch/Index.Documents.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -543,5 +542,35 @@ public async Task> SearchAsync(string query, .ReadFromJsonAsync>(cancellationToken: cancellationToken) .ConfigureAwait(false); } + + /// + /// Search index facets + /// + /// Name of the facet to search. + /// The search criteria to find the facet matches. + /// The cancellation token for this call. + /// Facets meeting the search criteria. + public async Task FacetSearchAsync(string facetName, + SearchFacetsQuery query = default, CancellationToken cancellationToken = default) + { + SearchFacetsQuery body; + if (query == null) + { + body = new SearchFacetsQuery() { FacetName = facetName }; + } + else + { + body = query; + body.FacetName = facetName; + } + + var responseMessage = await _http.PostAsJsonAsync($"indexes/{Uid}/facet-search", body, + Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken) + .ConfigureAwait(false); + + return await responseMessage.Content + .ReadFromJsonAsync(cancellationToken: cancellationToken) + .ConfigureAwait(false); + } } } From dac1c89a63eba195f8fbef3cbffd7988b27e1ff3 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 4 Dec 2024 11:35:56 -0600 Subject: [PATCH 3/9] tests implementation --- .../Meilisearch.Tests/FacetingSearchTests.cs | 250 ++++++++++++++++++ .../ServerConfigs/BaseUriServer.cs | 8 + .../ServerConfigs/ProxiedUriServer.cs | 8 + 3 files changed, 266 insertions(+) create mode 100644 tests/Meilisearch.Tests/FacetingSearchTests.cs diff --git a/tests/Meilisearch.Tests/FacetingSearchTests.cs b/tests/Meilisearch.Tests/FacetingSearchTests.cs new file mode 100644 index 00000000..abfd267b --- /dev/null +++ b/tests/Meilisearch.Tests/FacetingSearchTests.cs @@ -0,0 +1,250 @@ +using System.Linq; +using System.Threading.Tasks; + +using FluentAssertions; + +using Xunit; + +namespace Meilisearch.Tests +{ + public abstract class FacetingSearchTests : IAsyncLifetime where TFixture : IndexFixture + { + private Index _indexForFaceting; + //private Index _basicIndex; + //private Index _nestedIndex; + //private Index _indexWithIntId; + //private Index _productIndexForDistinct; + + private readonly TFixture _fixture; + + public FacetingSearchTests(TFixture fixture) + { + _fixture = fixture; + } + + public async Task InitializeAsync() + { + await _fixture.DeleteAllIndexes(); // Test context cleaned for each [Fact] + _indexForFaceting = await _fixture.SetUpIndexForFaceting("IndexForFaceting-SearchTests"); + //_basicIndex = await _fixture.SetUpBasicIndex("BasicIndex-SearchTests"); + //_indexWithIntId = await _fixture.SetUpBasicIndexWithIntId("IndexWithIntId-SearchTests"); + //_nestedIndex = await _fixture.SetUpIndexForNestedSearch("IndexForNestedDocs-SearchTests"); + //_productIndexForDistinct = await _fixture.SetUpIndexForDistinctProductsSearch("IndexForDistinctProducts-SearchTests"); + } + + public Task DisposeAsync() => Task.CompletedTask; + + [Fact] + public async Task BasicFacetSearch() + { + var results = await _indexForFaceting.FacetSearchAsync("genre"); + + Assert.Equal(4, results.FacetHits.Count()); + Assert.Null(results.FacetQuery); + } + + //[Fact] + //public async Task BasicFacetSearchWithNoFacet() + //{ + // var results = await _indexForFaceting.SearchFacetsAsync(null); + + // results.FacetHits.Should().BeEmpty(); + //} + + //[Fact] + //public async Task BasicFacetSearchWithEmptyFacet() + //{ + // var results = await _indexForFaceting.SearchFacetsAsync(string.Empty); + + // results.FacetHits.Should().BeEmpty(); + //} + + [Fact] + public async Task FacetSearchWithFilter() + { + var query = new SearchFacetsQuery() + { + Filter = "genre = SF" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Single(results.FacetHits); + Assert.Equal("SF", results.FacetHits.First().Value); + Assert.Equal(2, results.FacetHits.First().Count); + Assert.Null(results.FacetQuery); + } + + [Fact] + public async Task FacetSearchWithFilterWithSpaces() + { + var query = new SearchFacetsQuery() + { + Filter = "genre = 'sci fi'" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Single(results.FacetHits); + Assert.Equal("sci fi", results.FacetHits.First().Value); + Assert.Equal(1, results.FacetHits.First().Count); + Assert.Null(results.FacetQuery); + } + + [Fact] + public async Task FacetSearchWithFilterFacetIsNotNull() + { + var query = new SearchFacetsQuery() + { + Filter = "genre IS NOT NULL" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Equal(4, results.FacetHits.Count()); + Assert.Equal("Action", results.FacetHits.First().Value); + Assert.Equal(3, results.FacetHits.First().Count); + Assert.Null(results.FacetQuery); + } + + [Fact] + public async Task FacetSearchWithMultipleFilter() + { + var newFilters = new Settings + { + FilterableAttributes = new string[] { "genre", "id" }, + }; + var task = await _indexForFaceting.UpdateSettingsAsync(newFilters); + task.TaskUid.Should().BeGreaterOrEqualTo(0); + await _indexForFaceting.WaitForTaskAsync(task.TaskUid); + + var query = new SearchFacetsQuery() + { + Filter = "genre = SF AND id != 13" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Single(results.FacetHits); + Assert.Equal("SF", results.FacetHits.First().Value); + Assert.Equal(1, results.FacetHits.First().Count); + Assert.Null(results.FacetQuery); + } + + [Fact] + public async Task FacetSearchWithFilterFacetIsNull() + { + var query = new SearchFacetsQuery() + { + Filter = "genre IS NULL" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Empty(results.FacetHits); + Assert.Null(results.FacetQuery); + } + + [Fact] + public async Task FacetSearchWithFacetQuery() + { + var query = new SearchFacetsQuery() + { + FacetQuery = "SF" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Single(results.FacetHits); + Assert.Equal("SF", results.FacetHits.First().Value); + Assert.Equal(2, results.FacetHits.First().Count); + results.FacetQuery.Should().NotBeNullOrEmpty(); + } + + [Fact] + public async Task FacetSearchWithFacetQueryWithSpaces() + { + var query = new SearchFacetsQuery() + { + FacetQuery = "sci fi" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Single(results.FacetHits); + Assert.Equal("sci fi", results.FacetHits.First().Value); + Assert.Equal(1, results.FacetHits.First().Count); + results.FacetQuery.Should().NotBeNullOrEmpty(); + } + + [Fact] + public async Task FacetSearchWithLooseFacetQuery() + { + var query = new SearchFacetsQuery() + { + FacetQuery = "s" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Equal(2, results.FacetHits.Count()); + Assert.Equal("sci fi", results.FacetHits.First().Value); + Assert.Equal(1, results.FacetHits.First().Count); + results.FacetQuery.Should().NotBeNullOrEmpty(); + } + + [Fact] + public async Task FacetSearchWithLooseQuery() + { + var query = new SearchFacetsQuery() + { + Query = "s" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Equal(3, results.FacetHits.Count()); + Assert.Contains(results.FacetHits, x => x.Value.Equals("Action") && x.Count == 1); + Assert.Contains(results.FacetHits, x => x.Value.Equals("SF") && x.Count == 2); + Assert.Contains(results.FacetHits, x => x.Value.Equals("sci fi") && x.Count == 1); + Assert.Null(results.FacetQuery); + } + + [Fact] + public async Task FacetSearchWithMultipleQueryAndLastMatchingStrategy() + { + var query = new SearchFacetsQuery() + { + Query = "action spider man", + MatchingStrategy = "last" + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Single(results.FacetHits); + results.FacetHits.First().Count.Should().Be(3); + Assert.Null(results.FacetQuery); + } + + [Fact] + public async Task FacetSearchWithMultipleQueryAndAllMatchingStrategy() + { + var query = new SearchFacetsQuery() + { + Query = "action spider man", + MatchingStrategy = "all", + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Single(results.FacetHits); + results.FacetHits.First().Count.Should().Be(1); + Assert.Null(results.FacetQuery); + } + + [Fact] + public async Task FacetSearchWithMultipleQueryAndAllMatchingStrategyAndAttributesToSearchOn() + { + var query = new SearchFacetsQuery() + { + Query = "spider man", + MatchingStrategy = "all", + AttributesToSearchOn = new[] { "name" } + }; + var results = await _indexForFaceting.FacetSearchAsync("genre", query); + + Assert.Single(results.FacetHits); + results.FacetHits.First().Count.Should().Be(1); + Assert.Null(results.FacetQuery); + } + } +} diff --git a/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs b/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs index c8920cf2..5f3d2a1d 100644 --- a/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs +++ b/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs @@ -72,6 +72,14 @@ public MultiIndexSearchTests(ConfigFixture fixture) : base(fixture) } } + [Collection(CollectionFixtureName)] + public class FacetingSearchTests : FacetingSearchTests + { + public FacetingSearchTests(ConfigFixture fixture) : base(fixture) + { + } + } + [Collection(CollectionFixtureName)] public class SettingsTests : SettingsTests { diff --git a/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs b/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs index 50abd3b7..cea66077 100644 --- a/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs +++ b/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs @@ -72,6 +72,14 @@ public MultiIndexSearchTests(ConfigFixture fixture) : base(fixture) } } + [Collection(CollectionFixtureName)] + public class FacetingSearchTests : FacetingSearchTests + { + public FacetingSearchTests(ConfigFixture fixture) : base(fixture) + { + } + } + [Collection(CollectionFixtureName)] public class SettingsTests : SettingsTests { From d52309dff684cecad2b25ded6e33396e8d4b28a8 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 4 Dec 2024 11:36:01 -0600 Subject: [PATCH 4/9] code samples --- .code-samples.meilisearch.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 0a788658..c1dcb4f9 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -782,3 +782,16 @@ distinct_attribute_guide_distinct_parameter_1: |- Distinct = "sku" }; await client.Index("products").SearchAsync("white shirt", params); +facet_search_1: |- + var query = new SearchFacetsQuery() + { + FacetQuery = "fiction", + Filter = "rating > 3" + }; + await client.Index("books").FacetSearchAsync("genres", query); +facet_search_2: |- + var query = new SearchFacetsQuery() + { + FacetQuery = "c" + }; + await client.Index("books").FacetSearchAsync("genres", query); From 5dbd4f890ea242fd3f2142b31daf39f8bf615adc Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 4 Dec 2024 11:41:02 -0600 Subject: [PATCH 5/9] code samples --- .code-samples.meilisearch.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index c1dcb4f9..ba4e9840 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -782,6 +782,19 @@ distinct_attribute_guide_distinct_parameter_1: |- Distinct = "sku" }; await client.Index("products").SearchAsync("white shirt", params); +search_parameter_reference_ranking_score_threshold_1: |- + var params = new SearchQuery() + { + RankingScoreThreshold = 0.2M + }; + await client.Index("INDEX_NAME").SearchAsync("badman", params); +get_dictionary_1: |- + var indexDictionary = await client.Index("books").GetDictionaryAsync(); +update_dictionary_1: |- + var newDictionary = new string[] { "J. R. R.", "W. E. B." }; + await client.Index("books").UpdateDictionaryAsync(newDictionary); +reset_dictionary_1: |- + await client.Index("books").ResetDictionaryAsync(); facet_search_1: |- var query = new SearchFacetsQuery() { From c0261af415fed8e41d7326a233dd3220ef78b519 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 4 Dec 2024 11:43:44 -0600 Subject: [PATCH 6/9] names are more appropriate relative to method and convention --- ...archFacetsQuery.cs => FacetSearchQuery.cs} | 2 +- ...chFacetsResult.cs => FacetSearchResult.cs} | 2 +- src/Meilisearch/Index.Documents.cs | 10 ++++---- .../Meilisearch.Tests/FacetingSearchTests.cs | 24 +++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) rename src/Meilisearch/{SearchFacetsQuery.cs => FacetSearchQuery.cs} (97%) rename src/Meilisearch/{SearchFacetsResult.cs => FacetSearchResult.cs} (97%) diff --git a/src/Meilisearch/SearchFacetsQuery.cs b/src/Meilisearch/FacetSearchQuery.cs similarity index 97% rename from src/Meilisearch/SearchFacetsQuery.cs rename to src/Meilisearch/FacetSearchQuery.cs index 7e7fb2fe..24c208b4 100644 --- a/src/Meilisearch/SearchFacetsQuery.cs +++ b/src/Meilisearch/FacetSearchQuery.cs @@ -6,7 +6,7 @@ namespace Meilisearch /// /// Wrapper for facet search query /// - public class SearchFacetsQuery + public class FacetSearchQuery { /// /// Gets or sets the facetName property diff --git a/src/Meilisearch/SearchFacetsResult.cs b/src/Meilisearch/FacetSearchResult.cs similarity index 97% rename from src/Meilisearch/SearchFacetsResult.cs rename to src/Meilisearch/FacetSearchResult.cs index 58ed3044..bc7a8a8a 100644 --- a/src/Meilisearch/SearchFacetsResult.cs +++ b/src/Meilisearch/FacetSearchResult.cs @@ -6,7 +6,7 @@ namespace Meilisearch /// /// Wrapper for FacetSearchResponse /// - public class SearchFacetsResult + public class FacetSearchResult { /// /// Gets or sets the facetHits property diff --git a/src/Meilisearch/Index.Documents.cs b/src/Meilisearch/Index.Documents.cs index 5b868a63..e21c0097 100644 --- a/src/Meilisearch/Index.Documents.cs +++ b/src/Meilisearch/Index.Documents.cs @@ -550,13 +550,13 @@ public async Task> SearchAsync(string query, /// The search criteria to find the facet matches. /// The cancellation token for this call. /// Facets meeting the search criteria. - public async Task FacetSearchAsync(string facetName, - SearchFacetsQuery query = default, CancellationToken cancellationToken = default) + public async Task FacetSearchAsync(string facetName, + FacetSearchQuery query = default, CancellationToken cancellationToken = default) { - SearchFacetsQuery body; + FacetSearchQuery body; if (query == null) { - body = new SearchFacetsQuery() { FacetName = facetName }; + body = new FacetSearchQuery() { FacetName = facetName }; } else { @@ -569,7 +569,7 @@ public async Task FacetSearchAsync(string facetName, .ConfigureAwait(false); return await responseMessage.Content - .ReadFromJsonAsync(cancellationToken: cancellationToken) + .ReadFromJsonAsync(cancellationToken: cancellationToken) .ConfigureAwait(false); } } diff --git a/tests/Meilisearch.Tests/FacetingSearchTests.cs b/tests/Meilisearch.Tests/FacetingSearchTests.cs index abfd267b..cf60666e 100644 --- a/tests/Meilisearch.Tests/FacetingSearchTests.cs +++ b/tests/Meilisearch.Tests/FacetingSearchTests.cs @@ -62,7 +62,7 @@ public async Task BasicFacetSearch() [Fact] public async Task FacetSearchWithFilter() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { Filter = "genre = SF" }; @@ -77,7 +77,7 @@ public async Task FacetSearchWithFilter() [Fact] public async Task FacetSearchWithFilterWithSpaces() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { Filter = "genre = 'sci fi'" }; @@ -92,7 +92,7 @@ public async Task FacetSearchWithFilterWithSpaces() [Fact] public async Task FacetSearchWithFilterFacetIsNotNull() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { Filter = "genre IS NOT NULL" }; @@ -115,7 +115,7 @@ public async Task FacetSearchWithMultipleFilter() task.TaskUid.Should().BeGreaterOrEqualTo(0); await _indexForFaceting.WaitForTaskAsync(task.TaskUid); - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { Filter = "genre = SF AND id != 13" }; @@ -130,7 +130,7 @@ public async Task FacetSearchWithMultipleFilter() [Fact] public async Task FacetSearchWithFilterFacetIsNull() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { Filter = "genre IS NULL" }; @@ -143,7 +143,7 @@ public async Task FacetSearchWithFilterFacetIsNull() [Fact] public async Task FacetSearchWithFacetQuery() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { FacetQuery = "SF" }; @@ -158,7 +158,7 @@ public async Task FacetSearchWithFacetQuery() [Fact] public async Task FacetSearchWithFacetQueryWithSpaces() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { FacetQuery = "sci fi" }; @@ -173,7 +173,7 @@ public async Task FacetSearchWithFacetQueryWithSpaces() [Fact] public async Task FacetSearchWithLooseFacetQuery() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { FacetQuery = "s" }; @@ -188,7 +188,7 @@ public async Task FacetSearchWithLooseFacetQuery() [Fact] public async Task FacetSearchWithLooseQuery() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { Query = "s" }; @@ -204,7 +204,7 @@ public async Task FacetSearchWithLooseQuery() [Fact] public async Task FacetSearchWithMultipleQueryAndLastMatchingStrategy() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { Query = "action spider man", MatchingStrategy = "last" @@ -219,7 +219,7 @@ public async Task FacetSearchWithMultipleQueryAndLastMatchingStrategy() [Fact] public async Task FacetSearchWithMultipleQueryAndAllMatchingStrategy() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { Query = "action spider man", MatchingStrategy = "all", @@ -234,7 +234,7 @@ public async Task FacetSearchWithMultipleQueryAndAllMatchingStrategy() [Fact] public async Task FacetSearchWithMultipleQueryAndAllMatchingStrategyAndAttributesToSearchOn() { - var query = new SearchFacetsQuery() + var query = new FacetSearchQuery() { Query = "spider man", MatchingStrategy = "all", From c1a15300d87e6208e3eeef80b2b6d8da409937f4 Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 4 Dec 2024 11:45:30 -0600 Subject: [PATCH 7/9] rename test class and file --- ...{FacetingSearchTests.cs => FacetSearchTests.cs} | 14 +++----------- .../ServerConfigs/BaseUriServer.cs | 2 +- .../ServerConfigs/ProxiedUriServer.cs | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) rename tests/Meilisearch.Tests/{FacetingSearchTests.cs => FacetSearchTests.cs} (91%) diff --git a/tests/Meilisearch.Tests/FacetingSearchTests.cs b/tests/Meilisearch.Tests/FacetSearchTests.cs similarity index 91% rename from tests/Meilisearch.Tests/FacetingSearchTests.cs rename to tests/Meilisearch.Tests/FacetSearchTests.cs index cf60666e..a23b42af 100644 --- a/tests/Meilisearch.Tests/FacetingSearchTests.cs +++ b/tests/Meilisearch.Tests/FacetSearchTests.cs @@ -7,17 +7,13 @@ namespace Meilisearch.Tests { - public abstract class FacetingSearchTests : IAsyncLifetime where TFixture : IndexFixture + public abstract class FacetSearchTests : IAsyncLifetime where TFixture : IndexFixture { private Index _indexForFaceting; - //private Index _basicIndex; - //private Index _nestedIndex; - //private Index _indexWithIntId; - //private Index _productIndexForDistinct; private readonly TFixture _fixture; - public FacetingSearchTests(TFixture fixture) + public FacetSearchTests(TFixture fixture) { _fixture = fixture; } @@ -26,10 +22,6 @@ public async Task InitializeAsync() { await _fixture.DeleteAllIndexes(); // Test context cleaned for each [Fact] _indexForFaceting = await _fixture.SetUpIndexForFaceting("IndexForFaceting-SearchTests"); - //_basicIndex = await _fixture.SetUpBasicIndex("BasicIndex-SearchTests"); - //_indexWithIntId = await _fixture.SetUpBasicIndexWithIntId("IndexWithIntId-SearchTests"); - //_nestedIndex = await _fixture.SetUpIndexForNestedSearch("IndexForNestedDocs-SearchTests"); - //_productIndexForDistinct = await _fixture.SetUpIndexForDistinctProductsSearch("IndexForDistinctProducts-SearchTests"); } public Task DisposeAsync() => Task.CompletedTask; @@ -43,7 +35,7 @@ public async Task BasicFacetSearch() Assert.Null(results.FacetQuery); } - //[Fact] + //[Fact] //these may or may not be required. //public async Task BasicFacetSearchWithNoFacet() //{ // var results = await _indexForFaceting.SearchFacetsAsync(null); diff --git a/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs b/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs index 5f3d2a1d..38d17dbf 100644 --- a/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs +++ b/tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs @@ -73,7 +73,7 @@ public MultiIndexSearchTests(ConfigFixture fixture) : base(fixture) } [Collection(CollectionFixtureName)] - public class FacetingSearchTests : FacetingSearchTests + public class FacetingSearchTests : FacetSearchTests { public FacetingSearchTests(ConfigFixture fixture) : base(fixture) { diff --git a/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs b/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs index cea66077..7b07233f 100644 --- a/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs +++ b/tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs @@ -73,7 +73,7 @@ public MultiIndexSearchTests(ConfigFixture fixture) : base(fixture) } [Collection(CollectionFixtureName)] - public class FacetingSearchTests : FacetingSearchTests + public class FacetingSearchTests : FacetSearchTests { public FacetingSearchTests(ConfigFixture fixture) : base(fixture) { From a1c279001d9fcf5456979c6f5a7d68c92ba1616c Mon Sep 17 00:00:00 2001 From: Dan Fehrenbach Date: Wed, 4 Dec 2024 12:00:56 -0600 Subject: [PATCH 8/9] change filter to dynamic to allow for strings and arrays --- src/Meilisearch/FacetSearchQuery.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Meilisearch/FacetSearchQuery.cs b/src/Meilisearch/FacetSearchQuery.cs index 24c208b4..20eb34d1 100644 --- a/src/Meilisearch/FacetSearchQuery.cs +++ b/src/Meilisearch/FacetSearchQuery.cs @@ -30,7 +30,7 @@ public class FacetSearchQuery /// Gets or sets the filter property /// [JsonPropertyName("filter")] - public string Filter { get; set; } + public dynamic Filter { get; set; } /// /// Gets or sets the matchingStrategy property, can be last, all or frequency. From c88e22f5f81bfc74b5bb56a209b8d00dceca66a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mentine?= Date: Wed, 8 Jan 2025 15:49:39 +0100 Subject: [PATCH 9/9] Update .code-samples.meilisearch.yaml --- .code-samples.meilisearch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index ba4e9840..8744d03d 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -802,7 +802,7 @@ facet_search_1: |- Filter = "rating > 3" }; await client.Index("books").FacetSearchAsync("genres", query); -facet_search_2: |- +facet_search_3: |- var query = new SearchFacetsQuery() { FacetQuery = "c"