Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion src/Plugin/Fuzzy/Payload.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -235,6 +237,7 @@ public function getQueriesSQLRequest(callable $fn): string {
'MATCH(\'%s\'%s)',
'',
'',
'',
' ',
' option ',
' facet ',
Expand Down
27 changes: 27 additions & 0 deletions test/Buddy/functional/MultipleQueriesTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}