Skip to content

Commit

Permalink
Route all queries for Fuzzy without match and improve error message o…
Browse files Browse the repository at this point in the history
…n missing match
  • Loading branch information
donhardman committed Dec 7, 2024
1 parent 84d7b85 commit 8c27b7d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Plugin/Fuzzy/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ protected static function fromSqlRequest(Request $request): static {
preg_match('/FROM\s+(\w+)\s+WHERE/ius', $query, $matches);
$tableName = $matches[1] ?? '';

// Check that we have match
if (!preg_match('/match\s*\(\'(.*?)\'\)/ius', $query, $matches)) {
throw QueryParseError::create("The 'fuzzy' option requires a full-text query");
}

// Parse fuzzy and use default 0 if missing
if (!preg_match('/fuzzy\s*=\s*(\d+)/ius', $query, $matches)) {
throw QueryParseError::create('Invalid value for option \'fuzzy\'');
Expand Down Expand Up @@ -380,7 +385,6 @@ public static function cleanUpPayloadOptions(array $payload): array {
*/
public static function hasMatch(Request $request): bool {
$hasMatch = stripos($request->payload, 'select') === 0
&& stripos($request->payload, 'match') !== false
&& stripos($request->payload, 'option') !== false
&& stripos($request->payload, 'fuzzy') !== false
&& stripos($request->error, 'unknown option') !== false
Expand Down

0 comments on commit 8c27b7d

Please sign in to comment.