3 final class PhabricatorSearchController
4 extends PhabricatorSearchBaseController
{
6 const SCOPE_CURRENT_APPLICATION
= 'application';
8 public function shouldAllowPublic() {
12 public function handleRequest(AphrontRequest
$request) {
13 $viewer = $this->getViewer();
14 $query = $request->getStr('query');
16 if ($request->getStr('jump') != 'no' && strlen($query)) {
17 $jump_uri = id(new PhabricatorDatasourceEngine())
21 if ($jump_uri !== null) {
22 return id(new AphrontRedirectResponse())->setURI($jump_uri);
26 $engine = new PhabricatorSearchApplicationSearchEngine();
27 $engine->setViewer($viewer);
29 // If we're coming from primary search, do some special handling to
30 // interpret the scope selector and query.
31 if ($request->getBool('search:primary')) {
33 // If there's no query, just take the user to advanced search.
34 if (!strlen($query)) {
35 $advanced_uri = '/search/query/advanced/';
36 return id(new AphrontRedirectResponse())->setURI($advanced_uri);
39 // First, load or construct a template for the search by examining
40 // the current search scope.
41 $scope = $request->getStr('search:scope');
44 if ($scope == self
::SCOPE_CURRENT_APPLICATION
) {
45 $application = id(new PhabricatorApplicationQuery())
47 ->withClasses(array($request->getStr('search:application')))
50 $types = $application->getApplicationSearchDocumentTypes();
52 $saved = id(new PhabricatorSavedQuery())
53 ->setEngineClassName(get_class($engine))
54 ->setParameter('types', $types)
55 ->setParameter('statuses', array('open'));
60 if (!$saved && !$engine->isBuiltinQuery($scope)) {
61 $saved = id(new PhabricatorSavedQueryQuery())
63 ->withQueryKeys(array($scope))
68 if (!$engine->isBuiltinQuery($scope)) {
71 $saved = $engine->buildSavedQueryFromBuiltin($scope);
74 // Add the user's query, then save this as a new saved query and send
75 // the user to the results page.
76 $saved->setParameter('query', $query);
78 $unguarded = AphrontWriteGuard
::beginScopedUnguardedWrites();
80 $saved->setID(null)->save();
81 } catch (AphrontDuplicateKeyQueryException
$ex) {
82 // Ignore, this is just a repeated search.
86 $query_key = $saved->getQueryKey();
87 $results_uri = $engine->getQueryResultsPageURI($query_key).'#R';
88 return id(new AphrontRedirectResponse())->setURI($results_uri);
91 $controller = id(new PhabricatorApplicationSearchController())
92 ->setQueryKey($request->getURIData('queryKey'))
93 ->setSearchEngine($engine)
94 ->setNavigation($this->buildSideNavView());
96 return $this->delegateToController($controller);
99 public function buildSideNavView($for_app = false) {
100 $viewer = $this->getViewer();
102 $nav = new AphrontSideNavFilterView();
103 $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
105 id(new PhabricatorSearchApplicationSearchEngine())
107 ->addNavigationItems($nav->getMenu());
109 $nav->selectFilter(null);