Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/query/PhabricatorSearchDocumentQuery.php
| <?php | <?php | ||||
| final class PhabricatorSearchDocumentQuery | final class PhabricatorSearchDocumentQuery | ||||
| extends PhabricatorPolicyAwareQuery { | extends PhabricatorPolicyAwareQuery { | ||||
| private $savedQuery; | private $savedQuery; | ||||
| private $objectCapabilities; | private $objectCapabilities; | ||||
| private $unfilteredOffset; | private $unfilteredOffset; | ||||
| private $fulltextResultSet; | |||||
| public function withSavedQuery(PhabricatorSavedQuery $query) { | public function withSavedQuery(PhabricatorSavedQuery $query) { | ||||
| $this->savedQuery = $query; | $this->savedQuery = $query; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function requireObjectCapabilities(array $capabilities) { | public function requireObjectCapabilities(array $capabilities) { | ||||
| $this->objectCapabilities = $capabilities; | $this->objectCapabilities = $capabilities; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getRequiredObjectCapabilities() { | protected function getRequiredObjectCapabilities() { | ||||
| if ($this->objectCapabilities) { | if ($this->objectCapabilities) { | ||||
| return $this->objectCapabilities; | return $this->objectCapabilities; | ||||
| } | } | ||||
| return $this->getRequiredCapabilities(); | return $this->getRequiredCapabilities(); | ||||
| } | } | ||||
| public function getFulltextResultSet() { | |||||
| if (!$this->fulltextResultSet) { | |||||
| throw new PhutilInvalidStateException('execute'); | |||||
| } | |||||
| return $this->fulltextResultSet; | |||||
| } | |||||
| protected function willExecute() { | protected function willExecute() { | ||||
| $this->unfilteredOffset = 0; | $this->unfilteredOffset = 0; | ||||
| $this->fulltextResultSet = null; | |||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| // NOTE: The offset and limit information in the inherited properties of | // NOTE: The offset and limit information in the inherited properties of | ||||
| // this object represent a policy-filtered offset and limit, but the | // this object represent a policy-filtered offset and limit, but the | ||||
| // underlying query engine needs an unfiltered offset and limit. We keep | // underlying query engine needs an unfiltered offset and limit. We keep | ||||
| // track of an unfiltered result offset internally. | // track of an unfiltered result offset internally. | ||||
| $query = id(clone($this->savedQuery)) | $query = id(clone($this->savedQuery)) | ||||
| ->setParameter('offset', $this->unfilteredOffset) | ->setParameter('offset', $this->unfilteredOffset) | ||||
| ->setParameter('limit', $this->getRawResultLimit()); | ->setParameter('limit', $this->getRawResultLimit()); | ||||
| $phids = PhabricatorSearchService::executeSearch($query); | $result_set = PhabricatorSearchService::newResultSet($query, $this); | ||||
| $phids = $result_set->getPHIDs(); | |||||
| $this->fulltextResultSet = $result_set; | |||||
| $this->unfilteredOffset += count($phids); | $this->unfilteredOffset += count($phids); | ||||
| $handles = id(new PhabricatorHandleQuery()) | $handles = id(new PhabricatorHandleQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->requireObjectCapabilities($this->getRequiredObjectCapabilities()) | ->requireObjectCapabilities($this->getRequiredObjectCapabilities()) | ||||
| ->withPHIDs($phids) | ->withPHIDs($phids) | ||||
| ->execute(); | ->execute(); | ||||
| ▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines | |||||