Changeset 28459


Ignore:
Timestamp:
May 13, 2014, 10:09:04 PM (10 years ago)
Author:
rvelices
Message:

bug 3056: quick search - cache results for 5 minutes + comments + small fix

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/batch_manager.php

    r28318 r28459  
    395395{
    396396  include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' );
    397   $res = get_quick_search_results($_SESSION['bulk_manager_filter']['search']['q'], array('permissions'=>false));
     397  $res = get_quick_search_results_no_cache($_SESSION['bulk_manager_filter']['search']['q'], array('permissions'=>false));
    398398  $filter_sets[] = $res['items'];
    399399}
  • trunk/include/functions_search.inc.php

    r28383 r28459  
    266266define('QST_BREAK',          0x20);
    267267
     268/**
     269 * A search scope applies to a single token and restricts the search to a subset of searchable fields.
     270 */
    268271class QSearchScope
    269272{
     
    604607              break;
    605608            }
    606             if (strlen($crt_token) && isdigit(substr($crt_token,0,-1))
    607               && $qi+1<strlen($q) && isdigit($q[$qi+1]))
     609            if (strlen($crt_token) && preg_match('/[0-9]/', substr($crt_token,-1))
     610              && $qi+1<strlen($q) && preg_match('/[0-9]/', $q[$qi+1]))
    608611            {// dot between digits is not a separator e.g. F2.8
    609612              $crt_token .= $ch;
     
    704707  }
    705708
     709  /**
     710  * Applies recursively a search scope to all sub single tokens. We allow 'tag:(John Bill)' but we cannot evaluate
     711  * scopes on expressions so we rewrite as '(tag:John tag:Bill)'
     712  */
    706713  private function apply_scope(QSearchScope $scope)
    707714  {
     
    10621069}
    10631070
     1071
    10641072/**
    10651073 * Returns the search results corresponding to a quick/query search.
     
    10831091function get_quick_search_results($q, $options)
    10841092{
     1093  global $persistent_cache, $conf, $user;
     1094
     1095  $cache_key = $persistent_cache->make_key( array(
     1096    strtolower($q),
     1097    $conf['order_by'],
     1098    $user['id'],$user['cache_update_time'],
     1099    isset($options['permissions']) ? (boolean)$options['permissions'] : true,
     1100    isset($options['images_where']) ? $options['images_where'] : '',
     1101    ) );
     1102  if ($persistent_cache->get($cache_key, $res))
     1103  {
     1104    return $res;
     1105  }
     1106
     1107  $res = get_quick_search_results_no_cache($q, $options);
     1108
     1109  $persistent_cache->set($cache_key, $res, 300);
     1110  return $res;
     1111}
     1112
     1113/**
     1114 * @see get_quick_search_results but without result caching
     1115 */
     1116function get_quick_search_results_no_cache($q, $options)
     1117{
    10851118  global $conf;
    10861119  //@TODO: maybe cache for 10 minutes the result set to avoid many expensive sql calls when navigating the pictures
Note: See TracChangeset for help on using the changeset viewer.