From 2d02a4735cff125229b071981ae14e42658b9fd6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 15 Mar 2017 14:46:23 +0100 Subject: Fix search ordering Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Cache.php | 2 ++ lib/private/Files/Cache/QuerySearchHelper.php | 11 +++++++++++ 2 files changed, 13 insertions(+) (limited to 'lib/private/Files/Cache') diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 95a78f99829..b14f80a7e23 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -666,6 +666,8 @@ class Cache implements ICache { $query->andWhere($this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation())); + $this->querySearchHelper->addSearchOrdersToQuery($query, $searchQuery->getOrder()); + if ($searchQuery->getLimit()) { $query->setMaxResults($searchQuery->getLimit()); } diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index 7d8098f0efa..2d20da72f51 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -26,6 +26,7 @@ use OCP\Files\IMimeTypeLoader; use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchComparison; use OCP\Files\Search\ISearchOperator; +use OCP\Files\Search\ISearchOrder; /** * Tools for transforming search queries into database queries @@ -185,4 +186,14 @@ class QuerySearchHelper { } return $builder->createNamedParameter($value, $type); } + + /** + * @param IQueryBuilder $query + * @param ISearchOrder[] $orders + */ + public function addSearchOrdersToQuery(IQueryBuilder $query, array $orders) { + foreach ($orders as $order) { + $query->addOrderBy($order->getField(), $order->getDirection()); + } + } } -- cgit v1.2.3