From 8aa7508dab46e07bc3b302c4e4069783979f7a14 Mon Sep 17 00:00:00 2001 From: SJ Date: Mon, 23 Dec 2013 12:12:18 +0100 Subject: [PATCH] show total found number --- webui/controller/search/helper.php | 4 +-- webui/model/search/search.php | 25 +++++++++++-------- .../theme/default/templates/search/helper.tpl | 2 +- .../theme/mobile/templates/search/helper.tpl | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/webui/controller/search/helper.php b/webui/controller/search/helper.php index f94f74d5..86ffb8b5 100644 --- a/webui/controller/search/helper.php +++ b/webui/controller/search/helper.php @@ -54,12 +54,12 @@ class ControllerSearchHelper extends Controller { $this->fixup_post_request(); - list ($this->data['n'], $this->data['all_ids'], $this->data['messages']) = $this->model_search_search->search_messages($this->a, $this->data['page']); + list ($this->data['n'], $this->data['total_found'], $this->data['all_ids'], $this->data['messages']) = $this->model_search_search->search_messages($this->a, $this->data['page']); } else { $this->fixup_post_simple_request(); - list ($this->data['n'], $this->data['all_ids'], $this->data['messages']) = $this->model_search_search->search_messages($this->a, $this->data['page']); + list ($this->data['n'], $this->data['total_found'], $this->data['all_ids'], $this->data['messages']) = $this->model_search_search->search_messages($this->a, $this->data['page']); } diff --git a/webui/model/search/search.php b/webui/model/search/search.php index 91356ec3..2efc9784 100644 --- a/webui/model/search/search.php +++ b/webui/model/search/search.php @@ -5,6 +5,7 @@ class ModelSearchSearch extends Model { public function search_messages($data = array(), $page = 0) { $one_page_of_ids = array(); $total_hits = 0; + $total_found = 0; $sort = "sent"; $order = "DESC"; $sortorder = "ORDER BY sent DESC"; @@ -44,13 +45,14 @@ class ModelSearchSearch extends Model { if(isset($m['ids'])) { $all_ids = $m['ids']; + $total_found = $m['total_found']; } else { if(isset($data['ref']) && $data['ref']){ - $all_ids = $this->query_all_possible_IDs_by_reference($data['ref'], $cache_key); + list ($total_found, $all_ids) = $this->query_all_possible_IDs_by_reference($data['ref'], $cache_key); } else { - $all_ids = $this->query_all_possible_IDs($data, $sort, $order, $sortorder, $cache_key); + list ($total_found, $all_ids) = $this->query_all_possible_IDs($data, $sort, $order, $sortorder, $cache_key); } } @@ -86,7 +88,7 @@ class ModelSearchSearch extends Model { $all_ids_csv = substr($all_ids_csv, 1, strlen($all_ids_csv)); - return array($total_hits, $all_ids_csv, $this->get_meta_data($one_page_of_ids, $q, $sortorder)); + return array($total_hits, $total_found, $all_ids_csv, $this->get_meta_data($one_page_of_ids, $q, $sortorder)); } @@ -225,7 +227,9 @@ class ModelSearchSearch extends Model { $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $a $id $date $attachment $direction $size $folders MATCH('$match') $sortorder LIMIT 0," . MAX_SEARCH_HITS . " OPTION max_matches=" . MAX_SEARCH_HITS); } - if(ENABLE_SYSLOG == 1) { syslog(LOG_INFO, sprintf("sphinx query: '%s' in %.2f s, %d hits", $query->query, $query->exec_time, $query->num_rows)); } + $total_found = $query->total_found; + + if(ENABLE_SYSLOG == 1) { syslog(LOG_INFO, sprintf("sphinx query: '%s' in %.2f s, %d hits, %d total found", $query->query, $query->exec_time, $query->num_rows, $total_found)); } /* @@ -251,11 +255,11 @@ class ModelSearchSearch extends Model { if($data['sort'] == 'from' || $data['sort'] == 'subj') { - $query = $this->db->query("SELECT id FROM " . TABLE_META . " WHERE id IN ($q) ORDER BY `$sort` $order", $ids); + $fs_query = $this->db->query("SELECT id FROM " . TABLE_META . " WHERE id IN ($q) ORDER BY `$sort` $order", $ids); $ids = array(); - foreach($query->rows as $q) { + foreach($fs_query->rows as $q) { array_push($ids, $q['id']); } @@ -264,10 +268,10 @@ class ModelSearchSearch extends Model { if(MEMCACHED_ENABLED && $cache_key) { $memcache = Registry::get('memcache'); - $memcache->add($cache_key, array('ts' => time(), 'total_hits' => count($ids), 'ids' => $ids), 0, MEMCACHED_TTL); + $memcache->add($cache_key, array('ts' => time(), 'total_hits' => count($ids), 'ids' => $ids, 'total_found' => $total_found), 0, MEMCACHED_TTL); } - return $ids; + return array($total_found, $ids); } @@ -292,13 +296,14 @@ class ModelSearchSearch extends Model { } } + $total_found = count($ids); if(MEMCACHED_ENABLED && $cache_key) { $memcache = Registry::get('memcache'); - $memcache->add($cache_key, array('ts' => time(), 'total_hits' => count($ids), 'ids' => $ids), 0, MEMCACHED_TTL); + $memcache->add($cache_key, array('ts' => time(), 'total_hits' => count($ids), 'total_found' => $total_found, 'ids' => $ids), 0, MEMCACHED_TTL); } - return $ids; + return array($total_found, $ids); } diff --git a/webui/view/theme/default/templates/search/helper.tpl b/webui/view/theme/default/templates/search/helper.tpl index b9c4fdba..3bc2d1ce 100644 --- a/webui/view/theme/default/templates/search/helper.tpl +++ b/webui/view/theme/default/templates/search/helper.tpl @@ -125,7 +125,7 @@   0) { ?>   - -, : + -, : $n) { ?> ()     diff --git a/webui/view/theme/mobile/templates/search/helper.tpl b/webui/view/theme/mobile/templates/search/helper.tpl index e36e7428..e47c0eb8 100644 --- a/webui/view/theme/mobile/templates/search/helper.tpl +++ b/webui/view/theme/mobile/templates/search/helper.tpl @@ -96,7 +96,7 @@ 0) { ?><<   <<   0) { ?> < < - -, : + -, : $n) { ?> () > >   >>   >>