How to NOT have a rigid search parameter

How do I go about creating a search based on n attributes, where I would like to order in which the results are returned to be based on the number of attributes that match?

Example. Let us say each of my record has the following data structure:

    attribute_1: "x",
    attribute_2: 40,
    attribute_3: true,

I execute a search with the following params:

    filters: [
       'attribute_1: x',
       'attribute_2: 40',
       'attribute_3: true',

I get records where all the attributes match the above conditions.

Instead, I would like to get all records in the following order / rank:

  • first N records in the result are having all attributes matching the above condition
  • second M records in the same result are having at least 2 of the above conditions matching
  • third O records in the same result are having at least 1 of the above condition matching
  • last records in the result do not match any condition

I am not sure of the term to search for this requirement - I think this is a common use case and probably is documented, but I am not able to come up with the correct keywords or terms to search this in Algolia’s documentation. Any hints would be helpful

There’s not a way to explicitly say how many records to be returned from each criteria. The closest I can think of is to use optionalFilters so records that don’t match all the criteria still show up in the results but in a ranking order:

Thank you. That is exactly what I was looking for.

1 Like