I’m searching a collection using the following:
<?php
return function ($kirby) {
$query = get('q');
$results = $kirby->collection("searchable")->search($query, array('fields' => ['title', 'tags'], 'words' => true, 'minlength' => 4));
return [
'query' => $query,
'results' => $results,
];
};
I have a bunch of pages in the collection with the word ‘Test’ in the title and they all show up when I search for the strings ‘Tes’, ‘Te’, ‘T’, etc… Isn’t words => true
supposed to stop this, or am I misunderstanding how it works?
Hm, if your minlength
is set to 4 characters, and your search string length is shorter than that, your search words are in fact empty and nothing should be returned.
I’ve switched it to this to test but I’m still getting the same results described above:
$results = $site->search($query, ['words' => true, 'minlength' => 4]);
I’m stumped as to what the problem is as my implementation is identical to that of the search documentation.
Hm, guess we have to properly debug what’s happening.
What’s the best way to approach this? When I remove the ‘words’ parameter the results don’t change at all, but when I remove ‘minLength’ they do, despite it not appearing to work as expected.
I currently have the same issue. Adding 'words' => true
doesn’t change anything. Searching for special
will also include search results with the word especially
.
How can we debug this? It seems like the function does not do anything: https://github.com/getkirby/kirby/blob/3.3.6/src/Cms/Search.php#L65-L67
We should debug this with xdebug, haven’t got round to it yet. Maybe create an issue if this is still true with 3.4-rc1?
I’ve tried 3.4.0-rc.2 but words => true
still does not make a difference to the results.