[COMPONENT][Search] Don't explode if provided an empty search query
This commit is contained in:
parent
a16d31b70e
commit
b0d5ce8aab
|
@ -47,26 +47,28 @@ class Search extends FeedController
|
||||||
*/
|
*/
|
||||||
public function handle(Request $request)
|
public function handle(Request $request)
|
||||||
{
|
{
|
||||||
$actor = Common::actor();
|
$actor = Common::actor();
|
||||||
$language = !\is_null($actor) ? $actor->getTopLanguage()->getLocale() : null;
|
$language = !\is_null($actor) ? $actor->getTopLanguage()->getLocale() : null;
|
||||||
$q = $this->string('q');
|
$q = $this->string('q');
|
||||||
[$note_criteria, $actor_criteria] = Parser::parse($q, $language);
|
if (!empty($q) && !empty($q = trim($q))) {
|
||||||
|
[$note_criteria, $actor_criteria] = Parser::parse($q, $language);
|
||||||
|
|
||||||
$note_qb = DB::createQueryBuilder();
|
$note_qb = DB::createQueryBuilder();
|
||||||
$actor_qb = DB::createQueryBuilder();
|
$actor_qb = DB::createQueryBuilder();
|
||||||
$note_qb->select('note')->from('App\Entity\Note', 'note')->orderBy('note.created', 'DESC');
|
$note_qb->select('note')->from('App\Entity\Note', 'note')->orderBy('note.created', 'DESC');
|
||||||
$actor_qb->select('actor')->from('App\Entity\Actor', 'actor')->orderBy('actor.created', 'DESC');
|
$actor_qb->select('actor')->from('App\Entity\Actor', 'actor')->orderBy('actor.created', 'DESC');
|
||||||
Event::handle('SearchQueryAddJoins', [&$note_qb, &$actor_qb]);
|
Event::handle('SearchQueryAddJoins', [&$note_qb, &$actor_qb]);
|
||||||
|
|
||||||
$notes = $actors = [];
|
$notes = $actors = [];
|
||||||
if (!\is_null($note_criteria)) {
|
if (!\is_null($note_criteria)) {
|
||||||
$note_qb->addCriteria($note_criteria);
|
$note_qb->addCriteria($note_criteria);
|
||||||
$notes = $note_qb->getQuery()->execute();
|
$notes = $note_qb->getQuery()->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!\is_null($actor_criteria)) {
|
if (!\is_null($actor_criteria)) {
|
||||||
$actor_qb->addCriteria($actor_criteria);
|
$actor_qb->addCriteria($actor_criteria);
|
||||||
$actors = $actor_qb->getQuery()->execute();
|
$actors = $actor_qb->getQuery()->execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$search_builder_form = Form::create([
|
$search_builder_form = Form::create([
|
||||||
|
@ -150,8 +152,8 @@ class Search extends FeedController
|
||||||
'_template' => 'search/show.html.twig',
|
'_template' => 'search/show.html.twig',
|
||||||
'search_form' => Comp\Search::searchForm($request, query: $q, add_subscribe: true),
|
'search_form' => Comp\Search::searchForm($request, query: $q, add_subscribe: true),
|
||||||
'search_builder_form' => $search_builder_form->createView(),
|
'search_builder_form' => $search_builder_form->createView(),
|
||||||
'notes' => $notes,
|
'notes' => $notes ?? [],
|
||||||
'actors' => $actors,
|
'actors' => $actors ?? [],
|
||||||
'page' => 1, // TODO paginate
|
'page' => 1, // TODO paginate
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user