diff --git a/src/Plugin/Fuzzy/Payload.php b/src/Plugin/Fuzzy/Payload.php old mode 100644 new mode 100755 index 92d15849..356378c3 --- a/src/Plugin/Fuzzy/Payload.php +++ b/src/Plugin/Fuzzy/Payload.php @@ -173,7 +173,8 @@ protected static function fromSqlRequest(Request $request): static { protected static function extractAdditionalQueries(string $query): array { $additionalQueries = []; - // Find the position of the first semicolon + // Find the position of the first semicolon that is a multi query delimiter + $query = (string)preg_replace(['/\'([^\']*)\'/uis', '/"([^"]*)"/uis'], '', $query); $firstSemicolonPos = strpos($query, ';', strripos($query, ' where ') ?: 0) ?: 0; // If a semicolon exists @@ -224,6 +225,7 @@ public function getQueriesSQLRequest(callable $fn): string { $template = (string)preg_replace( [ static::MATCH_REG_PATTERN, + '/;[\s\S]*/ius', '/(fuzzy|distance|preserve)\s*=\s*\d+[,\s]*/ius', '/(layouts)\s*=\s*\'([a-zA-Z, ]*)\'[,\s]*/ius', '/option,(?!.*option|.*from)/ius', @@ -235,6 +237,7 @@ public function getQueriesSQLRequest(callable $fn): string { 'MATCH(\'%s\'%s)', '', '', + '', ' ', ' option ', ' facet ', diff --git a/test/Buddy/functional/MultipleQueriesTest.php b/test/Buddy/functional/MultipleQueriesTest.php old mode 100644 new mode 100755 index 4366ece0..a1e24faf --- a/test/Buddy/functional/MultipleQueriesTest.php +++ b/test/Buddy/functional/MultipleQueriesTest.php @@ -185,4 +185,31 @@ public function testSqlMultipleQueriesOk(): void { $out = static::runSqlQuery("select col1,col2 from {$this->testTable1}"); $this->assertEquals($selectResult, $out); } + + public function testSqlMultipleQueriesWithFuzzySearchOk(): void { + static::runSqlQuery('CREATE TABLE ' . $this->testTable1 . "(f text) min_infix_len='2'"); + static::runSqlQuery('INSERT INTO ' . $this->testTable1 . "(f) VALUES ('abcdef')"); + $selectResult = [ + '+--------+', + '| f |', + '+--------+', + '| abcdef |', + '+--------+', + '+----------------+-------+', + '| Variable_name | Value |', + '+----------------+-------+', + '| total | 1 |', + '| total_found | 1 |', + '| total_relation | eq |', + '| time | 0.001 |', + '+----------------+-------+', + ]; + $out = static::runSqlQuery( + 'SELECT f FROM ' . $this->testTable1 . " WHERE MATCH('abcdeg') OPTION fuzzy=1; SHOW META" + ); + //Removing time value from response to avoid possible inconsistencies + array_splice($selectResult, 11, 1); + array_splice($out, 11, 1); + $this->assertEquals($selectResult, $out); + } }