summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-03-10 09:40:57 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2017-04-21 20:43:36 +0200
commitecba3722da8b2bcb4987acb13c9bbe912f8e711e (patch)
tree111736761f382a8dd364628e1f83e4f8ccea40bc /apps/dav
parent867b3ee234b91ce5fbbbf3b81a5bcce59a0179a3 (diff)
downloadnextcloud-server-ecba3722da8b2bcb4987acb13c9bbe912f8e711e.tar.gz
nextcloud-server-ecba3722da8b2bcb4987acb13c9bbe912f8e711e.zip
Factorize query for searching contacts
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php11
1 files changed, 4 insertions, 7 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index 397a77c1d1b..65b8176aed4 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -869,16 +869,13 @@ class CardDavBackend implements BackendInterface, SyncSupport {
public function search($addressBookId, $pattern, $searchProperties) {
$query = $this->db->getQueryBuilder();
$query2 = $this->db->getQueryBuilder();
+
$query2->selectDistinct('cp.cardid')->from($this->dbCardsPropertiesTable, 'cp');
+ $query2->andWhere($query2->expr()->eq('cp.addressbookid', $query->createNamedParameter($addressBookId)));
foreach ($searchProperties as $property) {
- $query2->orWhere(
- $query2->expr()->andX(
- $query2->expr()->eq('cp.name', $query->createNamedParameter($property)),
- $query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%'))
- )
- );
+ $query2->expr()->orX($query2->expr()->eq('cp.name', $query->createNamedParameter($property)));
}
- $query2->andWhere($query2->expr()->eq('cp.addressbookid', $query->createNamedParameter($addressBookId)));
+ $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
$query->select('c.carddata', 'c.uri')->from($this->dbCardsTable, 'c')
->where($query->expr()->in('c.id', $query->createFunction($query2->getSQL())));