Display record in search result based on search text present in number of search fiels

Here is my index data,

{
objectID:37778
Title:“DST02WH Floral Vanity Set”
Keyword:“vanity bathroom set table vanity desk”
OfferRating:5
CategoryKeywordText:“Furniture & Home Goods , Furniture & Decor , Antiques”
CategoryNameText:“Furniture & Home Goods”
}
{
objectID:37779
Title:“Medium Floral Rental”
Keyword:“flowers florist decor office color”
OfferRating:5
CategoryKeywordText:""
CategoryNameText:“Event Planning , Furniture & Home Goods , Furniture & Decor , Furniture , Furniture & Home Goods , Furniture & Decor , Interior Design , Business & Industrial , Business Supplies , Office Supplies , Event Planning , florist & Decor , Clothing & Consumer Items , Other Clothing & Consumer Items , Flowers & Gift Baskets , Furniture & Home Goods , Furniture & Decor , Business & Industrial , Business Supplies , Business & Industrial , Business Supplies , Other Business Supplies”
}
{
objectID:37777
Title:“Modern floral runner 2-3x5-9”
Keyword:“rug carpet rug pakistan red rust”
OfferRating:5
CategoryKeywordText:“flower design carpet, carpet with big flowers”
CategoryNameText:“Furniture & Home Goods”
}
{
objectID:37780
Title:“18K White Gold florist Pin”
Keyword:“gift women pin accessories”
OfferRating:5
CategoryKeywordText:""
CategoryNameText:“Clothing & Consumer Items , Other Clothing & Consumer Items , Other Gift Items , Jewelry & Watches , Bracelets”
}
{
objectID:37781
Title:“Floral Image Seattle”
Keyword:“flowers decor flower florist”
OfferRating:5
CategoryKeywordText:“decorate venue with seasonal flower, expert in flower design”
CategoryNameText:“Event Planning , florist & Decor , Clothing & Consumer Items , Other Clothing & Consumer Items , Flowers & Gift Baskets”
}

When I search for “florist” without quotation mark, result appears in following order

  1. Floral Image Seattle
  2. DST02WH Floral Vanity Set
  3. Modern floral runner 2-3x5-9
  4. Medium Floral Rental
  5. 18K White Gold florist Pin

However I want result to be

  1. Floral Image Seattle
  2. Medium Floral Rental
  3. Modern floral runner 2-3x5-9
  4. DST02WH Floral Vanity Set
  5. 18K White Gold florist Pin

What I need is if search text is matched against multiple search attributes, I need result to be sorted on descending order of number of attribute it matches. When I search florist

  1. Floral Image Seattle (Matches Title & CategoryKeywordText & CategoryNameText)
  2. Medium Floral Rental (Matches Title & CategoryNameText)
  3. Modern floral runner 2-3x5-9 (Matches Title & CategoryKeywordText)
  4. DST02WH Floral Vanity Set (Matches Title, order of word flower in 2nd as Title attribute is “Ordered”)
  5. 18K White Gold florist Pin (Matches Title, order of word flower in 4th as Title attribute is “Ordered”)

Here is my index configuration,
IndexConfiguration

Quick help is highly appreciated

Hello @jimb,

Thank you for your message. I understand you’d like to see your results ranked in a different order than the one you currently have.

Thank you for all the details (records and settings). I’ve been able to reproduce your index with all your data and settings. However, it seems things are a bit off on my side. Out of the box, when I type “florist” (without the quotation marks), I only get the following results (in that order):

  • 18K White Gold florist Pin
  • Floral Image Seattle
  • Medium Floral Rental

Hence, the following records are not part of my result set:

  • DST02WH Floral Vanity Set
  • Modern floral runner 2-3x5-9

I’m not sure how you get the extra results containing the floral term.

I’ve been able to reproduce nearly exactly what you wanted to achieve using a florist <-> floral (or florist <-> floral <-> flower) and changing the Categories.Name (which seems to be a mistake) searchable attribute from your settings with CategoryKeywordText. This way, I get the following ranking:

  • Floral Image Seattle
  • Medium Floral Rental
  • DST02WH Floral Vanity Set
  • Modern floral runner 2-3x5-9
  • 18K White Gold florist Pin

