<p>In my article listing page, I have a search function. I define the article query like so:</p>
<pre><code>{% set orderByRule = 'postDate DESC' %} {# Default order. #}
{% if searchQuery is not null %}
    {% set orderByRule = 'score' %}
{% endif %}

{% set articleEntries = craft.entries()
    .section('articles')
    .search(search|trim)
    .orderBy(orderByRule)
    .relatedTo(categoryQuery)
    .limit(21)
%}
</code></pre>
<p>The articles have a custom field called <code>articleBody</code> instead of the regular <code>body</code>.</p>
<p>Now, the <code>searchScore</code> I get on each article seems weird to me, because it doesn't seem to care about the body text at all. However I recently realized this is probably because <code>searchScore</code> is calculated on title, slug and body, only. In other words, searchScore doesn't care about my <code>articleBody</code> field.</p>
<p>In case it matters, my <code>config/general.php</code> file has this in terms of customization for the search functionality:</p>
<pre class="lang-php prettyprint-override"><code>'defaultSearchTermOptions' =&gt; [
    'attribute' =&gt; 'title',
    'subLeft' =&gt; true,
    'subRight' =&gt; true,
],
</code></pre>
<p>I can find very little documentation on the subject in general to be honest. I did find <a href="https://gregorterrill.com/posts/search-scores-in-craft-cms" rel="nofollow noreferrer">this article</a>, but it doesn't talk about customizing the parameters with which searchScore is calculated.</p>
<p>So how do I customize what pieces of content searchScore is calculated on? Can it even be done?</p>

CC BY-SA 4.0
2022-05-05T15:06:02.440Z
What kind of field is ``articleBody``? Make sure in the field settings that "use this field's values as search keywords" is [ticked](https://craftcms.com/docs/3.x/searching.html#rebuilding-your-search-indexes). Then rebuild the search index if necessary.
RitterKnight
CC BY-SA 4.0
2022-05-06T08:50:48.937Z
@RitterKnight It's a Redactor field. It is being used for search keywords, that's not the problem. The problem is that the words within this field isn't receiving a `searchScore`.
InanisAtheos
<search>
How do I customize the searchScore?
# How do I customize the searchScore?

(Asked by: username_0 on 2022-05-04)

In my article listing page, I have a search function. I define the article query like so:
{% set orderByRule = 'postDate DESC' %} {# Default order. #}
{% if searchQuery is not null %}
    {% set orderByRule = 'score' %}
{% endif %}

{% set articleEntries = craft.entries()
    .section('articles')
    .search(search|trim)
    .orderBy(orderByRule)
    .relatedTo(categoryQuery)
    .limit(21)
%}

The articles have a custom field called articleBody instead of the regular body.
Now, the searchScore I get on each article seems weird to me, because it doesn't seem to care about the body text at all. However I recently realized this is probably because searchScore is calculated on title, slug and body, only. In other words, searchScore doesn't care about my articleBody field.
In case it matters, my config/general.php file has this in terms of customization for the search functionality:
'defaultSearchTermOptions' => [
    'attribute' => 'title',
    'subLeft' => true,
    'subRight' => true,
],

I can find very little documentation on the subject in general to be honest. I did find this article, but it doesn't talk about customizing the parameters with which searchScore is calculated.
So how do I customize what pieces of content searchScore is calculated on? Can it even be done?

**Tags:** search

> **Comments:**
> **username_1**: What kind of field is ``articleBody``? Make sure in the field settings that "use this field's values as search keywords" is [ticked](https://craftcms.com/docs/3.x/searching.html#rebuilding-your-search-indexes). Then rebuild the search index if necessary.  
> **username_0**: @username_1 It's a Redactor field. It is being used for search keywords, that's not the problem. The problem is that the words within this field isn't receiving a `searchScore`.  

---

## 0 answers

