Is there a way to control the weighting of certain fields in Craft when using search in the front-end?

I have a Products Channel which I am trying to search against and I want to be able to boost certain entries, ideally via specific keywords.

I have tried to do this via a tag field but this doesn't seem to have a noticeable impact on the results.

Take the following query:

{% set tmpEntries = craft.entries({
section: 'products',
search: q,
orderBy: 'score',
with: ['product_preview','productCategory','searchWeighting'],
}).all() %}

If I carry this out against the term LAS8001 I get the following results and scores:

  • LAS8001M (83.25)
  • LAS8001 si (46.4841269841)
  • LAS9010 (0.488017429194)

I'm struggling to work out why the weighting is so different for the first two results. Both entries have associated assets with the search term in file names. In trying to boost the second result I have added a tag field and included the search term in that field but with only a negligible boost in search score (from 46.4841269841 to 53.1507936508).

Is there any documentation on how the search algorithms are calculated or ways in which we can control the weighting of specific fields over others?


  • I'm getting odd results too, so would be good to know. I search for "food" and an entry with 2 instances scores double an entry with 4 references to the keyword (after search re-index). Found this: craftcms.stackexchange.com/questions/2376/… – Peter Lewis May 22 '19 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.