The fact that this is not working exactly as you expect seems to be that the flower term seems not to match with the synonym. I’ve opened an issue internally to check if this may be an issue on our end.

Regarding the matching of multiple terms which belong to the same lexical field, keep in mind that this is not possible out of the box with most search engines, as they only care about the exact term or prefixes or prefixes with typos. When looking for lexically close terms, you need to instruct the search engines for that, using synonyms in the case of Algolia.

Let me know if this helps. I’ll let you know on my side if I get any extra informations that could be related to your issue.

Hello Anthony,

Thank you for quick reply. I remove Category.Name as it was mistake. Still in my case search result us as mentioned below.

  1. Floral Image Seattle
  2. DST02WH Floral Vanity Set
  3. Medium Floral Rental
  4. Modern floral runner 2-3x5-9
  5. 18K White Gold florist Pin
  • “DST02WH Floral Vanity Set” is in “Furniture & Home Goods” category while “Medium Floral Rental” is in " florist & Decor" category.

  • As “Medium Floral Rental” matches 2 search attributes while “DST02WH Floral Vanity Set” matches only one, “DST02WH Floral Vanity Set” should be below “Medium Floral Rental”.

  • Again “Modern floral runner 2-3x5-9” matches Title & CategoryKeywordText it should be ahead of “DST02WH Floral Vanity Set”.

  • “DST02WH Floral Vanity Set” should be 4th and “18K White Gold florist Pin” should be 5th as matching word in “DST02WH Floral Vanity Set” as 2nd position while in “18K White Gold florist Pin” at 4th position.

So result order should be,

  1. Floral Image Seattle (Matches Title & CategoryKeywordText & CategoryNameText)
  2. Medium Floral Rental (Matches Title & CategoryNameText)
  3. Modern floral runner 2-3x5-9 (Matches Title & CategoryKeywordText)
  4. DST02WH Floral Vanity Set (Matches Title, order of word flower in 2nd as Title attribute is “Ordered”)
  5. 18K White Gold florist Pin (Matches Title, order of word flower in 4th as Title attribute is “Ordered”)

Hello again,

I’m not sure to understand how your result set may contain DST02WH Floral Vanity Set and Modern floral runner 2-3x5-9 as those records do not contain your original florist query term. Could you tell us if you are using any synonym or other settings? Normally, typing florist shouldn’t bring those two records if you only changed searchableAttributes in your settings.

I think I’m missing some context here to provide you the best appropriate solution for your use-case. Could you let me know your exact settings configuration?

Thank you in advance for your answer.

Hello Anthony,

We have synonyms as mention below and that is why results are correct.

florist :left_right_arrow: flower :left_right_arrow: floral

I just want to change order of result based on logic I mentioned below.

  1. Floral Image Seattle (Matches Title & CategoryKeywordText & CategoryNameText)
  2. Medium Floral Rental (Matches Title & CategoryNameText)
  3. Modern floral runner 2-3x5-9 (Matches Title & CategoryKeywordText)
  4. DST02WH Floral Vanity Set (Matches Title, order of word flower/floral/florist is 2nd as Title attribute is “Ordered”)
  5. 18K White Gold florist Pin (Matches Title, order of word flower/floral/florist in 4th as Title attribute is “Ordered”)

What I need is, if search text appears in searchable attribute, it should sort them in descending order of number of attribute includes search text. If search text appears in 3 attributes it should be ahead of record for which search text appears in 2 attributes.

Let me know if I am still not clear.

Thank you for the additional details regarding your synonym setup.

As mentionned before, I’m able to reproduce what you want with the florist <> floral <> flower 3-terms synonym and searchableAttributes set to [ordered(Title), ordered(CategoryKeywordText), ordered(CategoryNameText)] expect that results 3. and 4. are inverted (DST02WH Floral Vanity Set is 3rd whereas Modern floral runner 2-3x5-9 is 4th).

As I told you before, it seems to be a bug or a limitation of the engine and I’ve opened a ticket internally on which I’m notified. I’ll let you know once I’ll get more informations regarding this.

I’m sorry not to be able to help further at the moment. I’ll answer on this topic at the moment I’ll have a better answer for you. Thank you for your patience and your understanding.

Hello Anthony,

Simple queston, is following possible?

I just want to change order of result based on logic I mentioned below.

  1. Floral Image Seattle (Matches Title & CategoryKeywordText & CategoryNameText)
  2. Medium Floral Rental (Matches Title & CategoryNameText)
  3. Modern floral runner 2-3x5-9 (Matches Title & CategoryKeywordText)
  4. DST02WH Floral Vanity Set (Matches Title, order of word flower/floral/florist is 2nd as Title attribute is “Ordered”)
  5. 18K White Gold florist Pin (Matches Title, order of word flower/floral/florist in 4th as Title attribute is “Ordered”)

What I need is, if search text appears in searchable attribute, it should sort them in descending order of number of attribute includes search text. If search text appears in 3 attributes it should be ahead of record for which search text appears in 2 attributes.

Yes or No?

Hello again @jimb,

I’ve discussed with other colleagues at Algolia and what you want to do is actually not possible. This is due to the fact that when using a synonym, only one of the alternatives will be used to match the record, not all of them. It means that even if you records would match against multiple alternatives of the synonym, only one of them is used.

Also, the ordered option in searchableAttributes does not relate to the order of your list of alternatives in a synonym, because alternatives are all equivalent in term of score. What ordered means is that a record with an attribute matching at the beginning of the field would be ranked higher than one with an attribute matching in the middle or at the end. See https://www.algolia.com/doc/api-reference/api-parameters/searchableAttributes/#parameter-option-ordered for more details about this. In other words, ordered/unordered in searchableAttributes does not relate to synonyms.

I’m sorry not to be able to find a more suitable solution for your use-case. The fact that DST02WH Floral Vanity Set is ranked just before Modern floral runner 2-3x5-9 with the settings I suggested you is that these two records do match with exactly the same criterion and the engine, to differentiate them, use alphabetical order between DST... < Modern ... in the first attribute.

Hello Anthony,

Again simple questions. I have 2 records,

{
objectID:1
Title:“Seattle best coffee”
Keyword:“bes coffe in seattle"
OfferRating:5
CategoryKeywordText:”"
CategoryNameText:“Food & Drink”
}
{
objectID:2
Title:“Best Coffee table”
Keyword:“best coffee table for your garden”
OfferRating:5
CategoryKeywordText:""
CategoryNameText:“Furniture”
}

Assume that user is searching coffee and I want to show coffee from food & drink first and later want to show coffee from furniture.

How can I achieve this?

This is possible but depending on the input query it may not be relevant.

I don’t know if it would match your use-case, but most of the times with categories, front-ends tend to implement a faceting list with respect to categories to let the user define what he/she wants to search more specifically.

If you really wanted to give priorities to your categories, it would be possible in theory using a number in front of the category name and by adding a Sort-By criterion on top of your ranking formula, but this would probably decrease the overall relevancy of your search experience, so I would not recommend you to do so.

Hello Anthony,

Sorry to ask you again, can you explain me why “Seattle Seahawks Ornaments - 6 Pack” is ahead of “12” Poinsettias" in following case.

Search Result for - flowers

Algolia Ranking setting

Algolia Synonyms
Synonyms

How can I see more detail why particular record is ahead of other record? The screenshot below show partial detail however it does not answer my question.
RankingDetail

Thank you in advance

Hello Anthony,

Can you please help?

Hi @jimb in the case you are describing, both records have exactly the same relevancy given the query inputted. Thus the engine rank them most probably by the oldest object added to the engine. Aside from that, you have a custom ranking formula where you removed the “typo” from the formula as warned by the dashboard.

I would encourage you to use the default ranking formula, as handling typos is one of the core feature of Algolia.

Thanks!