Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14379888
D8135.id18407.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D8135.id18407.diff
View Options
diff --git a/src/applications/search/constants/PhabricatorSearchScope.php b/src/applications/search/constants/PhabricatorSearchScope.php
deleted file mode 100644
--- a/src/applications/search/constants/PhabricatorSearchScope.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-/**
- * @group search
- */
-final class PhabricatorSearchScope {
-
- const SCOPE_ALL = 'all';
- const SCOPE_OPEN_REVISIONS = 'open-revisions';
- const SCOPE_OPEN_TASKS = 'open-tasks';
- const SCOPE_COMMITS = 'commits';
- const SCOPE_WIKI = 'wiki';
- const SCOPE_QUESTIONS = 'questions';
-
- public static function getScopeOptions() {
- return array(
- self::SCOPE_ALL => 'All Documents',
- self::SCOPE_OPEN_TASKS => 'Open Tasks',
- self::SCOPE_WIKI => 'Wiki Documents',
- self::SCOPE_OPEN_REVISIONS => 'Open Revisions',
- self::SCOPE_COMMITS => 'Commits',
- self::SCOPE_QUESTIONS => 'Ponder Questions',
- );
- }
-
- public static function getScopePlaceholder($scope) {
- switch ($scope) {
- case self::SCOPE_OPEN_TASKS:
- return pht('Search Open Tasks');
- case self::SCOPE_WIKI:
- return pht('Search Wiki Documents');
- case self::SCOPE_OPEN_REVISIONS:
- return pht('Search Open Revisions');
- case self::SCOPE_COMMITS:
- return pht('Search Commits');
- default:
- return pht('Search');
- }
- }
-
-}
diff --git a/src/applications/search/controller/PhabricatorSearchController.php b/src/applications/search/controller/PhabricatorSearchController.php
--- a/src/applications/search/controller/PhabricatorSearchController.php
+++ b/src/applications/search/controller/PhabricatorSearchController.php
@@ -30,9 +30,52 @@
}
}
+ $engine = new PhabricatorSearchApplicationSearchEngine();
+ $engine->setViewer($viewer);
+
+ // NOTE: This is a little weird. If we're coming from primary search, we
+ // load the user's first search filter and overwrite the "query" part of
+ // it, then send them to that result page. This is sort of odd, but lets
+ // users choose a default query like "Open Tasks" in a reasonable way,
+ // with only this piece of somewhat-sketchy code. See discussion in T4365.
+
+ if ($request->getBool('search:primary')) {
+ $named_queries = $engine->loadEnabledNamedQueries();
+ if ($named_queries) {
+ $named = head($named_queries);
+
+ $query_key = $named->getQueryKey();
+ $saved = null;
+ if ($engine->isBuiltinQuery($query_key)) {
+ $saved = $engine->buildSavedQueryFromBuiltin($query_key);
+ } else {
+ $saved = id(new PhabricatorSavedQueryQuery())
+ ->setViewer($viewer)
+ ->withQueryKeys(array($query_key))
+ ->executeOne();
+ }
+
+ if ($saved) {
+ $saved->setParameter('query', $request->getStr('query'));
+ $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
+ try {
+ $saved->setID(null)->save();
+ } catch (AphrontQueryDuplicateKeyException $ex) {
+ // Ignore, this is just a repeated search.
+ }
+ unset($unguarded);
+
+ $results_uri = $engine->getQueryResultsPageURI(
+ $saved->getQueryKey()).'#R';
+
+ return id(new AphrontRedirectResponse())->setURI($results_uri);
+ }
+ }
+ }
+
$controller = id(new PhabricatorApplicationSearchController($request))
->setQueryKey($this->queryKey)
- ->setSearchEngine(new PhabricatorSearchApplicationSearchEngine())
+ ->setSearchEngine($engine)
->setUseOffsetPaging(true)
->setNavigation($this->buildSideNavView());
diff --git a/src/view/page/PhabricatorStandardPageView.php b/src/view/page/PhabricatorStandardPageView.php
--- a/src/view/page/PhabricatorStandardPageView.php
+++ b/src/view/page/PhabricatorStandardPageView.php
@@ -13,7 +13,6 @@
private $menuContent;
private $showChrome = true;
private $disableConsole;
- private $searchDefaultScope;
private $pageObjects = array();
private $applicationMenu;
@@ -58,15 +57,6 @@
return $this->showChrome;
}
- public function setSearchDefaultScope($search_default_scope) {
- $this->searchDefaultScope = $search_default_scope;
- return $this;
- }
-
- public function getSearchDefaultScope() {
- return $this->searchDefaultScope;
- }
-
public function appendPageObjects(array $objs) {
foreach ($objs as $obj) {
$this->pageObjects[] = $obj;
@@ -212,8 +202,7 @@
}
$menu = id(new PhabricatorMainMenuView())
- ->setUser($viewer)
- ->setDefaultSearchScope($this->getSearchDefaultScope());
+ ->setUser($viewer);
if ($this->getController()) {
$menu->setController($this->getController());
diff --git a/src/view/page/menu/PhabricatorMainMenuSearchView.php b/src/view/page/menu/PhabricatorMainMenuSearchView.php
--- a/src/view/page/menu/PhabricatorMainMenuSearchView.php
+++ b/src/view/page/menu/PhabricatorMainMenuSearchView.php
@@ -2,14 +2,8 @@
final class PhabricatorMainMenuSearchView extends AphrontView {
- private $scope;
private $id;
- public function setScope($scope) {
- $this->scope = $scope;
- return $this;
- }
-
public function getID() {
if (!$this->id) {
$this->id = celerity_generate_unique_node_id();
@@ -32,8 +26,6 @@
'autocomplete' => 'off',
));
- $scope = $this->scope;
-
$target = javelin_tag(
'div',
array(
@@ -49,15 +41,15 @@
'input' => $search_id,
'src' => '/typeahead/common/mainsearch/',
'limit' => 10,
- 'placeholder' => PhabricatorSearchScope::getScopePlaceholder($scope),
+ 'placeholder' => pht('Search'),
));
- $scope_input = phutil_tag(
+ $primary_input = phutil_tag(
'input',
array(
'type' => 'hidden',
- 'name' => 'scope',
- 'value' => $scope,
+ 'name' => 'search:primary',
+ 'value' => 'true',
));
$form = phabricator_form(
@@ -69,7 +61,7 @@
phutil_tag_div('phabricator-main-menu-search-container', array(
$input,
phutil_tag('button', array(), pht('Search')),
- $scope_input,
+ $primary_input,
$target,
)));
diff --git a/src/view/page/menu/PhabricatorMainMenuView.php b/src/view/page/menu/PhabricatorMainMenuView.php
--- a/src/view/page/menu/PhabricatorMainMenuView.php
+++ b/src/view/page/menu/PhabricatorMainMenuView.php
@@ -2,7 +2,6 @@
final class PhabricatorMainMenuView extends AphrontView {
- private $defaultSearchScope;
private $controller;
private $applicationMenu;
@@ -24,15 +23,6 @@
return $this->controller;
}
- public function setDefaultSearchScope($default_search_scope) {
- $this->defaultSearchScope = $default_search_scope;
- return $this;
- }
-
- public function getDefaultSearchScope() {
- return $this->defaultSearchScope;
- }
-
public function render() {
$user = $this->user;
@@ -105,7 +95,6 @@
if ($show_search) {
$search = new PhabricatorMainMenuSearchView();
$search->setUser($user);
- $search->setScope($this->getDefaultSearchScope());
$result = $search;
$pref_shortcut = PhabricatorUserPreferences::PREFERENCE_SEARCH_SHORTCUT;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 22, 3:23 AM (19 h, 32 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6917262
Default Alt Text
D8135.id18407.diff (7 KB)
Attached To
Mode
D8135: Replace "search scope" with selectable default behavior
Attached
Detach File
Event Timeline
Log In to Comment