Skip to content

Commit

Permalink
Merge branch 'feature/initial-implementation' into feature/core-name
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Mar 21, 2024
2 parents 56aa128 + f4bdbd2 commit 914ffb7
Show file tree
Hide file tree
Showing 40 changed files with 312 additions and 348 deletions.
7 changes: 4 additions & 3 deletions src/Console/Command/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ protected function configure(): void
'cleanup-threshold',
null,
InputArgument::OPTIONAL,
'Specifies the number of indexed documents from ' .
'which indexing is considered successful and old entries ' .
'can be deleted. Is only used for full indexing.',
'Specifies the number of documents required to be indexed ' .
'successfully for the entire process to be considered ' .
'successfull. Old entries will only ever be removed if this ' .
'threshold is reached. Only relevant for full-indexing.',
0
)
->addOption(
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Io/IndexerProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function formatProgressBar(string $color): void
$this->progressBar->setProgressCharacter('<fg=' . $color . '>➤</>');
$this->progressBar->setFormat(
"%current%/%max% [%bar%] %percent:3s%%\n" .
" %estimated:-20s% %memory:20s%"
" %estimated:-20s% %memory:20s%"
);
}

Expand All @@ -83,7 +83,7 @@ public function error(Throwable $throwable): void
public function finish(): void
{
$this->progressBar->finish();
$this->status->state = IndexerStatusState::INDEXED;
$this->status->state = IndexerStatusState::FINISHED;
$this->status->endTime = new DateTime();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Io/TypifiedInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getIntOption(string $name): int
$value = $this->input->getOption($name);
if (!is_numeric($value)) {
throw new InvalidArgumentException(
'option' . $name . ' must be a integer: ' . $value
'option ' . $name . ' must be a integer: ' . $value
);
}
return (int)$value;
Expand All @@ -44,7 +44,7 @@ public function getStringArgument(string $name): string
$value = $this->input->getArgument($name);
if (!is_string($value)) {
throw new InvalidArgumentException(
'argument' . $name . ' must be a string'
'argument ' . $name . ' must be a string'
);
}
return $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/MoreLikeThis.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function configure(): void
'location',
InputArgument::REQUIRED,
'Location of the resource to which the MoreLikeThis ' .
'search is to be applied..'
'search is to be applied.'
)
->addOption(
'lang',
Expand Down
11 changes: 3 additions & 8 deletions src/Console/Command/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function configure(): void
->setHelp('Command to performs a search')
->addArgument(
'text',
InputArgument::IS_ARRAY,
InputArgument::REQUIRED,
'Text with which to search.'
)
->addOption(
Expand Down Expand Up @@ -71,13 +71,8 @@ protected function buildQuery(InputInterface $input): SelectQuery
{
$builder = new SelectQueryBuilder();

$text = $this->input->getArrayArgument('text');
if (is_array($text)) {
$builder->text(implode(' ', $text));
}
$lang = $this->input->getStringOption('lang');
$builder->lang($lang);

$text = $this->input->getStringArgument('text');
$builder->text($text);

// TODO: filter

Expand Down
13 changes: 5 additions & 8 deletions src/Console/Command/Suggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function __construct(
protected function configure(): void
{
$this
->setHelp('Command to performs a suggest search')
->setHelp('Command that performs a suggest search')
->addArgument(
'terms',
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
InputArgument::REQUIRED,
'Suggest terms.'
)
->addOption(
Expand All @@ -57,7 +57,7 @@ protected function execute(
): int {
$this->input = new TypifiedInput($input);
$this->io = new SymfonyStyle($input, $output);
$terms = $this->input->getArrayArgument('terms');
$terms = $this->input->getStringArgument('terms');
$lang = $this->input->getStringOption('lang');

$query = $this->buildQuery($terms, $lang);
Expand All @@ -69,15 +69,12 @@ protected function execute(
return Command::SUCCESS;
}

/**
* @param string[] $terms
*/
protected function buildQuery(array $terms, string $lang): SuggestQuery
protected function buildQuery(string $terms, string $lang): SuggestQuery
{
$excludeMedia = new ObjectTypeFilter(['media'], 'media');
$excludeMedia = $excludeMedia->exclude();
return new SuggestQuery(
implode(' ', $terms),
$terms,
$lang,
[
new ArchiveFilter(),
Expand Down
2 changes: 1 addition & 1 deletion src/Dto/Indexer/IndexerStatusState.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ enum IndexerStatusState: string
{
case UNKNOWN = 'UNKNOWN';
case RUNNING = 'RUNNING';
case INDEXED = 'INDEXED';
case FINISHED = 'FINISHED';
case ABORTED = 'ABORTED';
}
42 changes: 33 additions & 9 deletions src/Dto/Search/Query/SelectQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,28 @@ public function __construct()
{
}

public function text(string $text): SelectQueryBuilder
/**
* @return $this
*/
public function text(string $text): static
{
$this->text = $text;
return $this;
}

public function lang(string $lang): SelectQueryBuilder
/**
* @return $this
*/
public function lang(string $lang): static
{
$this->lang = $lang;
return $this;
}

public function offset(int $offset): SelectQueryBuilder
/**
* @return $this
*/
public function offset(int $offset): static
{
if ($offset < 0) {
throw new \InvalidArgumentException('offset is lower then 0');
Expand All @@ -56,24 +65,33 @@ public function offset(int $offset): SelectQueryBuilder
return $this;
}

public function limit(int $limit): SelectQueryBuilder
/**
* @return $this
*/
public function limit(int $limit): static
{
if ($limit < 0) {
throw new \InvalidArgumentException('offset is lower then 0');
throw new \InvalidArgumentException('limit is lower then 0');
}
$this->limit = $limit;
return $this;
}

public function sort(Criteria ...$criteriaList): SelectQueryBuilder
/**
* @return $this
*/
public function sort(Criteria ...$criteriaList): static
{
foreach ($criteriaList as $criteria) {
$this->sort[] = $criteria;
}
return $this;
}

public function filter(Filter ...$filterList): SelectQueryBuilder
/**
* @return $this
*/
public function filter(Filter ...$filterList): static
{
foreach ($filterList as $filter) {
if (isset($this->filter[$filter->key])) {
Expand All @@ -87,7 +105,10 @@ public function filter(Filter ...$filterList): SelectQueryBuilder
return $this;
}

public function facet(Facet ...$facetList): SelectQueryBuilder
/**
* @return $this
*/
public function facet(Facet ...$facetList): static
{
foreach ($facetList as $facet) {
if (isset($this->facets[$facet->key])) {
Expand All @@ -101,9 +122,12 @@ public function facet(Facet ...$facetList): SelectQueryBuilder
return $this;
}

/**
* @return $this
*/
public function defaultQueryOperator(
QueryOperator $defaultQueryOperator
): SelectQueryBuilder {
): static {
$this->defaultQueryOperator = $defaultQueryOperator;
return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dto/Search/Result/SuggestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* @implements IteratorAggregate<int,Suggestion>
@codeCoverageIgnore
* @codeCoverageIgnore
*/
class SuggestResult implements IteratorAggregate
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnexpectedResultException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(
?\Throwable $previous = null
) {
parent::__construct(
$message . "\n" . $this->result,
$message . ": " . $this->result,
$code,
$previous
);
Expand Down
2 changes: 1 addition & 1 deletion src/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* The main task of an indexer is to systematically analyze documents or
* content in order to extract relevant information from them. This information
* is structured and stored in a search index to enable efficient search
* queries. The indexer organizes the data and extract hierarchical structure
* queries. The indexer organizes the data and extracts hierarchical structures
* that search engines use to deliver fast and accurate search results.
*/
interface Indexer
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Indexer/BackgroundIndexerProgressState.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function finish(): void
$this->status->endTime = new DateTime();
}
if ($this->status->state === IndexerStatusState::RUNNING) {
$this->status->state = IndexerStatusState::INDEXED;
$this->status->state = IndexerStatusState::FINISHED;
}
$this->statusStore->store($this->index, $this->status);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Indexer/ContentCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ private function walk(array $path, array $data): array
}
}

return array_merge([], ...$contentCollections);
return array_merge(...$contentCollections);
}
}
5 changes: 3 additions & 2 deletions src/Service/Indexer/DocumentEnricher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ interface DocumentEnricher
public function isIndexable(Resource $resource): bool;

/**
* @param T $doc
* @return T
* @template E of T
* @param E $doc
* @return E
* @throws DocumentEnrichingException
*/
public function enrichDocument(
Expand Down
Loading

0 comments on commit 914ffb7

Please sign in to comment.