Hi,
I’ve got two questions on the search() function:
1- If I use this code:
$site->search('my query search')
Does it search in all type of fields (text, select …) included the structure field?
2- In the doc we can read: (https://getkirby.com/docs/cheatsheet/site/search)
$site->search($query, $params = array())
Possible parameters/defaults
$defaults = array(
'minlength' => 2,
'fields' => array(),
'words' => false,
'score' => array()
);
2a - If the parameter “words” is set to true, this means the search function will search the “exact expression” enter in the input field? Right?
2b- How works the “score” parameter? does anyone can explain to me with code example?
Thanks for your help
- The search loops through all fields, including the structure field (but score-wise, it is treated as a single field)
2a. If this option is set to true, Kirby will only search for words; for example, if you search for “refresh” it will find “refresh” or “pull-to-refresh” but not “refreshing”. Note that search does not search for expressions but words only! See this post: How to use search to include multiple "words"
2b. You can define a score for each field, for example, if the search result should be more relevant if the search word appears in the title
'score' => array('title' => 3)
The default score per field is 1.
If you want to know more, check out the source code in /kirby/pages.php, #172ff.
1 Like
I had no idea that this feature existed, even after reviewing the cheatsheet multiple times. Would it be possible to add an example of using the ‘score’ parameter to the documentation?
Sure! (and some more chars)
1 Like
Thank you!
Any time the documentation can be expanded (even a little bit) it helps the entire community, not just the newbies.
True, we try our best. Feedback on how to improve the docs is always welcome .