You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apparently, search:results array can only return result sorted by relevance, when I expected, from 2383, that adding sort='date:desc' would do the trick.
I also tried to add 'property_weights' => ['date' => 1], to the index used for the search, to no avail.
There are 3 articles posted on 3 consecutive days. All 3 articles contain the word "text" but the middle article contains it twice so that it is expected to be more relevant than the other 2 when searching for that word.
The code for the search page (template search.antlers.html) is:
<ol>
{{ search:results index="testindex" sort='date:desc' }}
<li>{{ date }} / {{ title }} </li>
{{ /search:results }}
</ol>
Goto URL /search?q=text. The desired order (newest to oldest) of the returned articles is 3, 2, 1.
They will be returned in order 2, 1, 3, though.
Removing sort='date:desc' from the template has no impact
Changing the index definition to include 0, 1 or several of the following lines has no impact either (at least, no impact on the order but definitely an undesired impact on the search result, see comments:
'property_weights' => [ 'date' => 1],
'include_properties' => ['date'], (with this line, the search returns no post; the example site from the repo will just display the title of the search page itself)
If I do that, I can now search by date (e.g. /search?q=2024-10-02) but this has no impact on the sorting of results.
What I am trying to do is the sorting only, not the lookup of posts. I took the liberty to restore the title of this issue accordingly.
BTW, this is the reason why I tried using include_properties. The description (down this section) is not very explicit if you ask me but it looked to me that there was a chance the date was included in the search results and could therefore be used for sorting.
FYI, I noticed in the debugbar that {{ search:results index="testindex" sort='date:desc' }} does impact (at least) the query:
select * from search_testindex where status = 'published' order by date desc
Why I get the results in a different order is beyond me.
Bug description
Continuation of this discussion
Apparently,
search:results
array can only return result sorted by relevance, when I expected, from 2383, that addingsort='date:desc'
would do the trick.I also tried to add
'property_weights' => ['date' => 1],
to the index used for the search, to no avail.How to reproduce
I posted an example Statamic - Search, sort by date repo from a blank site.
There are 3 articles posted on 3 consecutive days. All 3 articles contain the word "text" but the middle article contains it twice so that it is expected to be more relevant than the other 2 when searching for that word.
The code for the search page (template
search.antlers.html
) is:testindex
is configured like so:/search?q=text
. The desired order (newest to oldest) of the returned articles is 3, 2, 1.They will be returned in order 2, 1, 3, though.
sort='date:desc'
from the template has no impact'property_weights' => [ 'date' => 1],
'include_properties' => ['date'],
(with this line, the search returns no post; the example site from the repo will just display the title of the search page itself)'include_properties' => ['title', 'tags', 'content', 'date']
, (same unsorted results)'sort_by_score' => false,
'sort_by_score' => true,
(to make it explicit)'group_by_category' => true
, (out of desperation)property_weights
:Logs
No response
Environment
Installation
Fresh statamic/statamic site via CLI
Additional details
No response
The text was updated successfully, but these errors were encountered: