gui: fix folder search

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2017-08-27 16:33:02 +02:00
parent 2fa5eac578
commit d291779692

View File

@ -196,7 +196,6 @@ class ModelSearchSearch extends Model {
array_push($search_folders, $v); array_push($search_folders, $v);
} }
} }
array_push($search_folders, 0);
} }
@ -213,7 +212,7 @@ class ModelSearchSearch extends Model {
else if(ENABLE_FOLDER_RESTRICTIONS == 1 && count($search_folders) > 0) { else if(ENABLE_FOLDER_RESTRICTIONS == 1 && count($search_folders) > 0) {
$q2 = "?" . str_repeat(",?", count($search_folders)-1); $q2 = "?" . str_repeat(",?", count($search_folders)-1);
if($data['match']) { if(isset($data['match'][0]) && $data['match'][0]) {
// run a query to figure out how many total hits we have // run a query to figure out how many total hits we have
$query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE MATCH('$match')"); $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE MATCH('$match')");
@ -223,24 +222,21 @@ class ModelSearchSearch extends Model {
$query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE MATCH('$match') OPTION max_matches=" . (int)$query->num_rows); $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE MATCH('$match') OPTION max_matches=" . (int)$query->num_rows);
} }
if(count($search_folders) > 1) { $f_bag = array();
$f_bag = array(); foreach($query->rows as $q) {
foreach($query->rows as $q) { array_push($f_bag, $q['id']);
array_push($f_bag, $q['id']);
}
// run a final query to filter which messages are in this folder
$q1 = "?" . str_repeat(",?", count($f_bag)-1);
$f_bag = array_merge($f_bag, $search_folders);
//$query = $this->db->query("SELECT id FROM " . TABLE_FOLDER_MESSAGE . " WHERE message_id IN ($q1) AND folder_id IN ($q2)", $f_bag);
$query = $this->db->query("SELECT DISTINCT message_id AS id FROM " . TABLE_FOLDER_MESSAGE . " WHERE message_id IN ($q1) AND folder_id IN ($q2)", $f_bag);
if(LOG_LEVEL >= NORMAL) { syslog(LOG_INFO, sprintf("sql query: '%s' in %.2f s, %d hits", $query->query, $query->exec_time, $query->num_rows)); }
} }
// run a final query to filter which messages are in this folder
$q1 = "?" . str_repeat(",?", count($f_bag)-1);
$f_bag = array_merge($f_bag, $search_folders);
$query = $this->db->query("SELECT DISTINCT message_id AS id FROM " . TABLE_FOLDER_MESSAGE . " WHERE message_id IN ($q1) AND folder_id IN ($q2)", $f_bag);
if(LOG_LEVEL >= NORMAL) { syslog(LOG_INFO, sprintf("sql query: '%s' in %.2f s, %d hits", $query->query, $query->exec_time, $query->num_rows)); }
} }
else { else {
$query = $this->sphx->query("SELECT message_id FROM " . SPHINX_FOLDER_INDEX . " WHERE folder_id IN ($q2) $sortorder LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS, $search_folders); $query = $this->db->query("SELECT message_id AS id FROM " . TABLE_FOLDER_MESSAGE . " WHERE folder_id IN ($q2) LIMIT $offset,$pagelen", $search_folders);
} }
$total_found = $query->total_found; $total_found = $query->total_found;