Skip to content

Commit 267c833

Browse files
authored
Merge branch 'main' into sort-facets-value-460
2 parents 7c4bc09 + 1dadb40 commit 267c833

File tree

8 files changed

+396
-2
lines changed

8 files changed

+396
-2
lines changed

.code-samples.meilisearch.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,3 +809,16 @@ facet_search_2: |-
809809
}
810810
};
811811
await client.Index("books").UpdateFacetingAsync(newFaceting);
812+
facet_search_1: |-
813+
var query = new SearchFacetsQuery()
814+
{
815+
FacetQuery = "fiction",
816+
Filter = "rating > 3"
817+
};
818+
await client.Index("books").FacetSearchAsync("genres", query);
819+
facet_search_3: |-
820+
var query = new SearchFacetsQuery()
821+
{
822+
FacetQuery = "c"
823+
};
824+
await client.Index("books").FacetSearchAsync("genres", query);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Collections.Generic;
2+
using System.Text.Json.Serialization;
3+
4+
namespace Meilisearch
5+
{
6+
/// <summary>
7+
/// Wrapper for facet search query
8+
/// </summary>
9+
public class FacetSearchQuery
10+
{
11+
/// <summary>
12+
/// Gets or sets the facetName property
13+
/// </summary>
14+
[JsonPropertyName("facetName")]
15+
public string FacetName { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the facetQuery property
19+
/// </summary>
20+
[JsonPropertyName("facetQuery")]
21+
public string FacetQuery { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets the q property
25+
/// </summary>
26+
[JsonPropertyName("q")]
27+
public string Query { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the filter property
31+
/// </summary>
32+
[JsonPropertyName("filter")]
33+
public dynamic Filter { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the matchingStrategy property, can be <c>last</c>, <c>all</c> or <c>frequency</c>.
37+
/// </summary>
38+
[JsonPropertyName("matchingStrategy")]
39+
public string MatchingStrategy { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets the attributesToSearchOn property
43+
/// </summary>
44+
[JsonPropertyName("attributesToSearchOn")]
45+
public IEnumerable<string> AttributesToSearchOn { get; set; }
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Collections.Generic;
2+
using System.Text.Json.Serialization;
3+
4+
namespace Meilisearch
5+
{
6+
/// <summary>
7+
/// Wrapper for FacetSearchResponse
8+
/// </summary>
9+
public class FacetSearchResult
10+
{
11+
/// <summary>
12+
/// Gets or sets the facetHits property
13+
/// </summary>
14+
[JsonPropertyName("facetHits")]
15+
public IEnumerable<FacetHit> FacetHits { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the facet query
19+
/// </summary>
20+
[JsonPropertyName("facetQuery")]
21+
public string FacetQuery { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets the processingTimeMs property
25+
/// </summary>
26+
[JsonPropertyName("processingTimeMs")]
27+
public int ProcessingTimeMs { get; set; }
28+
29+
/// <summary>
30+
/// Wrapper for Facet Hit
31+
/// </summary>
32+
public class FacetHit
33+
{
34+
/// <summary>
35+
/// Gets or sets the value property
36+
/// </summary>
37+
[JsonPropertyName("value")]
38+
public string Value { get; set; }
39+
40+
/// <summary>
41+
/// Gets or sets the count property
42+
/// </summary>
43+
[JsonPropertyName("count")]
44+
public int Count { get; set; }
45+
}
46+
}
47+
}

src/Meilisearch/Index.Documents.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Linq;
43
using System.Net.Http;
@@ -543,5 +542,35 @@ public async Task<ISearchable<T>> SearchAsync<T>(string query,
543542
.ReadFromJsonAsync<ISearchable<T>>(cancellationToken: cancellationToken)
544543
.ConfigureAwait(false);
545544
}
545+
546+
/// <summary>
547+
/// Search index facets
548+
/// </summary>
549+
/// <param name="facetName">Name of the facet to search.</param>
550+
/// <param name="query">The search criteria to find the facet matches.</param>
551+
/// <param name="cancellationToken">The cancellation token for this call.</param>
552+
/// <returns>Facets meeting the search criteria.</returns>
553+
public async Task<FacetSearchResult> FacetSearchAsync(string facetName,
554+
FacetSearchQuery query = default, CancellationToken cancellationToken = default)
555+
{
556+
FacetSearchQuery body;
557+
if (query == null)
558+
{
559+
body = new FacetSearchQuery() { FacetName = facetName };
560+
}
561+
else
562+
{
563+
body = query;
564+
body.FacetName = facetName;
565+
}
566+
567+
var responseMessage = await _http.PostAsJsonAsync($"indexes/{Uid}/facet-search", body,
568+
Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
569+
.ConfigureAwait(false);
570+
571+
return await responseMessage.Content
572+
.ReadFromJsonAsync<FacetSearchResult>(cancellationToken: cancellationToken)
573+
.ConfigureAwait(false);
574+
}
546575
}
547576
}

src/Meilisearch/SearchQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,6 @@ public class SearchQuery
147147
/// Gets or sets rankingScoreThreshold, a number between 0.0 and 1.0.
148148
/// </summary>
149149
[JsonPropertyName("rankingScoreThreshold")]
150-
public decimal RankingScoreThreshold { get; set; }
150+
public decimal? RankingScoreThreshold { get; set; }
151151
}
152152
}

0 commit comments

Comments
 (0)