Skip to content
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

[v1.3] Sort facets value by alphanumerical or count order #460

Open
3 tasks
brunoocasali opened this issue Aug 8, 2023 · 1 comment
Open
3 tasks

[v1.3] Sort facets value by alphanumerical or count order #460

brunoocasali opened this issue Aug 8, 2023 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@brunoocasali
Copy link
Member

brunoocasali commented Aug 8, 2023

⚠️ This issue is generated, it means the examples and the namings do not necessarily correspond to the language of this repository.
Also, if you are a maintainer, please add any clarification and instructions about this issue.

Sorry if this is already wholly/partially implemented. Feel free to let me know about the state of this issue in the repo.

Related to meilisearch/integration-guides#280


This issue is divided into two sections, first, you need to make the implementation, and second, you must update the code-samples (no one likes outdated docs, right?).

New implementation

Related to:

Adds the ability to sort facets by their value which could be by using alpha or count.

Ensure the SDKs can handle the new index faceting configuration attribute sortFacetValuesBy. This enum could only take count or alpha.

The faceting configuration now have two attributes:

maxValuesPerFacet: integer
sortFacetValuesBy: object 
  index_name: alpha|count
  *: alpha|count // when should be applied to all indexes

Code samples

Inside of this file: .code-samples.meilisearch.yml:

  1. Create a new entry with this key facet_search_2 containing a call to the updateFaceting() settings method.
    "Translate" the following curl example: https://github.com/meilisearch/documentation/blob/e4fdc3d485c22e31a045b8a71bacf18b6a7d50e0/.code-samples.meilisearch.yaml#L1078

  2. Update getting_started_faceting key to contain the new behavior sortFacetValuesBy
    Refer to this curl example: https://github.com/meilisearch/documentation/blob/e4fdc3d485c22e31a045b8a71bacf18b6a7d50e0/.code-samples.meilisearch.yaml#L875

  3. Update update_faceting_settings_1 key to contain the new behavior sortFacetValuesBy
    Refer to this curl example: https://github.com/meilisearch/documentation/blob/e4fdc3d485c22e31a045b8a71bacf18b6a7d50e0/.code-samples.meilisearch.yaml#L854

update_faceting_settings_1: |-
  PATCH 'http://localhost:7700/indexes/books/settings/faceting' 
  with data: {
    "maxValuesPerFacet": 2,
    "sortFacetValuesBy": {
      "*": "alpha",
      "genres": "count"
    }
  }

TODO:

  • Add the ability receive a new param in the updateFaceting settings method called sortFacetValuesBy.
  • Update the code-samples accordingly
  • Add integration tests
@brunoocasali brunoocasali added good first issue Good for newcomers enhancement New feature or request labels Aug 8, 2023
@danFbach
Copy link

danFbach commented Nov 13, 2024

@brunoocasali working on this one as well. does it need to process the facet name into camel case for the user, or is it on the user to provide the correct facet name?

I'm implementing the sortFacetValuesBy type as an enum which will utilizes JsonStringEnumConverter.

I have modified Faceting:

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, SortFacetValuesBy> SortFacetValuesBy { get; set; }
    }

    [JsonConverter(typeof(JsonStringEnumConverter))]
    public enum SortFacetValuesBy
    {
        /// <summary>
        /// Sort by alpha value.
        /// </summary>
        Alpha,

        /// <summary>
        /// Sort by count value.
        /// </summary>
        Count
    }
}

does the key of the dictionary, the facet name, need any automatic JSON serialization to comply with camelcase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants