Modularize SearchEngine extensions

Summary:
Ref T9964. ApplicationSearch currently has a bunch of hard-coded `if ($object instanceof thing)` stuff.

Pull that out so it can live in extensions.

Test Plan:
 - Searched by spaces, subscribers, projects.

{F1023921}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9964

Differential Revision: https://secure.phabricator.com/D14764
This commit is contained in:
epriestley
2015-12-13 04:12:34 -08:00
parent 05a798e3ac
commit 1b325a0a89
10 changed files with 248 additions and 151 deletions

View File

@@ -14,10 +14,43 @@ final class PhabricatorSpacesSearchEngineExtension
return pht('Support for Spaces');
}
public function getExtensionOrder() {
return 3000;
}
public function supportsObject($object) {
return ($object instanceof PhabricatorSpacesInterface);
}
public function getSearchFields($object) {
$fields = array();
if (PhabricatorSpacesNamespaceQuery::getSpacesExist()) {
$fields[] = id(new PhabricatorSpacesSearchField())
->setKey('spacePHIDs')
->setConduitKey('spaces')
->setAliases(array('space', 'spaces'))
->setLabel(pht('Spaces'));
}
return $fields;
}
public function applyConstraintsToQuery(
$object,
$query,
PhabricatorSavedQuery $saved,
array $map) {
if (!empty($map['spacePHIDs'])) {
$query->withSpacePHIDs($map['spacePHIDs']);
} else {
// If the user doesn't search for objects in specific spaces, we
// default to "all active spaces you have permission to view".
$query->withSpaceIsArchived(false);
}
}
public function getFieldSpecificationsForConduit($object) {
return array(
'spacePHID' => array(