Skip to content

Commit

Permalink
refactor: rename Select to Search
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Mar 22, 2024
1 parent 784cb4e commit 5c956fa
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 69 deletions.
14 changes: 7 additions & 7 deletions src/Console/Command/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Atoolo\Search\Console\Command;

use Atoolo\Search\Console\Command\Io\TypifiedInput;
use Atoolo\Search\Dto\Search\Query\SelectQuery;
use Atoolo\Search\Dto\Search\Query\SelectQueryBuilder;
use Atoolo\Search\Dto\Search\Query\SearchQuery;
use Atoolo\Search\Dto\Search\Query\SearchQueryBuilder;
use Atoolo\Search\Dto\Search\Result\SearchResult;
use Atoolo\Search\Service\Search\SolrSelect;
use Atoolo\Search\Service\Search\SolrSearch;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -26,7 +26,7 @@ class Search extends Command
private TypifiedInput $input;

public function __construct(
private readonly SolrSelect $searcher
private readonly SolrSearch $searcher
) {
parent::__construct();
}
Expand Down Expand Up @@ -60,16 +60,16 @@ protected function execute(

$query = $this->buildQuery($input);

$result = $this->searcher->select($query);
$result = $this->searcher->search($query);

$this->outputResult($result);

return Command::SUCCESS;
}

