Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Don't enforce a query length on comb searches #10496

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/Search/Comb/Comb.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Statamic\Search\Comb;

use Statamic\Search\Comb\Exceptions\Exception as CombException;
use Statamic\Search\Comb\Exceptions\NoQuery;
use Statamic\Search\Comb\Exceptions\NoResultsFound;
use Statamic\Search\Comb\Exceptions\NotEnoughCharacters;
use Statamic\Search\Comb\Exceptions\TooManyResults;
Expand Down Expand Up @@ -827,18 +826,11 @@ private function standardizeArray($array)
*
* @param string $query Query to test
*
* @throws NoQuery
* @throws NotEnoughCharacters
*/
private function testValidQuery($query)
{
$length = strlen($query);

if ($length === 0) {
throw new NoQuery('No query given.');
}

if ($length < $this->min_characters) {
if (strlen($query) < $this->min_characters) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should maybe leave it as it was, but change the NoQuery condition to if ($length === 0 && $this->min_characters > 0) {

Then things will work exactly the same for everyone, but if you set your min_characters config to 0, you can go ahead and search for nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

throw new NotEnoughCharacters('Not enough characters entered.');
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Search/Comb/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Statamic\Search\Comb;

use Statamic\Facades\File;
use Statamic\Search\Comb\Exceptions\NoQuery;
use Statamic\Search\Comb\Exceptions\NoResultsFound;
use Statamic\Search\Comb\Exceptions\NotEnoughCharacters;
use Statamic\Search\Documents;
Expand All @@ -29,7 +28,7 @@ public function lookup($query)

try {
$results = $comb->lookUp($query)['data'];
} catch (NoResultsFound|NotEnoughCharacters|NoQuery $e) {
} catch (NoResultsFound|NotEnoughCharacters $e) {
return collect();
}

Expand Down
Loading