Complete provider, finder, transformers and configuration refactoring
This commit is contained in:
parent
7be25f92bb
commit
0db0490be5
17 changed files with 444 additions and 320 deletions
|
|
@ -29,6 +29,7 @@ class SearchCommand extends Command
|
|||
->addOption('index', null, InputOption::VALUE_NONE, 'The index to search in')
|
||||
->addOption('limit', null, InputOption::VALUE_REQUIRED, 'The maximum number of documents to return', 20)
|
||||
->addOption('show-source', null, InputOption::VALUE_NONE, 'Show the documents sources')
|
||||
->addOption('show-id', null, InputOption::VALUE_NONE, 'Show the documents ids')
|
||||
->addOption('explain', null, InputOption::VALUE_NONE, 'Enables explanation for each hit on how its score was computed.')
|
||||
->setName('foq:elastica:search')
|
||||
->setDescription('Searches documents in a given type and index');
|
||||
|
|
@ -51,17 +52,20 @@ class SearchCommand extends Command
|
|||
|
||||
$output->writeLn(sprintf('Found %d results', $type->count($query)));
|
||||
foreach ($resultSet->getResults() as $result) {
|
||||
$output->writeLn($this->formatResult($result, $input->getOption('show-source'), $input->getOption('explain')));
|
||||
$output->writeLn($this->formatResult($result, $input->getOption('show-source'), $input->getOption('show-id'), $input->getOption('explain')));
|
||||
}
|
||||
}
|
||||
|
||||
protected function formatResult(Elastica_Result $result, $showSource, $explain)
|
||||
protected function formatResult(Elastica_Result $result, $showSource, $showId, $explain)
|
||||
{
|
||||
$source = $result->getSource();
|
||||
$string = sprintf('[%0.2f] %s', $result->getScore(), var_export(reset($source), true));
|
||||
if ($showSource) {
|
||||
$string = sprintf('%s %s', $string, json_encode($source));
|
||||
}
|
||||
if ($showId) {
|
||||
$string = sprintf('{%s} %s', $result->getId(), $string);
|
||||
}
|
||||
if ($explain) {
|
||||
$string = sprintf('%s %s', $string, json_encode($result->getExplanation()));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue