Nested custom ranking

I have documents with keywords that looks like the one below:

{
  objectID: 1,
  keywords: [
    {value: 'foo', weight: 1},
    {value: 'bar', weight: 2},
  ]
}

Users are able to find documents based on a keywords search using: keywords.value.
But now, I would like to implement a custom ranking based on the keywords weight.
I have tried to use the following settings with no luck:

const settings = {
  searchableAttributes: ['unordered(keywords.value)'],
  customRanking: ['asc(keywords.weight)'],
}

My custom ranking isn’t taken into account. Any idea how I could make it work?
Thanks!

Hi,

If I understand correctly, if you have

[
    {
      objectID: 1,
      keywords: [
        {value: 'foo', weight: 1},
        {value: 'bar', weight: 2},
      ]
    },
    {
      objectID: 2,
      keywords: [
        {value: 'foo', weight: 10},
        {value: 'bar', weight: 1},
      ]
    }
]

When the user search for ‘foo’, he gets object 2 first but if he searches for ‘bar’ he gets object 1 first. Is that correct?

Algolia does ranking at indexing time, in order to return the results faster. Hence, the ranking formula cannot rely on something depending on the query.

Can you give us more details about your data and your usecase so we can find a solution?

When the user search for ‘foo’, he gets object 2 first but if he searches for ‘bar’ he gets object 1 first. Is that correct?

No, it’s not what I have, the hits are returned sorted by objectID desc. No matter the search, the hits are identical when I search with foo and when I search with bar.

I have been writing an automated test to make sure of the behavior.

Hi. I’m still experiencing this issue. I have tried your example with no luck. Is it working on your side?

[
    {
      "objectID": "1",
      "keywords": [
        {"value": "foo", "weight": 1},
        {"value": "bar", "weight": 2}
      ]
    },
    {
      "objectID": "2",
      "keywords": [
        {"value": "foo", "weight": 10},
        {"value": "bar", "weight": 1}
      ]
    }
]