0

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?

2
  • 1
    What kind of field is articleBody? Make sure in the field settings that "use this field's values as search keywords" is ticked. Then rebuild the search index if necessary. May 5 at 15:06
  • @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. May 6 at 8:50

0

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.