-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
591: SortFacetValuesBy support r=curquiza a=danFbach # Pull Request ## Related issue Fixes #460 ## What does this PR do? -implements sort facets feature ## 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? let me know if i missed anything. Co-authored-by: Dan Fehrenbach <[email protected]> Co-authored-by: Clémentine <[email protected]>
- Loading branch information
Showing
4 changed files
with
95 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Meilisearch.Converters | ||
{ | ||
public class SortFacetValuesConverter : JsonConverter<SortFacetValuesByType> | ||
{ | ||
public override SortFacetValuesByType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == JsonTokenType.String) | ||
{ | ||
var enumValue = reader.GetString(); | ||
if (Enum.TryParse<SortFacetValuesByType>(enumValue, true, out var sortFacetValues)) | ||
{ | ||
return sortFacetValues; | ||
} | ||
} | ||
|
||
// If we reach here, it means we encountered an unknown value, so we'll use meilisearch default of Alpha | ||
return SortFacetValuesByType.Alpha; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, SortFacetValuesByType value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToString().ToLower()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,39 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
using Meilisearch.Converters; | ||
|
||
namespace Meilisearch | ||
{ | ||
/// <summary> | ||
/// Faceting configuration. | ||
/// </summary> | ||
public class Faceting | ||
{ | ||
/// <summary> | ||
/// Gets or sets maxValuesPerFacet. | ||
/// </summary> | ||
[JsonPropertyName("maxValuesPerFacet")] | ||
public int MaxValuesPerFacet { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets sortFacetValuesBy. | ||
/// </summary> | ||
[JsonPropertyName("sortFacetValuesBy")] | ||
public Dictionary<string, SortFacetValuesByType> SortFacetValuesBy { get; set; } | ||
} | ||
|
||
[JsonConverter(typeof(SortFacetValuesConverter))] | ||
public enum SortFacetValuesByType | ||
{ | ||
/// <summary> | ||
/// Sort by alphanumerical value. | ||
/// </summary> | ||
Alpha, | ||
|
||
/// <summary> | ||
/// Sort by count value. | ||
/// </summary> | ||
Count | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters