Skip to content

Commit

Permalink
refactor: move logic from dto to Services
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed May 6, 2024
1 parent 9208e14 commit 743634b
Show file tree
Hide file tree
Showing 54 changed files with 1,711 additions and 1,145 deletions.
4 changes: 2 additions & 2 deletions src/Console/Command/Suggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Atoolo\Resource\ResourceChannelFactory;
use Atoolo\Search\Console\Command\Io\TypifiedInput;
use Atoolo\Search\Dto\Search\Query\Filter\ArchiveFilter;
use Atoolo\Search\Dto\Search\Query\Filter\NotFilter;
use Atoolo\Search\Dto\Search\Query\Filter\ObjectTypeFilter;
use Atoolo\Search\Dto\Search\Query\SuggestQuery;
use Atoolo\Search\Dto\Search\Result\SuggestResult;
Expand Down Expand Up @@ -76,8 +77,7 @@ protected function execute(

protected function buildQuery(string $terms, string $lang): SuggestQuery
{
$excludeMedia = new ObjectTypeFilter(['media'], 'media');
$excludeMedia = $excludeMedia->exclude();
$excludeMedia = new NotFilter(new ObjectTypeFilter(['media']));
return new SuggestQuery(
$terms,
$lang,
Expand Down
3 changes: 3 additions & 0 deletions src/Dto/Search/Query/Facet/AbsoluteDateRangeFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use DateInterval;
use DateTime;

/**
* @codeCoverageIgnore
*/
class AbsoluteDateRangeFacet extends Facet
{
/**
Expand Down
17 changes: 1 addition & 16 deletions src/Dto/Search/Query/Facet/CategoryFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@
/**
* @codeCoverageIgnore
*/
class CategoryFacet extends FacetField
class CategoryFacet extends FieldFacet
{
/**
* @param string[] $categories
* @param string[] $excludeFilter
*/
public function __construct(
string $key,
array $categories,
array $excludeFilter = []
) {
parent::__construct(
$key,
$categories,
$excludeFilter
);
}
}
17 changes: 1 addition & 16 deletions src/Dto/Search/Query/Facet/ContentSectionTypeFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@
/**
* @codeCoverageIgnore
*/
class ContentSectionTypeFacet extends FacetField
class ContentSectionTypeFacet extends FieldFacet
{
/**
* @param string[] $contentSectionTypes
* @param string[] $excludeFilter
*/
public function __construct(
string $key,
array $contentSectionTypes,
array $excludeFilter = []
) {
parent::__construct(
$key,
$contentSectionTypes,
$excludeFilter
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @codeCoverageIgnore
*/
class FacetField extends Facet
class FieldFacet extends Facet
{
/**
* @param string[] $terms
Expand Down
17 changes: 1 addition & 16 deletions src/Dto/Search/Query/Facet/GroupFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@
/**
* @codeCoverageIgnore
*/
class GroupFacet extends FacetField
class GroupFacet extends FieldFacet
{
/**
* @param string[] $groups
* @param string[] $excludeFilter
*/
public function __construct(
string $key,
public readonly array $groups,
array $excludeFilter = []
) {
parent::__construct(
$key,
$groups,
$excludeFilter
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
/**
* @codeCoverageIgnore
*/
class FacetMultiQuery extends Facet
class MultiQueryFacet extends Facet
{
/**
* @param FacetQuery[] $queries
* @param QueryFacet[] $queries
* @param string[] $excludeFilter
*/
public function __construct(
Expand Down
17 changes: 1 addition & 16 deletions src/Dto/Search/Query/Facet/ObjectTypeFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@
/**
* @codeCoverageIgnore
*/
class ObjectTypeFacet extends FacetField
class ObjectTypeFacet extends FieldFacet
{
/**
* @param string[] $objectTypes
* @param string[] $excludeFilter
*/
public function __construct(
string $key,
public readonly array $objectTypes,
array $excludeFilter = []
) {
parent::__construct(
$key,
$objectTypes,
$excludeFilter
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @codeCoverageIgnore
*/
class FacetQuery extends Facet
class QueryFacet extends Facet
{
/**
* @param string[] $excludeFilter
Expand Down
3 changes: 3 additions & 0 deletions src/Dto/Search/Query/Facet/RelativeDateRangeFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Atoolo\Search\Dto\Search\Query\DateRangeRound;
use DateInterval;

/**
* @codeCoverageIgnore
*/
class RelativeDateRangeFacet extends Facet
{
/**
Expand Down
17 changes: 1 addition & 16 deletions src/Dto/Search/Query/Facet/SiteFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@
/**
* @codeCoverageIgnore
*/
class SiteFacet extends FacetField
class SiteFacet extends FieldFacet
{
/**
* @param string[] $sites
* @param string[] $excludeFilter
*/
public function __construct(
string $key,
public readonly array $sites,
array $excludeFilter = []
) {
parent::__construct(
$key,
$sites,
$excludeFilter
);
}
}
25 changes: 2 additions & 23 deletions src/Dto/Search/Query/Filter/AbsoluteDateRangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
class AbsoluteDateRangeFilter extends Filter
{
public function __construct(
private readonly ?DateTime $from,
private readonly ?DateTime $to,
public readonly ?DateTime $from,
public readonly ?DateTime $to,
?string $key = null
) {
parent::__construct(
Expand All @@ -24,25 +24,4 @@ public function __construct(
);
}
}

public function getQuery(): string
{
return 'sp_date_list:' .
'[' .
$this->formatDate($this->from) .
' TO ' .
$this->formatDate($this->to) .
']';
}

private function formatDate(?DateTime $date): string
{
if ($date === null) {
return '*';
}

$formatter = clone $date;
$formatter->setTimezone(new \DateTimeZone('UTC'));
return $formatter->format('Y-m-d\TH:i:s\Z');
}
}
15 changes: 4 additions & 11 deletions src/Dto/Search/Query/Filter/AndFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,19 @@

namespace Atoolo\Search\Dto\Search\Query\Filter;

/**
* @codeCoverageIgnore
*/
class AndFilter extends Filter
{
/**
* @param Filter[] $filter
*/
public function __construct(
private readonly array $filter,
public readonly array $filter,
?string $key = null,
array $tags = []
) {
parent::__construct($key, $tags);
}

public function getQuery(): string
{
$query = [];
foreach ($this->filter as $filter) {
$query[] = $filter->getQuery();
}

return '(' . implode(' AND ', $query) . ')';
}
}
8 changes: 3 additions & 5 deletions src/Dto/Search/Query/Filter/ArchiveFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Atoolo\Search\Dto\Search\Query\Filter;

/**
* @codeCoverageIgnore
*/
class ArchiveFilter extends Filter
{
public function __construct()
Expand All @@ -12,9 +15,4 @@ public function __construct()
'archive'
);
}

public function getQuery(): string
{
return '-sp_archive:true';
}
}
13 changes: 0 additions & 13 deletions src/Dto/Search/Query/Filter/CategoryFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,4 @@
*/
class CategoryFilter extends FieldFilter
{
/**
* @param string[] $category
*/
public function __construct(
array $category,
?string $key = null
) {
parent::__construct(
'sp_category_path',
$category,
$key
);
}
}
13 changes: 0 additions & 13 deletions src/Dto/Search/Query/Filter/ContentSectionTypeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,4 @@
*/
class ContentSectionTypeFilter extends FieldFilter
{
/**
* @param string[] $contentTypes
*/
public function __construct(
array $contentTypes,
?string $key = null,
) {
parent::__construct(
'sp_contenttype',
$contentTypes,
$key
);
}
}
30 changes: 1 addition & 29 deletions src/Dto/Search/Query/Filter/FieldFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,21 @@

class FieldFilter extends Filter
{
/**
* @var string[]
*/
private readonly array $values;

/**
* @param string[] $values
*/
public function __construct(
private readonly string $field,
array $values,
public readonly array $values,
?string $key = null
) {
if (count($values) === 0) {
throw new InvalidArgumentException(
'values is an empty array'
);
}
$this->values = $values;
parent::__construct(
$key,
$key !== null ? [$key] : []
);
}

public function getQuery(): string
{
$filterValue = count($this->values) === 1
? $this->values[0]
: '(' . implode(' ', $this->values) . ')';
return $this->field . ':' . $filterValue;
}

public function exclude(): FieldFilter
{
$field = $this->field;
if (!str_starts_with($field, '-')) {
$field = '-' . $field;
}
return new FieldFilter(
$field,
$this->values,
$this->key
);
}
}
2 changes: 0 additions & 2 deletions src/Dto/Search/Query/Filter/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ public function __construct(
public readonly array $tags = []
) {
}

abstract public function getQuery(): string;
}
13 changes: 0 additions & 13 deletions src/Dto/Search/Query/Filter/GroupFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,4 @@
*/
class GroupFilter extends FieldFilter
{
/**
* @param string[] $group
*/
public function __construct(
array $group,
?string $key = null,
) {
parent::__construct(
'sp_group_path',
$group,
$key
);
}
}
Loading

0 comments on commit 743634b

Please sign in to comment.