Answers.Body: <p>Rather than trying to explain it myself, I prefer to link to the following article: <a href="https://gregorterrill.com/posts/search-scores-in-craft-cms" rel="nofollow noreferrer">https://gregorterrill.com/posts/search-scores-in-craft-cms</a>. Even though the article is from 2021, it does a great job of explaining how search scoring works in Craft CMS by analyzing its source code and giving examples.</p>
  <p>That said the article closes with a few key findings such as:</p>
  <ol>
  <li><p>Titles are the most important field for search result scoring.</p>
  </li>
  <li><p>Don't remove important keywords from slugs as this is another way to score highly.</p>
  </li>
  <li><p>Titles, slugs, and field values with fewer words will always be stronger matches to individual search terms.</p>
  </li>
  <li><p>Search keywords in body copy fields with high word counts will probably be rounded out of existence unless the keyword appears multiple times.</p>
  </li>
  <li><p>You might consider adding a &quot;Search Keywords&quot; field to your entries that doesn't render on the front-end but gives you a place to put in some terms that you really want the entry to appear for when they're searched.</p>
  </li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-03-10T15:13:30.417Z
Answers.LastActivityDate: 2023-03-10T15:13:30.417Z
Answers.UserDisplayName: MisterMike
Body: <p>Is there a way to control the weighting of certain fields in Craft when using search in the front-end?</p>
  
  <p>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.</p>
  
  <p>I have tried to do this via a tag field but this doesn't seem to have a noticeable impact on the results.</p>
  
  <p>Take the following query:</p>
  
  <pre><code>{% set tmpEntries = craft.entries({
  section: 'products',
  search: q,
  orderBy: 'score',
  with: ['product_preview','productCategory','searchWeighting'],
  }).all() %}
  </code></pre>
  
  <p>If I carry this out against the term <code>LAS8001</code> I get the following results and scores:</p>
  
  <ul>
  <li>LAS8001M (83.25)</li>
  <li>LAS8001 si (46.4841269841)</li>
  <li>LAS9010 (0.488017429194)</li>
  </ul>
  
  <p>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 <code>tag</code> field and included the search term in that field but with only a negligible boost in search score (from 46.4841269841 to 53.1507936508).</p>
  
  <p>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?</p>
  
  <p>Cole</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-05-22T16:18:52.400Z
Comments.Text: 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: https://craftcms.stackexchange.com/questions/2376/search-order-score-criteria
Comments.UserDisplayName: Peter Lewis
Tags: <craft3><search>
Title: Search weighting
ThreadText: # Search weighting
  
  (Asked by: username_0 on 2019-01-15)
  
  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?
  
  username_0
  
  **Tags:** craft3, search
  
  > **Comments:**
  > **username_1**: 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: https://craftcms.stackexchange.com/questions/2376/search-order-score-criteria  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2023-03-10. Score: 3
  
  Rather than trying to explain it myself, I prefer to link to the following article: <https://gregorterrill.com/posts/search-scores-in-craft-cms>. Even though the article is from 2021, it does a great job of explaining how search scoring works in Craft CMS by analyzing its source code and giving examples.
  
  That said the article closes with a few key findings such as:
  
  1. Titles are the most important field for search result scoring.
  2. Don't remove important keywords from slugs as this is another way to score highly.
  3. Titles, slugs, and field values with fewer words will always be stronger matches to individual search terms.
  4. Search keywords in body copy fields with high word counts will probably be rounded out of existence unless the keyword appears multiple times.
  5. You might consider adding a "Search Keywords" field to your entries that doesn't render on the front-end but gives you a place to put in some terms that you really want the entry to appear for when they're searched.
  
  
  ---
  
  