Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/cluster/search/PhabricatorSearchService.php
| Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | class PhabricatorSearchService | ||||
| } | } | ||||
| /** | /** | ||||
| * Execute a full-text query and return a list of PHIDs of matching objects. | * Execute a full-text query and return a list of PHIDs of matching objects. | ||||
| * @return string[] | * @return string[] | ||||
| * @throws PhutilAggregateException | * @throws PhutilAggregateException | ||||
| */ | */ | ||||
| public static function executeSearch(PhabricatorSavedQuery $query) { | public static function executeSearch(PhabricatorSavedQuery $query) { | ||||
| $result_set = self::newResultSet($query); | |||||
| return $result_set->getPHIDs(); | |||||
| } | |||||
| public static function newResultSet(PhabricatorSavedQuery $query) { | |||||
| $exceptions = array(); | $exceptions = array(); | ||||
| // try all services until one succeeds | // try all services until one succeeds | ||||
| foreach (self::getAllServices() as $service) { | foreach (self::getAllServices() as $service) { | ||||
| if (!$service->isReadable()) { | |||||
| continue; | |||||
| } | |||||
| try { | try { | ||||
| $engine = $service->getEngine(); | $engine = $service->getEngine(); | ||||
| $res = $engine->executeSearch($query); | $phids = $engine->executeSearch($query); | ||||
| // return immediately if we get results | |||||
| return $res; | return id(new PhabricatorFulltextResultSet()) | ||||
| ->setPHIDs($phids) | |||||
| ->setFulltextTokens($engine->getFulltextTokens()); | |||||
| } catch (PhutilSearchQueryCompilerSyntaxException $ex) { | } catch (PhutilSearchQueryCompilerSyntaxException $ex) { | ||||
| // If there's a query compilation error, return it directly to the | // If there's a query compilation error, return it directly to the | ||||
| // user: they issued a query with bad syntax. | // user: they issued a query with bad syntax. | ||||
| throw $ex; | throw $ex; | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $exceptions[] = $ex; | $exceptions[] = $ex; | ||||
| } | } | ||||
| } | } | ||||
| $msg = pht('All of the configured Fulltext Search services failed.'); | $msg = pht('All of the configured Fulltext Search services failed.'); | ||||
| throw new PhutilAggregateException($msg, $exceptions); | throw new PhutilAggregateException($msg, $exceptions); | ||||
| } | } | ||||
| } | } | ||||