From 23a202866a1f78402933052c42688c2afa887ce9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 29 Nov 2016 10:38:38 -0800 Subject: [PATCH] When running a fulltext query with no query, enforce order by document creation date Summary: Fixes T11929. When running with a query, we no longer enforce an order on the subquery join to produce results more quickly when searching for common strings. However, this means that empty queries (like those issued by "Close as Duplicate") don't order subquery results. Restore a `dateCreated` order if there is no query text. Test Plan: Artificially set limit to 10, still saw 10 most recent tasks. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11929 Differential Revision: https://secure.phabricator.com/D16960 --- .../PhabricatorMySQLFulltextStorageEngine.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/applications/search/fulltextstorage/PhabricatorMySQLFulltextStorageEngine.php b/src/applications/search/fulltextstorage/PhabricatorMySQLFulltextStorageEngine.php index f86458c26b..c30c74139e 100644 --- a/src/applications/search/fulltextstorage/PhabricatorMySQLFulltextStorageEngine.php +++ b/src/applications/search/fulltextstorage/PhabricatorMySQLFulltextStorageEngine.php @@ -347,13 +347,24 @@ final class PhabricatorMySQLFulltextStorageEngine $where = ''; } + if (strlen($compiled_query)) { + $order = ''; + } else { + // When not executing a query, order by document creation date. This + // is the default view in object browser dialogs, like "Close Duplicate". + $order = qsprintf( + $conn, + 'ORDER BY document.documentCreated DESC'); + } + return qsprintf( $conn, - 'SELECT %Q FROM %T document %Q %Q LIMIT 1000', + 'SELECT %Q FROM %T document %Q %Q %Q LIMIT 1000', $select, $document_table, $join, - $where); + $where, + $order); } protected function joinRelationship(