From 021c1b5a05a6efae212a32c52f4fe026fc129153 Mon Sep 17 00:00:00 2001 From: vrana Date: Mon, 2 Apr 2012 17:29:52 -0700 Subject: [PATCH] Display object shortcuts in search results Summary: Search for D1234 currently finds everything but revision 1234. Test Plan: Search for: - rX - rX1234 under SVN - rXabcd under GIT - D1234 - T4 Reviewers: epriestley Reviewed By: epriestley CC: aran Differential Revision: https://secure.phabricator.com/D2081 --- .../search/PhabricatorSearchController.php | 35 +++++++++++++++++++ .../search/controller/search/__init__.php | 4 +++ 2 files changed, 39 insertions(+) diff --git a/src/applications/search/controller/search/PhabricatorSearchController.php b/src/applications/search/controller/search/PhabricatorSearchController.php index 23456c2f85..754f150452 100644 --- a/src/applications/search/controller/search/PhabricatorSearchController.php +++ b/src/applications/search/controller/search/PhabricatorSearchController.php @@ -230,6 +230,41 @@ final class PhabricatorSearchController $results = $pager->sliceResults($results); + if (!$request->getInt('page')) { + $jump = null; + $query_str = $query->getQuery(); + $match = null; + if (preg_match('/^r([A-Z]+)(\S*)$/', $query_str, $match)) { + $repository = id(new PhabricatorRepository()) + ->loadOneWhere('callsign = %s', $match[1]); + if ($match[2] == '') { + $jump = $repository; + } elseif ($repository) { + $jump = id(new PhabricatorRepositoryCommit())->loadOneWhere( + 'repositoryID = %d AND commitIdentifier = %s', + $repository->getID(), + $match[2]); + if (!$jump) { + try { + $jump = id(new PhabricatorRepositoryCommit())->loadOneWhere( + 'repositoryID = %d AND commitIdentifier LIKE %>', + $repository->getID(), + $match[2]); + } catch (AphrontQueryCountException $ex) { + // Ambiguous, no jump. + } + } + } + } elseif (preg_match('/^d(\d+)$/i', $query_str, $match)) { + $jump = id(new DifferentialRevision())->load($match[1]); + } elseif (preg_match('/^t(\d+)$/i', $query_str, $match)) { + $jump = id(new ManiphestTask())->load($match[1]); + } + if ($jump) { + array_unshift($results, $jump->getPHID()); + } + } + if ($results) { $loader = new PhabricatorObjectHandleData($results); diff --git a/src/applications/search/controller/search/__init__.php b/src/applications/search/controller/search/__init__.php index a2fd9df50d..5e3ac55056 100644 --- a/src/applications/search/controller/search/__init__.php +++ b/src/applications/search/controller/search/__init__.php @@ -8,9 +8,13 @@ phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/redirect'); +phutil_require_module('phabricator', 'applications/differential/storage/revision'); +phutil_require_module('phabricator', 'applications/maniphest/storage/task'); phutil_require_module('phabricator', 'applications/people/storage/preferences'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/phid/handle/data'); +phutil_require_module('phabricator', 'applications/repository/storage/commit'); +phutil_require_module('phabricator', 'applications/repository/storage/repository'); phutil_require_module('phabricator', 'applications/search/constants/scope'); phutil_require_module('phabricator', 'applications/search/controller/base'); phutil_require_module('phabricator', 'applications/search/engine/jumpnav');