From 10171e21013c4f50580598f67796e193dafd2208 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 4 Jan 2017 14:40:09 -0800 Subject: [PATCH] Allow "O42" to find packages by monogram in Owners typeaheads Summary: When a user queries by package monogram explicitly, search by package ID. Test Plan: {F2305075} Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D17142 --- .../typeahead/PhabricatorOwnersPackageDatasource.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/applications/owners/typeahead/PhabricatorOwnersPackageDatasource.php b/src/applications/owners/typeahead/PhabricatorOwnersPackageDatasource.php index 41d5d6823a..720b4cc2ef 100644 --- a/src/applications/owners/typeahead/PhabricatorOwnersPackageDatasource.php +++ b/src/applications/owners/typeahead/PhabricatorOwnersPackageDatasource.php @@ -22,9 +22,18 @@ final class PhabricatorOwnersPackageDatasource $results = array(); $query = id(new PhabricatorOwnersPackageQuery()) - ->withNameNgrams($raw_query) ->setOrder('name'); + // If the user is querying by monogram explicitly, like "O123", do an ID + // search. Otherwise, do an ngram substring search. + if (preg_match('/^[oO]\d+\z/', $raw_query)) { + $id = trim($raw_query, 'oO'); + $id = (int)$id; + $query->withIDs(array($id)); + } else { + $query->withNameNgrams($raw_query); + } + $packages = $this->executeQuery($query); foreach ($packages as $package) { $name = $package->getName();