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

whereFullText case consistency #53395

Merged
merged 1 commit into from
Nov 5, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2276,7 +2276,7 @@ public function whereFullText($columns, $value, array $options = [], $boolean =
*/
public function orWhereFullText($columns, $value, array $options = [])
{
return $this->whereFulltext($columns, $value, $options, 'or');
return $this->whereFullText($columns, $value, $options, 'or');
}

/**
Expand Down
24 changes: 12 additions & 12 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1252,65 +1252,65 @@ public function testArrayWhereColumn()
public function testWhereFulltextMySql()
{
$builder = $this->getMySqlBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', 'Hello World');
$builder->select('*')->from('users')->whereFullText('body', 'Hello World');
$this->assertSame('select * from `users` where match (`body`) against (? in natural language mode)', $builder->toSql());
$this->assertEquals(['Hello World'], $builder->getBindings());

$builder = $this->getMySqlBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', 'Hello World', ['expanded' => true]);
$builder->select('*')->from('users')->whereFullText('body', 'Hello World', ['expanded' => true]);
$this->assertSame('select * from `users` where match (`body`) against (? in natural language mode with query expansion)', $builder->toSql());
$this->assertEquals(['Hello World'], $builder->getBindings());

$builder = $this->getMySqlBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', '+Hello -World', ['mode' => 'boolean']);
$builder->select('*')->from('users')->whereFullText('body', '+Hello -World', ['mode' => 'boolean']);
$this->assertSame('select * from `users` where match (`body`) against (? in boolean mode)', $builder->toSql());
$this->assertEquals(['+Hello -World'], $builder->getBindings());

$builder = $this->getMySqlBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', '+Hello -World', ['mode' => 'boolean', 'expanded' => true]);
$builder->select('*')->from('users')->whereFullText('body', '+Hello -World', ['mode' => 'boolean', 'expanded' => true]);
$this->assertSame('select * from `users` where match (`body`) against (? in boolean mode)', $builder->toSql());
$this->assertEquals(['+Hello -World'], $builder->getBindings());

$builder = $this->getMySqlBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext(['body', 'title'], 'Car,Plane');
$builder->select('*')->from('users')->whereFullText(['body', 'title'], 'Car,Plane');
$this->assertSame('select * from `users` where match (`body`, `title`) against (? in natural language mode)', $builder->toSql());
$this->assertEquals(['Car,Plane'], $builder->getBindings());
}

public function testWhereFulltextPostgres()
{
$builder = $this->getPostgresBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', 'Hello World');
$builder->select('*')->from('users')->whereFullText('body', 'Hello World');
$this->assertSame('select * from "users" where (to_tsvector(\'english\', "body")) @@ plainto_tsquery(\'english\', ?)', $builder->toSql());
$this->assertEquals(['Hello World'], $builder->getBindings());

$builder = $this->getPostgresBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', 'Hello World', ['language' => 'simple']);
$builder->select('*')->from('users')->whereFullText('body', 'Hello World', ['language' => 'simple']);
$this->assertSame('select * from "users" where (to_tsvector(\'simple\', "body")) @@ plainto_tsquery(\'simple\', ?)', $builder->toSql());
$this->assertEquals(['Hello World'], $builder->getBindings());

$builder = $this->getPostgresBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', 'Hello World', ['mode' => 'plain']);
$builder->select('*')->from('users')->whereFullText('body', 'Hello World', ['mode' => 'plain']);
$this->assertSame('select * from "users" where (to_tsvector(\'english\', "body")) @@ plainto_tsquery(\'english\', ?)', $builder->toSql());
$this->assertEquals(['Hello World'], $builder->getBindings());

$builder = $this->getPostgresBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', 'Hello World', ['mode' => 'phrase']);
$builder->select('*')->from('users')->whereFullText('body', 'Hello World', ['mode' => 'phrase']);
$this->assertSame('select * from "users" where (to_tsvector(\'english\', "body")) @@ phraseto_tsquery(\'english\', ?)', $builder->toSql());
$this->assertEquals(['Hello World'], $builder->getBindings());

$builder = $this->getPostgresBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', '+Hello -World', ['mode' => 'websearch']);
$builder->select('*')->from('users')->whereFullText('body', '+Hello -World', ['mode' => 'websearch']);
$this->assertSame('select * from "users" where (to_tsvector(\'english\', "body")) @@ websearch_to_tsquery(\'english\', ?)', $builder->toSql());
$this->assertEquals(['+Hello -World'], $builder->getBindings());

$builder = $this->getPostgresBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext('body', 'Hello World', ['language' => 'simple', 'mode' => 'plain']);
$builder->select('*')->from('users')->whereFullText('body', 'Hello World', ['language' => 'simple', 'mode' => 'plain']);
$this->assertSame('select * from "users" where (to_tsvector(\'simple\', "body")) @@ plainto_tsquery(\'simple\', ?)', $builder->toSql());
$this->assertEquals(['Hello World'], $builder->getBindings());

$builder = $this->getPostgresBuilderWithProcessor();
$builder->select('*')->from('users')->whereFulltext(['body', 'title'], 'Car Plane');
$builder->select('*')->from('users')->whereFullText(['body', 'title'], 'Car Plane');
$this->assertSame('select * from "users" where (to_tsvector(\'english\', "body") || to_tsvector(\'english\', "title")) @@ plainto_tsquery(\'english\', ?)', $builder->toSql());
$this->assertEquals(['Car Plane'], $builder->getBindings());
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/Database/MariaDb/FulltextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function setUp(): void
/** @link https://mariadb.com/kb/en/full-text-index-overview/#in-natural-language-mode */
public function testWhereFulltext()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], 'database')->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], 'database')->get();

$this->assertCount(2, $articles);
$this->assertSame('MariaDB Tutorial', $articles[0]->title);
Expand All @@ -54,15 +54,15 @@ public function testWhereFulltext()
/** @link https://mariadb.com/kb/en/full-text-index-overview/#in-boolean-mode */
public function testWhereFulltextWithBooleanMode()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], '+MariaDB -YourSQL', ['mode' => 'boolean'])->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], '+MariaDB -YourSQL', ['mode' => 'boolean'])->get();

$this->assertCount(5, $articles);
}

/** @link https://mariadb.com/kb/en/full-text-index-overview/#with-query-expansion */
public function testWhereFulltextWithExpandedQuery()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], 'database', ['expanded' => true])->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], 'database', ['expanded' => true])->get();

$this->assertCount(6, $articles);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/Database/MySql/FulltextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function setUp(): void
/** @link https://dev.mysql.com/doc/refman/8.0/en/fulltext-natural-language.html */
public function testWhereFulltext()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], 'database')->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], 'database')->get();

$this->assertCount(2, $articles);
$this->assertSame('MySQL Tutorial', $articles[0]->title);
Expand All @@ -54,15 +54,15 @@ public function testWhereFulltext()
/** @link https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html */
public function testWhereFulltextWithBooleanMode()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], '+MySQL -YourSQL', ['mode' => 'boolean'])->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], '+MySQL -YourSQL', ['mode' => 'boolean'])->get();

$this->assertCount(5, $articles);
}

/** @link https://dev.mysql.com/doc/refman/8.0/en/fulltext-query-expansion.html */
public function testWhereFulltextWithExpandedQuery()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], 'database', ['expanded' => true])->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], 'database', ['expanded' => true])->get();

$this->assertCount(6, $articles);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/Database/Postgres/FulltextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function setUp(): void

public function testWhereFulltext()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], 'database')->orderBy('id')->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], 'database')->orderBy('id')->get();

$this->assertCount(2, $articles);
$this->assertSame('PostgreSQL Tutorial', $articles[0]->title);
Expand All @@ -54,21 +54,21 @@ public function testWhereFulltext()
#[RequiresDatabase('pgsql', '>=11.0')]
public function testWhereFulltextWithWebsearch()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], '+PostgreSQL -YourSQL', ['mode' => 'websearch'])->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], '+PostgreSQL -YourSQL', ['mode' => 'websearch'])->get();

$this->assertCount(5, $articles);
}

public function testWhereFulltextWithPlain()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], 'PostgreSQL tutorial', ['mode' => 'plain'])->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], 'PostgreSQL tutorial', ['mode' => 'plain'])->get();

$this->assertCount(2, $articles);
}

public function testWhereFulltextWithPhrase()
{
$articles = DB::table('articles')->whereFulltext(['title', 'body'], 'PostgreSQL tutorial', ['mode' => 'phrase'])->get();
$articles = DB::table('articles')->whereFullText(['title', 'body'], 'PostgreSQL tutorial', ['mode' => 'phrase'])->get();

$this->assertCount(1, $articles);
}
Expand Down