0

I have some difficulties in the ranking configuration in algolia. I have a resultset like this when I search for "Contrat" :

[
  {
    "ope_id" : 1,
    "ope_lib" : "Contrat de maintenance en entretien de toitures",
    "ope_description" : "Réalisation d'un entretien régulier des toitures",
    "ope_nb_offre" : "42"
  },
  {
    "ope_id" : 2,
    "ope_lib" : "Contrat d'entretien de pompe à chaleur",
    "ope_description" : "<h2>Confort et sécurité au quotidien</h2> <h3>Votre domicile est équipé d’une pompe à chaleur comme système de chauffage ?</h3>Qu’elle soit géothermique ou aérothermique, il est indispensable de veiller à son entretien. En effet, en cas de dysfonctionnement, son efficacité sera réduite ce qui nuira à votre confort intérieur.En souscrivant un contrat d’entretien avec un professionnel pour votre pompe à chaleur, la durée de vie de votre installation sera prolongée et ses performances seront en permanence optimales, vous évitant ainsi toute augmentation de vos dépenses énergétiques.<h3>Le contrat d’entretien inclut :</h3> <ul> <li>Une révision annuelle de votre pompe à chaleur</li> <li>La vérification des fluides frigorigènes par un professionnel certifié Qualipac (opération imposée par la réglementation sur les appareils contenant plus de 2 kg de fluide)</li> <li>le remplacement des pièces et accessoires usagés</li> <li>un service de dépannage</li> </ul>",
    "ope_nb_offre" : "41"
  },
  {
   "ope_id" : 3,
    "ope_lib" : "Contrat d'entretien de chaudière murale au gaz",
    "ope_description" : "<h2>Economie d'énergie et sécurité de votre habitat</h2> <h3>Pour le chauffage et la production d’eau chaude, vous utilisez une chaudière au gaz ?</h3><span style=\"font-size: small;\">Les défaillances de cet appareil peuvent avoir des conséquences désagréables voire dangereuses. Afin d’éviter les risques de panne ou d’intoxication, vous avez la possibilité de souscrire un contrat d’entretien auprès d’un professionnel spécialisé.</span> <span style=\"font-size: small;\">Ce contrat vous garantira le bon état permanent de votre chaudière, il comprend : </span><h3 style=\"text-align: left;\"><span style=\"font-size: medium;\">Une visite annuelle incluant :</span></h3> <div> <ul> <li style=\"text-align: left;\"><span style=\"font-size: small;\"> Le nettoyage des composants de votre chaudière ( corps de chauffe , brûleur , extracteur, veilleuse)</span></li> <li style=\"text-align: left;\"><span style=\"font-size: small;\"> Le réglage des organes de régulations et des systèmes de sécurité</span></li> <li style=\"text-align: left;\"><span style=\"font-size: small;\"> La vérification de l’état, de la nature et de la géométrie du conduit de raccordement de l’appareil.</span></li> <li style=\"text-align: left;\"><span style=\"font-size: small;\"> La mesure des polluants atmosphériques (teneur en monoxyde de carbone)</span></li> <li style=\"text-align: left;\"><span style=\"font-size: small;\"> Le contrôle des points liés à la sécurité des biens et des personnes (entrée d\'air, évacuation des gaz de combustion)</span></li> </ul> <h3><span style=\"font-size: medium;\">Un dépannage éventuel sur appel justifié du souscripteur du contrat</span></h3> </div> <h2>Certificat nécessaire à votre assurance</h2>",
    "ope_nb_offre" : "265"
  }
]

And I don't understand why the ope_id 1 is displayed before the other. Here is ma algolia config : Searchable attributes : "ope_lib,ope_description" (unordered) Custom ranking attributes : "ope_nb_offre". Sort by attributes : false. Ranking formula : - typo - attribute - exact - geo - words - filters - proximity Custom ranking criteria (as said above) : desc(op_nb_offre).

ope_id 3 has more occurrences of my search keyword "contrat" AND ha more ope_nb_offre than the other, but it still is displayed after them.

If it helps, here is the ranking info for each result :

OPE_ID 1:
1 Number of typos 0
2 Best matching attribute
- ope_lib,ope_description (1st word)
3 Exact words count 0 (=> Why 0??)
4 Matching words 1
5 Matching filters 0
6 Proximity distance 0
7 Custom Ranking
- ope_nb_offre_total=42

OPE_ID 2
1 Number of typos 0
2 Best matching attribute
- ope_lib,ope_description (1st word)
3 Exact words count 0 (=> Why 0??)
4 Matching words 1
5 Matching filters 0
6 Proximity distance 0
7 Custom Ranking
- ope_nb_offre_total=41
was 
- ope_nb_offre_total=42

OPE_ID 3
1 Number of typos 0
2 Best matching attribute
- ope_lib,ope_description (1st word)
3 Exact words count 0
4 Matching words 1
5 Matching filters 0
6 Proximity distance 0
7 Custom Ranking
- ope_nb_offre_total=265
was 
- ope_nb_offre_total=27 (=> and why is 27 after 265??)

I think I gave all the information I had. If anyone has any clue, please let me know!

Thanks!

1 Answers1

1

Why is 27 after 265?

The attribute ope_nb_offre has been pushed to Algolia as a string. What this means, is that when the engine reaches the custom ranking rule to determine what record is most relevant it will actually try to sort alphabetically instead of numerically.

To solve this, you should re-index your data and make sure you cast that attribute as an integer.

Why you have no exact words count

Algolia uses prefix matching to determine the text relevancy of a record. Prefix matching means that if you type "soft" it will return results having a searchable attribute containing for example "software".

As long as your word is not finished though, the query string is considered as a prefix, meaning it is not a perfect match. The engine has no way to know if you have finished typing.

If you were to add a "space" after "Contrat " then you will see exact matches.

Words frequency

My assumption here is that you have the following configuration in Algolia:

Searchable attributes:

  • unordered(ope_lib)
  • unordered(ope_description)

What you tell the engine here, is that it should first try to find matching words in ope_lib and then in ope_description. What is important here is the order in which those appear in the configuration.

In your configuration, if something matched in the ope_lib, then no matching will be done on ope_description.

To solve this, you can add both those attributes at the same level in the dashboard. Here is a screenshot to illustrate what you should be doing. Please note that in this case, you don't need to wrap the attributes into unordered given it is the default if you have multiple attributes at the same level.

How to add multiple searchable attributes at the same level

rayrutjes
  • 788
  • 11
  • 17