protected function buildQuery(InputInterface $input): SelectQuery
protected function buildQuery(InputInterface $input): SearchQuery
{
$builder = new SelectQueryBuilder();
$builder = new SearchQueryBuilder();

$text = $this->input->getStringArgument('text');
$builder->text($text);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/Suggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function execute(

$query = $this->buildQuery($terms, $lang);

$result = $this->search->suggest($query);
$result = $this->search->search($query);

$this->outputResult($result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
/**
* @codeCoverageIgnore
*/
class SelectQuery
class SearchQuery
{
/**
* @param Criteria[] $sort
* @param Filter[] $filter
* @param Facet[] $facets
* @internal Do not use the constructor directly,
* but the SelectQueryBuilder
* but the SearchQueryBuilder
*/
public function __construct(
public readonly string $text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Atoolo\Search\Dto\Search\Query\Filter\Filter;
use Atoolo\Search\Dto\Search\Query\Sort\Criteria;

class SelectQueryBuilder
class SearchQueryBuilder
{
private string $text = '';
private string $lang = '';
Expand Down Expand Up @@ -132,9 +132,9 @@ public function defaultQueryOperator(
return $this;
}

public function build(): SelectQuery
public function build(): SearchQuery
{
return new SelectQuery(
return new SearchQuery(
$this->text,
$this->lang,
$this->offset,
Expand Down
2 changes: 1 addition & 1 deletion src/MoreLikeThisSearcher.php → src/MoreLikeThis.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* The reference point is specified via the location of a resource.
*/
interface MoreLikeThisSearcher
interface MoreLikeThis
{
public function moreLikeThis(
MoreLikeThisQuery $query
Expand Down
6 changes: 3 additions & 3 deletions src/SelectSearcher.php → src/Searcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Atoolo\Search;

use Atoolo\Search\Dto\Search\Query\SelectQuery;
use Atoolo\Search\Dto\Search\Query\SearchQuery;
use Atoolo\Search\Dto\Search\Result\SearchResult;

/**
* The service interface for a search with full-text, filter and facet support.
*/
interface SelectSearcher
interface Searcher
{
public function select(SelectQuery $query): SearchResult;
public function search(SearchQuery $query): SearchResult;
}
4 changes: 2 additions & 2 deletions src/Service/Search/SolrMoreLikeThis.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Atoolo\Search\Dto\Search\Query\MoreLikeThisQuery;
use Atoolo\Search\Dto\Search\Result\SearchResult;
use Atoolo\Search\MoreLikeThisSearcher;
use Atoolo\Search\MoreLikeThis;
use Atoolo\Search\Service\IndexName;
use Atoolo\Search\Service\SolrClientFactory;
use Solarium\Core\Client\Client;
Expand All @@ -16,7 +16,7 @@
/**
* Implementation of the "More-Like-This" on the basis of a Solr index.
*/
class SolrMoreLikeThis implements MoreLikeThisSearcher
class SolrMoreLikeThis implements MoreLikeThis
{
public function __construct(
private readonly IndexName $index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Atoolo\Search\Dto\Search\Query\Facet\FacetQuery;
use Atoolo\Search\Dto\Search\Query\Filter\Filter;
use Atoolo\Search\Dto\Search\Query\QueryOperator;
use Atoolo\Search\Dto\Search\Query\SelectQuery;
use Atoolo\Search\Dto\Search\Query\SearchQuery;
use Atoolo\Search\Dto\Search\Query\Sort\Criteria;
use Atoolo\Search\Dto\Search\Query\Sort\Date;
use Atoolo\Search\Dto\Search\Query\Sort\Headline;
Expand All @@ -19,7 +19,7 @@
use Atoolo\Search\Dto\Search\Result\Facet;
use Atoolo\Search\Dto\Search\Result\FacetGroup;
use Atoolo\Search\Dto\Search\Result\SearchResult;
use Atoolo\Search\SelectSearcher;
use Atoolo\Search\Searcher;
use Atoolo\Search\Service\IndexName;
use Atoolo\Search\Service\SolrClientFactory;
use InvalidArgumentException;
Expand All @@ -31,7 +31,7 @@
/**
* Implementation of the searcher on the basis of a Solr index.
*/
class SolrSelect implements SelectSearcher
class SolrSearch implements Searcher
{
/**
* @param iterable<SolrQueryModifier> $solrQueryModifierList
Expand All @@ -44,7 +44,7 @@ public function __construct(
) {
}

public function select(SelectQuery $query): SearchResult
public function search(SearchQuery $query): SearchResult
{
$index = $this->index->name($query->lang);
$client = $this->clientFactory->create($index);
Expand All @@ -57,7 +57,7 @@ public function select(SelectQuery $query): SearchResult

private function buildSolrQuery(
Client $client,
SelectQuery $query
SearchQuery $query
): SolrSelectQuery {

$solrQuery = $client->createSelect();
Expand Down Expand Up @@ -245,7 +245,7 @@ private function addFacetMultiQueryToSolrQuery(
}

private function buildResult(
SelectQuery $query,
SearchQuery $query,
SelectResult $result,
string $lang
): SearchResult {
Expand All @@ -268,7 +268,7 @@ private function buildResult(
* @return FacetGroup[]
*/
private function buildFacetGroupList(
SelectQuery $query,
SearchQuery $query,
SelectResult $result
): array {

Expand Down
6 changes: 3 additions & 3 deletions src/Service/Search/SolrSuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Atoolo\Search\Exception\UnexpectedResultException;
use Atoolo\Search\Service\IndexName;
use Atoolo\Search\Service\SolrClientFactory;
use Atoolo\Search\SuggestSearcher;
use Atoolo\Search\Suggest;
use JsonException;
use Solarium\Core\Client\Client;
use Solarium\QueryType\Select\Query\Query as SolrSelectQuery;
Expand All @@ -25,7 +25,7 @@
* }
* }
*/
class SolrSuggest implements SuggestSearcher
class SolrSuggest implements Suggest
{
private const INDEX_SUGGEST_FIELD = 'raw_content';

Expand All @@ -38,7 +38,7 @@ public function __construct(
/**
* @throws UnexpectedResultException
*/
public function suggest(SuggestQuery $query): SuggestResult
public function search(SuggestQuery $query): SuggestResult
{
$index = $this->index->name($query->lang);
$client = $this->clientFactory->create($index);
Expand Down
4 changes: 2 additions & 2 deletions src/SuggestSearcher.php → src/Suggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* A "suggest search" is a search function that automatically displays
* suggestions or auto-completions to users as they enter search queries.
*/
interface SuggestSearcher
interface Suggest
{
public function suggest(SuggestQuery $query): SuggestResult;
public function search(SuggestQuery $query): SuggestResult;
}
6 changes: 3 additions & 3 deletions test/Console/Command/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Atoolo\Search\Dto\Search\Result\Facet;
use Atoolo\Search\Dto\Search\Result\FacetGroup;
use Atoolo\Search\Dto\Search\Result\SearchResult;
use Atoolo\Search\Service\Search\SolrSelect;
use Atoolo\Search\Service\Search\SolrSearch;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -43,8 +43,8 @@ public function setUp(): void
)],
10
);
$solrSelect = $this->createStub(SolrSelect::class);
$solrSelect->method('select')
$solrSelect = $this->createStub(SolrSearch::class);
$solrSelect->method('search')
->willReturn($result);

$command = new Search($solrSelect);
Expand Down
2 changes: 1 addition & 1 deletion test/Console/Command/SuggestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setUp(): void
10
);
$solrSuggest = $this->createStub(SolrSuggest::class);
$solrSuggest->method('suggest')
$solrSuggest->method('search')
->willReturn($result);

$command = new Suggest($solrSuggest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
use Atoolo\Search\Dto\Search\Query\Facet\Facet;
use Atoolo\Search\Dto\Search\Query\Filter\Filter;
use Atoolo\Search\Dto\Search\Query\QueryOperator;
use Atoolo\Search\Dto\Search\Query\SelectQueryBuilder;
use Atoolo\Search\Dto\Search\Query\SearchQueryBuilder;
use Atoolo\Search\Dto\Search\Query\Sort\Criteria;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;

#[CoversClass(SelectQueryBuilder::class)]
class SelectQueryBuilderTest extends TestCase
#[CoversClass(SearchQueryBuilder::class)]
class SearchQueryBuilderTest extends TestCase
{
private SelectQueryBuilder $builder;
private SearchQueryBuilder $builder;

protected function setUp(): void
{
$this->builder = new SelectQueryBuilder();
$this->builder = new SearchQueryBuilder();
}

public function testSetText(): void
Expand Down
Loading

0 comments on commit 5c956fa

Please sign in to comment.