From 689a222170aed32165cbe8bc8fc89fd428b29186 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Mon, 20 Jan 2014 03:33:58 -0500
Subject: [PATCH] Append per-folder search results to global index but only if it has matches

---
 program/lib/Roundcube/rcube_result_multifolder.php |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/program/lib/Roundcube/rcube_result_multifolder.php b/program/lib/Roundcube/rcube_result_multifolder.php
index 277a6d1..188fb26 100644
--- a/program/lib/Roundcube/rcube_result_multifolder.php
+++ b/program/lib/Roundcube/rcube_result_multifolder.php
@@ -52,8 +52,15 @@
      */
     public function add($result)
     {
-        $this->sets[] = $result;
-        $this->meta['count'] += $result->count();
+        if ($count = $result->count()) {
+            $this->sets[] = $result;
+            $this->meta['count'] += $count;
+
+            // append UIDs to global index
+            $folder = $result->get_parameters('MAILBOX');
+            $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get());
+            $this->index = array_merge($this->index, $index);
+        }
     }
 
     /**

--
Gitblit v1.9.1