Differential D12523 Diff 30082 src/applications/search/query/PhabricatorSearchApplicationSearchEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/query/PhabricatorSearchApplicationSearchEngine.php
Show All 25 Lines | $saved->setParameter( | ||||
'authorPHIDs', | 'authorPHIDs', | ||||
$this->readUsersFromRequest($request, 'authorPHIDs')); | $this->readUsersFromRequest($request, 'authorPHIDs')); | ||||
$saved->setParameter( | $saved->setParameter( | ||||
'ownerPHIDs', | 'ownerPHIDs', | ||||
$this->readUsersFromRequest($request, 'ownerPHIDs')); | $this->readUsersFromRequest($request, 'ownerPHIDs')); | ||||
$saved->setParameter( | $saved->setParameter( | ||||
'withUnowned', | |||||
$this->readBoolFromRequest($request, 'withUnowned')); | |||||
$saved->setParameter( | |||||
'subscriberPHIDs', | 'subscriberPHIDs', | ||||
$this->readPHIDsFromRequest($request, 'subscriberPHIDs')); | $this->readPHIDsFromRequest($request, 'subscriberPHIDs')); | ||||
$saved->setParameter( | $saved->setParameter( | ||||
'projectPHIDs', | 'projectPHIDs', | ||||
$this->readPHIDsFromRequest($request, 'projectPHIDs')); | $this->readPHIDsFromRequest($request, 'projectPHIDs')); | ||||
return $saved; | return $saved; | ||||
} | } | ||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | ||||
$query = id(new PhabricatorSearchDocumentQuery()) | $query = new PhabricatorSearchDocumentQuery(); | ||||
->withSavedQuery($saved); | |||||
// Convert the saved query into a resolved form (without typeahead | |||||
// functions) which the fulltext search engines can execute. | |||||
$config = clone $saved; | |||||
$viewer = $this->requireViewer(); | |||||
$datasource = id(new PhabricatorPeopleOwnerDatasource()) | |||||
->setViewer($viewer); | |||||
$owner_phids = $this->readOwnerPHIDs($config); | |||||
$owner_phids = $datasource->evaluateTokens($owner_phids); | |||||
foreach ($owner_phids as $key => $phid) { | |||||
if ($phid == PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN) { | |||||
$config->setParameter('withUnowned', true); | |||||
unset($owner_phids[$key]); | |||||
} | |||||
} | |||||
$config->setParameter('ownerPHIDs', $owner_phids); | |||||
$datasource = id(new PhabricatorTypeaheadUserParameterizedDatasource()) | |||||
->setViewer($viewer); | |||||
$author_phids = $config->getParameter('authorPHIDs', array()); | |||||
$author_phids = $datasource->evaluateTokens($author_phids); | |||||
$config->setParameter('authorPHIDs', $author_phids); | |||||
$query->withSavedQuery($config); | |||||
return $query; | return $query; | ||||
} | } | ||||
public function buildSearchForm( | public function buildSearchForm( | ||||
AphrontFormView $form, | AphrontFormView $form, | ||||
PhabricatorSavedQuery $saved) { | PhabricatorSavedQuery $saved) { | ||||
$options = array(); | $options = array(); | ||||
$author_value = null; | $author_value = null; | ||||
$owner_value = null; | $owner_value = null; | ||||
$subscribers_value = null; | $subscribers_value = null; | ||||
$project_value = null; | $project_value = null; | ||||
$author_phids = $saved->getParameter('authorPHIDs', array()); | $author_phids = $saved->getParameter('authorPHIDs', array()); | ||||
$owner_phids = $saved->getParameter('ownerPHIDs', array()); | $owner_phids = $this->readOwnerPHIDs($saved); | ||||
$subscriber_phids = $saved->getParameter('subscriberPHIDs', array()); | $subscriber_phids = $saved->getParameter('subscriberPHIDs', array()); | ||||
$project_phids = $saved->getParameter('projectPHIDs', array()); | $project_phids = $saved->getParameter('projectPHIDs', array()); | ||||
$with_unowned = $saved->getParameter('withUnowned', array()); | |||||
$status_values = $saved->getParameter('statuses', array()); | $status_values = $saved->getParameter('statuses', array()); | ||||
$status_values = array_fuse($status_values); | $status_values = array_fuse($status_values); | ||||
$statuses = array( | $statuses = array( | ||||
PhabricatorSearchRelationship::RELATIONSHIP_OPEN => pht('Open'), | PhabricatorSearchRelationship::RELATIONSHIP_OPEN => pht('Open'), | ||||
PhabricatorSearchRelationship::RELATIONSHIP_CLOSED => pht('Closed'), | PhabricatorSearchRelationship::RELATIONSHIP_CLOSED => pht('Closed'), | ||||
); | ); | ||||
$status_control = id(new AphrontFormCheckboxControl()) | $status_control = id(new AphrontFormCheckboxControl()) | ||||
Show All 30 Lines | $form | ||||
->setName('query') | ->setName('query') | ||||
->setValue($saved->getParameter('query'))) | ->setValue($saved->getParameter('query'))) | ||||
->appendChild($status_control) | ->appendChild($status_control) | ||||
->appendControl($types_control) | ->appendControl($types_control) | ||||
->appendControl( | ->appendControl( | ||||
id(new AphrontFormTokenizerControl()) | id(new AphrontFormTokenizerControl()) | ||||
->setName('authorPHIDs') | ->setName('authorPHIDs') | ||||
->setLabel('Authors') | ->setLabel('Authors') | ||||
->setDatasource(new PhabricatorPeopleDatasource()) | ->setDatasource(new PhabricatorTypeaheadUserParameterizedDatasource()) | ||||
->setValue($author_phids)) | ->setValue($author_phids)) | ||||
->appendControl( | ->appendControl( | ||||
id(new AphrontFormTokenizerControl()) | id(new AphrontFormTokenizerControl()) | ||||
->setName('ownerPHIDs') | ->setName('ownerPHIDs') | ||||
->setLabel('Owners') | ->setLabel('Owners') | ||||
->setDatasource(new ManiphestOwnerDatasource()) | ->setDatasource(new PhabricatorPeopleOwnerDatasource()) | ||||
->setValue($owner_phids)) | ->setValue($owner_phids)) | ||||
->appendChild( | |||||
id(new AphrontFormCheckboxControl()) | |||||
->addCheckbox( | |||||
'withUnowned', | |||||
1, | |||||
pht('Show only unowned documents.'), | |||||
$with_unowned)) | |||||
->appendControl( | ->appendControl( | ||||
id(new AphrontFormTokenizerControl()) | id(new AphrontFormTokenizerControl()) | ||||
->setName('subscriberPHIDs') | ->setName('subscriberPHIDs') | ||||
->setLabel('Subscribers') | ->setLabel('Subscribers') | ||||
->setDatasource(new PhabricatorPeopleDatasource()) | ->setDatasource(new PhabricatorMetaMTAMailableDatasource()) | ||||
->setValue($subscriber_phids)) | ->setValue($subscriber_phids)) | ||||
->appendControl( | ->appendControl( | ||||
id(new AphrontFormTokenizerControl()) | id(new AphrontFormTokenizerControl()) | ||||
->setName('projectPHIDs') | ->setName('projectPHIDs') | ||||
->setLabel('In Any Project') | ->setLabel('In Any Project') | ||||
->setDatasource(new PhabricatorProjectDatasource()) | ->setDatasource(new PhabricatorProjectDatasource()) | ||||
->setValue($project_phids)); | ->setValue($project_phids)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if ($results) { | ||||
$results = id(new PHUIInfoView()) | $results = id(new PHUIInfoView()) | ||||
->appendChild(pht('No results returned for that query.')) | ->appendChild(pht('No results returned for that query.')) | ||||
->setSeverity(PHUIInfoView::SEVERITY_NODATA); | ->setSeverity(PHUIInfoView::SEVERITY_NODATA); | ||||
} | } | ||||
return $results; | return $results; | ||||
} | } | ||||
private function readOwnerPHIDs(PhabricatorSavedQuery $saved) { | |||||
$owner_phids = $saved->getParameter('ownerPHIDs', array()); | |||||
// This was an old checkbox from before typeahead functions. | |||||
if ($saved->getParameter('withUnowned')) { | |||||
$owner_phids[] = PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN; | |||||
} | |||||
return $owner_phids; | |||||
} | |||||
} | } |