Repository navigation
Replies: 3 comments
|
Did not find an out-of-the-box solution for a similar request, but used a twig hack for now: {# Adjust this factor to change the weight of the date #}
{% set factor = 0.1 %}
{% set entries = craft.entries.search('something').all %}
{# Give the score a penalty based on age and sort by higher score #}
{% set results = entries
|map(entry => {
entry: entry,
score: entry.searchScore - ((now.diff(entry.postDate).days) * factor)})
|sort((a, b) => a.score < b.score) %}
{% for result in results %}
<div>
{{ result.score }} {{ result.entry.link }}
</div>
{% endfor %}Craft 4 though, and does not work with /Mel |
0 replies
|
Craft 4.3 added a We are currently looking into ways to improve search performance for 4.5 (#9867) which could provide an opportunity for a new event that has more context for the elements as they’re being scored. We’ll see… |
0 replies
|
Awesome, thanks for the answers! |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi!
For one of our clients we've been asked to give extra weight to 'recent results' within their search functionality. This becomes relevant for recurring content, for example a graduation show that's hosted each year.
Say a user enters a search query like
graduation. With regular scoring, this could generate the following list:In this case it's confusing to the user that the most recent result is not at the very top. This is caused because the search score for the
2019variant is higher because the wordgraduationwas used more often in this specific entry.My question: is it possible to add extra weight to the item's post date in a search query? If so, what's the best way to go about this?
Thanks in advance!
Ps. this is a Craft 3.x site
All reactions