[HELP] Same match in different attributes - a particular case

EDIT: to show the problem I created a Demo UI at https://www.algolia.com/realtime-search-demo/test-interface-72361ffd-a44a-4a1b-95e1-0eadcaba31df Please try to perform the example search there.

Hey there,

Context

I have the following recordset in my index

[
    {
        "name" : "Don Joe",
        "experience": {
          "job_title": "Example 1",
          "superpowers": [
            "Golang", // <- MATCH (see below)
            "Vue",    // <- MATCH (see below)
            "React"
          ],
          "skills": [
            "Docker",
            "Goa",
            "Elixir",
            "Kubernetes",
            "Istio",
            "Phoenix",
            "Javascript"
          ]
      },
      "completed_at": 1590509228,
    },
    {
        "name" : "John Doe"
        "experience": {
          "job_title": "Example 2",
          "superpowers": [
            "Golang", // <- MATCH (see below)
            "Phoenix",
            "React"
          ],
          "skills": [
            "Docker",
            "Vue",    // <- MATCH (see below)
            "Kubernetes",
            "Elixir",
            "Goa",
            "Javascript",
            "Typescript"
          ]
      },
      "completed_at": 1590519361,
    }
]

The searchable attributes are set as

  • unordered(experience.superpowers)
  • unordered(experience.skills)

The ranking is the default one, plus

  • custom ranking desc(completed_at)

What I do

A simple textual search Golang Vue

What I expect

Superpowers have priority over skills, so since “Don Joe” has Golang and Vue in his superpowers ( while “John Doe” has Golang superpower and Vue skill) should appear first

What happens instead

The 2 records have the same score, and tie-breaking algorithm brings up the wrong one (which is not the main issue here, the issue is they have same score in first place)

Any idea in how I should configure algolia to perform what I expect?

Thanks in advance

Why in 3 days nobody answered from the team? Is anything wrong in the statement of the problem? how can I help you by providing more info?

Solution

I solved as follows:

  1. Convert a textual search to a “facets based” search
  2. Set up experience.skills and experience.superpowers to be facets
  3. use a series of OR filters with scores to get the desired facets
    {
       "filters": "experience.skills:Vue<score=1> OR experience.skills:Golang<score=1> OR experience.superpowers:Vue<score=2> OR experience.superpowers:Golang<score=2>",
       "sumOrFiltersScores": true 
    }
    
    IMPORTANT: set "sumOrFiltersScores": true to enable sum of scores and use a weighted search
  4. Call your search method using the payload in previous step.

Resources:

1 Like

Hello @devops2,

We’re very sorry for the late reply, as we are currently experiencing a very high amount of support tickets.

I’m really glad that you were able to find the solution by yourself and contributed to the community by taking the time to write your solution here. We are extremely grateful for this, thank you!