From f2c42c791efc4797ed22d8ca87518780ced759cb Mon Sep 17 00:00:00 2001 From: rvelices Date: Tue, 13 May 2014 20:09:04 +0000 Subject: bug 3056: quick search - cache results for 5 minutes + comments + small fix git-svn-id: http://piwigo.org/svn/trunk@28459 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions_search.inc.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'include/functions_search.inc.php') diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index 1aba9b961..6280c4d9d 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -265,6 +265,9 @@ define('QST_WILDCARD_END', 0x10); define('QST_WILDCARD', QST_WILDCARD_BEGIN|QST_WILDCARD_END); define('QST_BREAK', 0x20); +/** + * A search scope applies to a single token and restricts the search to a subset of searchable fields. + */ class QSearchScope { var $id; @@ -603,8 +606,8 @@ class QMultiToken $crt_token .= $ch; break; } - if (strlen($crt_token) && isdigit(substr($crt_token,0,-1)) - && $qi+1tokens); $i++) @@ -1061,6 +1068,7 @@ function qsearch_eval(QMultiToken $expr, QResults $qsr, &$qualifies, &$ignored_t return $ids; } + /** * Returns the search results corresponding to a quick/query search. * A quick/query search returns many items (search is not strict), but results @@ -1081,6 +1089,31 @@ function qsearch_eval(QMultiToken $expr, QResults $qsr, &$qualifies, &$ignored_t * @return array */ function get_quick_search_results($q, $options) +{ + global $persistent_cache, $conf, $user; + + $cache_key = $persistent_cache->make_key( array( + strtolower($q), + $conf['order_by'], + $user['id'],$user['cache_update_time'], + isset($options['permissions']) ? (boolean)$options['permissions'] : true, + isset($options['images_where']) ? $options['images_where'] : '', + ) ); + if ($persistent_cache->get($cache_key, $res)) + { + return $res; + } + + $res = get_quick_search_results_no_cache($q, $options); + + $persistent_cache->set($cache_key, $res, 300); + return $res; +} + +/** + * @see get_quick_search_results but without result caching + */ +function get_quick_search_results_no_cache($q, $options) { global $conf; //@TODO: maybe cache for 10 minutes the result set to avoid many expensive sql calls when navigating the pictures -- cgit v1.2.3