diff --git a/src/applications/paste/query/PhabricatorPasteSearchEngine.php b/src/applications/paste/query/PhabricatorPasteSearchEngine.php index 4b4b621895..bbc01164b7 100644 --- a/src/applications/paste/query/PhabricatorPasteSearchEngine.php +++ b/src/applications/paste/query/PhabricatorPasteSearchEngine.php @@ -11,21 +11,24 @@ final class PhabricatorPasteSearchEngine return 'PhabricatorPasteApplication'; } - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { + public function buildQueryFromParameters(array $map) { $query = id(new PhabricatorPasteQuery()) - ->needContent(true) - ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())) - ->withLanguages($saved->getParameter('languages', array())); + ->needContent(true); - $start = $this->parseDateTime($saved->getParameter('createdStart')); - $end = $this->parseDateTime($saved->getParameter('createdEnd')); - - if ($start) { - $query->withDateCreatedAfter($start); + if ($map['authorPHIDs']) { + $query->withAuthorPHIDs($map['authorPHIDs']); } - if ($end) { - $query->withDateCreatedBefore($end); + if ($map['languages']) { + $query->withLanguages($map['languages']); + } + + if ($map['createdStart']) { + $query->withDateCreatedAfter($map['createdStart']); + } + + if ($map['createdEnd']) { + $query->withDateCreatedBefore($map['createdEnd']); } return $query; diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php index 7891ef5174..1f2c7a3b45 100644 --- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php +++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php @@ -90,8 +90,24 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { * @param PhabricatorSavedQuery The saved query to operate on. * @return The result of the query. */ - abstract public function buildQueryFromSavedQuery( - PhabricatorSavedQuery $saved); + public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { + $fields = $this->buildSearchFields(); + $viewer = $this->requireViewer(); + + $parameters = array(); + foreach ($fields as $field) { + $field->setViewer($viewer); + $field->readValueFromSavedQuery($saved); + $value = $field->getValueForQuery($field->getValue()); + $parameters[$field->getKey()] = $value; + } + + return $this->buildQueryFromParameters($parameters); + } + + protected function buildQueryFromParameters(array $parameters) { + throw new PhutilMethodNotImplementedException(); + } /** * Builds the search form using the request. diff --git a/src/applications/search/field/PhabricatorSearchDateField.php b/src/applications/search/field/PhabricatorSearchDateField.php index e7568f7c01..c67c7178cc 100644 --- a/src/applications/search/field/PhabricatorSearchDateField.php +++ b/src/applications/search/field/PhabricatorSearchDateField.php @@ -11,6 +11,10 @@ final class PhabricatorSearchDateField return $request->getStr($key); } + public function getValueForQuery($value) { + return $this->parseDateTime($value); + } + protected function validateControlValue($value) { if (!strlen($value)) { return; diff --git a/src/applications/search/field/PhabricatorSearchField.php b/src/applications/search/field/PhabricatorSearchField.php index 75a7453b4a..6944cf31fe 100644 --- a/src/applications/search/field/PhabricatorSearchField.php +++ b/src/applications/search/field/PhabricatorSearchField.php @@ -201,6 +201,10 @@ abstract class PhabricatorSearchField extends Phobject { return null; } + public function getValueForQuery($value) { + return $value; + } + /* -( Rendering Controls )------------------------------------------------- */ diff --git a/src/applications/search/field/PhabricatorSearchTokenizerField.php b/src/applications/search/field/PhabricatorSearchTokenizerField.php index 1feb23f8a4..b2699bb846 100644 --- a/src/applications/search/field/PhabricatorSearchTokenizerField.php +++ b/src/applications/search/field/PhabricatorSearchTokenizerField.php @@ -11,11 +11,18 @@ abstract class PhabricatorSearchTokenizerField return $this->getListFromRequest($request, $key); } + public function getValueForQuery($value) { + return $this->newDatasource() + ->setViewer($this->getViewer()) + ->evaluateTokens($value); + } + protected function newControl() { return id(new AphrontFormTokenizerControl()) ->setDatasource($this->newDatasource()); } + abstract protected function newDatasource(); } diff --git a/src/applications/search/field/PhabricatorSearchUsersField.php b/src/applications/search/field/PhabricatorSearchUsersField.php index 789ffb0a83..2c9620ac3c 100644 --- a/src/applications/search/field/PhabricatorSearchUsersField.php +++ b/src/applications/search/field/PhabricatorSearchUsersField.php @@ -8,9 +8,7 @@ final class PhabricatorSearchUsersField } protected function newDatasource() { - // TODO: Make this use PhabricatorPeopleUserFunctionDatasource once field - // support is a little more powerful. - return new PhabricatorPeopleDatasource(); + return new PhabricatorPeopleUserFunctionDatasource(); } protected function getValueFromRequest(AphrontRequest $request, $key) {