Set minlength for search to one character is not working in my plugin

i use the following code to set the minlength

$results = site()->search($query, 'short_name|first_name|last_name', array('words' => false, 'minlength' => 1))->listed()->filterBy('template', 'base');

but it still takes two characters to get a result for my searching.

i’m on Kirby 3.5.8 with PHP 8.08

Your syntax is wrong. The method only accepts 2 parameters.

$results = site()->search($query,  [
  'fields' => 'short_name|first_name|last_name',
  'words' => false,
  'minlength' => 1
])->listed()->filterBy('template', 'base');

with you code example i get an error that the second parameter needs to be an array and not string.

therefore i changed your code example to

$results = site()->search($query,  [
  ['fields' => 'short_name|first_name|last_name'],
  ['words' => false],
  ['minlength' => 1]
])->listed()->filterBy('template', 'base');

this doesn’t gives an error but still the search is not working with one letter.

This is already an array, in your changed code you have created a nested array, which doesn’t make sense.

But the fields need to be provides as array it seems, so

  'fields' => ['short_name', 'first_name', 'last_name'],
  'words' => false,
  'minlength' => 1

thank you, that was the solution, you saved my day. Maybe you could add this example also to the docs.