diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index aca6e09fdb..a650e33fcf 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/search/management/PhabricatorSearchManagementQueryWorkflow.php b/src/applications/search/management/PhabricatorSearchManagementQueryWorkflow.php new file mode 100644 index 0000000000..8e40162a98 --- /dev/null +++ b/src/applications/search/management/PhabricatorSearchManagementQueryWorkflow.php @@ -0,0 +1,55 @@ +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; + } + +}