Skip to content

Commit

Permalink
Merge pull request #1274 from lunarphp/hotfix/fix-scout-db-empty-search
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson authored Sep 27, 2023
2 parents a9b87f7 + fbe1639 commit a256047
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion utils/scout-database-engine/src/DatabaseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ protected function getSearchQuery(Builder $builder)
$index = $this->getIndexFromBuilder($builder);

return SearchIndex::where('index', '=', $index)
->whereFullText('content', $builder->query.'*', ['mode' => 'boolean']);
->when(
$builder->query,
fn ($query) => $query ->whereFullText('content', $builder->query.'*', ['mode' => 'boolean'])
);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions utils/scout-database-engine/tests/Unit/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public function can_search_a_post()
$this->assertEquals($posts->first()->body, 'Lamborghini');
}

/** @test */
public function can_do_an_empty_search()
{
$this->seedPosts();

$posts = Post::search('')->get();

$this->assertCount(Post::count(), $posts);
}

/** @test */
public function can_raw_search_a_post()
{
Expand Down

1 comment on commit a256047

@vercel
Copy link

@vercel vercel bot commented on a256047 Sep 27, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.