mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
Add "bin/search query" for debugging query execution
Summary: Ref T13000. Currently, queries can only be executed from the web UI, which requires logging in as a user. I really want to avoid doing that wherever we can, but being able to execute queries on an instance (and, particularly, see the ngrams and timings on the underlying lookups) would have been helpful in several cases. Improve tooling a bit in advance of the "common ngrams" stuff going out since it seems likely that it will be useful if issues arise. Test Plan: Ran `bin/search query --query ...`, got useful minimal output. Ran with `--trace` to get internals. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13000 Differential Revision: https://secure.phabricator.com/D18690
This commit is contained in:
parent
66df5b1493
commit
17e83b53d5
2 changed files with 57 additions and 0 deletions
|
@ -3950,6 +3950,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSearchManagementIndexWorkflow' => 'applications/search/management/PhabricatorSearchManagementIndexWorkflow.php',
|
||||
'PhabricatorSearchManagementInitWorkflow' => 'applications/search/management/PhabricatorSearchManagementInitWorkflow.php',
|
||||
'PhabricatorSearchManagementNgramsWorkflow' => 'applications/search/management/PhabricatorSearchManagementNgramsWorkflow.php',
|
||||
'PhabricatorSearchManagementQueryWorkflow' => 'applications/search/management/PhabricatorSearchManagementQueryWorkflow.php',
|
||||
'PhabricatorSearchManagementWorkflow' => 'applications/search/management/PhabricatorSearchManagementWorkflow.php',
|
||||
'PhabricatorSearchNgrams' => 'applications/search/ngrams/PhabricatorSearchNgrams.php',
|
||||
'PhabricatorSearchNgramsDestructionEngineExtension' => 'applications/search/engineextension/PhabricatorSearchNgramsDestructionEngineExtension.php',
|
||||
|
@ -9532,6 +9533,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSearchManagementIndexWorkflow' => 'PhabricatorSearchManagementWorkflow',
|
||||
'PhabricatorSearchManagementInitWorkflow' => 'PhabricatorSearchManagementWorkflow',
|
||||
'PhabricatorSearchManagementNgramsWorkflow' => 'PhabricatorSearchManagementWorkflow',
|
||||
'PhabricatorSearchManagementQueryWorkflow' => 'PhabricatorSearchManagementWorkflow',
|
||||
'PhabricatorSearchManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
'PhabricatorSearchNgrams' => 'PhabricatorSearchDAO',
|
||||
'PhabricatorSearchNgramsDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorSearchManagementQueryWorkflow
|
||||
extends PhabricatorSearchManagementWorkflow {
|
||||
|
||||
protected function didConstruct() {
|
||||
$this
|
||||
->setName('query')
|
||||
->setSynopsis(
|
||||
pht('Run a search query. Intended for debugging and development.'))
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
'name' => 'query',
|
||||
'param' => 'query',
|
||||
'help' => pht('Raw query to execute.'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$viewer = $this->getViewer();
|
||||
$raw_query = $args->getArg('query');
|
||||
if (!strlen($raw_query)) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht('Specify a query with --query.'));
|
||||
}
|
||||
|
||||
$engine = id(new PhabricatorSearchApplicationSearchEngine())
|
||||
->setViewer($viewer);
|
||||
|
||||
$saved = $engine->newSavedQuery();
|
||||
$saved->setParameter('query', $raw_query);
|
||||
|
||||
$query = $engine->buildQueryFromSavedQuery($saved);
|
||||
$pager = $engine->newPagerForSavedQuery($saved);
|
||||
|
||||
$results = $engine->executeQuery($query, $pager);
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
echo tsprintf(
|
||||
"%s\t%s\n",
|
||||
$result->getPHID(),
|
||||
$result->getName());
|
||||
}
|
||||
} else {
|
||||
echo tsprintf(
|
||||
"%s\n",
|
||||
pht('No results.'));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue