Skip to content

Commit

Permalink
Merge pull request ezsystems#406 from mikadamczyk/ezp-28945-search-fo…
Browse files Browse the repository at this point in the history
…r-content-items-by-selecting-the-filters

EZP-28945: User will be able to search for content items by just selecting the filters.
  • Loading branch information
Łukasz Serwatka authored Mar 22, 2018
2 parents f493f18 + 7c1a8f7 commit 021458f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/bundle/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ public function searchAction(Request $request): Response
$lastModified = $data->getLastModified();
$created = $data->getCreated();
$query = new Query();
$criteria = [
new Criterion\FullText($queryString),
];
$criteria = [];

if (null !== $queryString) {
$criteria[] = new Criterion\FullText($queryString);
}
if (null !== $section) {
$criteria[] = new Criterion\SectionId($section->id);
}
Expand All @@ -152,7 +154,10 @@ public function searchAction(Request $request): Response
[$created['start_date'], $created['end_date']]
);
}
$query->filter = new Criterion\LogicalAnd($criteria);
if (!empty($criteria)) {
$query->filter = new Criterion\LogicalAnd($criteria);
}

$query->sortClauses[] = new SortClause\DateModified(Query::SORT_ASC);

$pagerfanta = new Pagerfanta(
Expand Down
6 changes: 1 addition & 5 deletions src/lib/Form/Data/Search/SearchData.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ class SearchData
/** @var int */
private $page;

/**
* @var string
*
* @Assert\NotBlank()
*/
/** @var string */
private $query;

/** @var \eZ\Publish\API\Repository\Values\Content\Section */
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Form/Type/Search/SearchType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(TranslatorInterface $translator)
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('query', CoreSearchType::class)
->add('query', CoreSearchType::class, ['required' => false])
->add('page', HiddenType::class)
->add('limit', HiddenType::class)
->add('section', SectionChoiceType::class, [
Expand Down

0 comments on commit 021458f

Please sign in to comment.