3 final class AlmanacServiceSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
6 public function getResultTypeDescription() {
7 return pht('Almanac Services');
10 public function getApplicationClassName() {
11 return 'PhabricatorAlmanacApplication';
14 public function newQuery() {
15 return new AlmanacServiceQuery();
18 protected function buildQueryFromParameters(array $map) {
19 $query = $this->newQuery();
21 if ($map['match'] !== null) {
22 $query->withNameNgrams($map['match']);
26 $query->withNames($map['names']);
29 if ($map['devicePHIDs']) {
30 $query->withDevicePHIDs($map['devicePHIDs']);
33 if ($map['serviceTypes']) {
34 $query->withServiceTypes($map['serviceTypes']);
41 protected function buildCustomSearchFields() {
43 id(new PhabricatorSearchTextField())
44 ->setLabel(pht('Name Contains'))
46 ->setDescription(pht('Search for services by name substring.')),
47 id(new PhabricatorSearchStringListField())
48 ->setLabel(pht('Exact Names'))
50 ->setDescription(pht('Search for services with specific names.')),
51 id(new PhabricatorSearchDatasourceField())
52 ->setLabel(pht('Service Types'))
53 ->setKey('serviceTypes')
54 ->setDescription(pht('Find services by type.'))
55 ->setDatasource(id(new AlmanacServiceTypeDatasource())),
56 id(new PhabricatorPHIDsSearchField())
57 ->setLabel(pht('Devices'))
58 ->setKey('devicePHIDs')
60 pht('Search for services bound to particular devices.')),
64 protected function getURI($path) {
65 return '/almanac/service/'.$path;
68 protected function getBuiltinQueryNames() {
70 'all' => pht('All Services'),
76 public function buildSavedQueryFromBuiltin($query_key) {
78 $query = $this->newSavedQuery();
79 $query->setQueryKey($query_key);
86 return parent
::buildSavedQueryFromBuiltin($query_key);
89 protected function renderResultList(
91 PhabricatorSavedQuery
$query,
93 assert_instances_of($services, 'AlmanacService');
95 $viewer = $this->requireViewer();
97 $list = new PHUIObjectItemListView();
98 $list->setUser($viewer);
99 foreach ($services as $service) {
100 $item = id(new PHUIObjectItemView())
101 ->setObjectName(pht('Service %d', $service->getID()))
102 ->setHeader($service->getName())
103 ->setHref($service->getURI())
104 ->setObject($service)
106 $service->getServiceImplementation()->getServiceTypeIcon(),
107 $service->getServiceImplementation()->getServiceTypeShortName());
109 $list->addItem($item);
112 $result = new PhabricatorApplicationSearchResultView();
113 $result->setObjectList($list);
114 $result->setNoDataString(pht('No Almanac Services found.'));