Changeset 28992 for trunk


Ignore:
Timestamp:
Jul 7, 2014, 10:39:29 PM (10 years ago)
Author:
rvelices
Message:

bug 3056 quick search - small fixes & improvements

  • scopes are case insesitive date:2013 and Date:2013 are the same thing
  • use strict comparison in scopes when required e.g. date:<2013 is not matching year 2013
  • allow scopes (in plugins) to overwrite behaviour of space characters ...
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_search.inc.php

    r28709 r28992  
    296296    return true;
    297297  }
     298 
     299  function process_char(&$ch, &$crt_token)
     300  {
     301    return false;
     302  }
    298303}
    299304
     
    310315  {
    311316    $str = $token->term;
     317    $strict = array(0,0);
    312318    if ( ($pos = strpos($str, '..')) !== false)
    313319      $range = array( substr($str,0,$pos), substr($str, $pos+2));
    314320    elseif ('>' == @$str[0])// ratio:>1
     321    {
    315322      $range = array( substr($str,1), '');
     323      $strict[0] = 1;
     324    }
    316325    elseif ('<' == @$str[0]) // size:<5mp
     326    {
    317327      $range = array('', substr($str,1));
     328      $strict[1] = 1;
     329    }
    318330    elseif( ($token->modifier & QST_WILDCARD_BEGIN) )
    319331      $range = array('', $str);
     
    350362      if (is_numeric($val))
    351363      {
    352         if ($i)
     364        if ($i ^ $strict[$i])
    353365          $val += $this->epsilon;
    354366        else
     
    359371    if (!$this->nullable && $range[0]=='' && $range[1] == '')
    360372      return false;
    361     $token->scope_data = $range;
     373    $token->scope_data = array( 'range'=>$range, 'strict'=>$strict );
    362374    return true;
    363375  }
     
    366378  {
    367379    $clauses = array();
    368     if ($token->scope_data[0]!=='')
    369       $clauses[] = $field.' >= ' .$token->scope_data[0].' ';
    370     if ($token->scope_data[1]!=='')
    371       $clauses[] = $field.' <= ' .$token->scope_data[1].' ';
     380    if ($token->scope_data['range'][0]!=='')
     381      $clauses[] = $field.' >'.($token->scope_data['strict'][0]?'':'=').$token->scope_data['range'][0].' ';
     382    if ($token->scope_data['range'][1]!=='')
     383      $clauses[] = $field.' <'.($token->scope_data['strict'][1]?'':'=').$token->scope_data['range'][1].' ';
    372384
    373385    if (empty($clauses))
     
    393405  {
    394406    $str = $token->term;
     407    $strict = array(0,0);
    395408    if ( ($pos = strpos($str, '..')) !== false)
    396409      $range = array( substr($str,0,$pos), substr($str, $pos+2));
    397410    elseif ('>' == @$str[0])
     411    {
    398412      $range = array( substr($str,1), '');
     413      $strict[0] = 1;
     414    }
    399415    elseif ('<' == @$str[0])
     416    {
    400417      $range = array('', substr($str,1));
     418      $strict[1] = 1;
     419    }
    401420    elseif( ($token->modifier & QST_WILDCARD_BEGIN) )
    402421      $range = array('', $str);
     
    412431        array_shift($matches);
    413432        if (!isset($matches[1]))
    414           $matches[1] = !$i ? 1 : 12;
     433          $matches[1] = ($i ^ $strict[$i]) ? 12 : 1;
    415434        if (!isset($matches[2]))
    416           $matches[2] = !$i ? 1 : 31;
    417         $val = $matches;
     435          $matches[2] = ($i ^ $strict[$i]) ? 31 : 1;
     436        $val = implode('-', $matches);
     437        if ($i ^ $strict[$i])
     438          $val .= ' 23:59:59';
    418439      }
    419440      elseif (strlen($val))
     
    432453    $clauses = array();
    433454    if ($token->scope_data[0]!=='')
    434       $clauses[] = $field.' >= \'' . implode('-',$token->scope_data[0]).'\'';
     455      $clauses[] = $field.' >= \'' . $token->scope_data[0].'\'';
    435456    if ($token->scope_data[1]!=='')
    436       $clauses[] = $field.' <= \'' . implode('-',$token->scope_data[1]).' 23:59:59\'';
     457      $clauses[] = $field.' <= \'' . $token->scope_data[1].'\'';
    437458
    438459    if (empty($clauses))
     
    579600            break;
    580601          case ':':
    581             $scope = @$root->scopes[$crt_token];
     602            $scope = @$root->scopes[strtolower($crt_token)];
    582603            if (!isset($scope) || isset($crt_scope))
    583604            { // white space
     
    621642            // else white space go on..
    622643          default:
    623             if (strpos(' ,.;!?', $ch)!==false)
    624             { // white space
    625               $this->push($crt_token, $crt_modifier, $crt_scope);
     644            if (!$crt_scope || !$crt_scope->process_char($ch, $crt_token))
     645            {
     646              if (strpos(' ,.;!?', $ch)!==false)
     647              { // white space
     648                $this->push($crt_token, $crt_modifier, $crt_scope);
     649              }
     650              else
     651                $crt_token .= $ch;
    626652            }
    627             else
    628               $crt_token .= $ch;
    629653            break;
    630654        }
     
    11181142  $res = get_quick_search_results_no_cache($q, $options);
    11191143
    1120   $persistent_cache->set($cache_key, $res, 300);
     1144  if ( count($res['items']) )
     1145  {// cache the results only if not empty - otherwise it is useless
     1146    $persistent_cache->set($cache_key, $res, 300);
     1147  }
    11211148  return $res;
    11221149}
     
    11281155{
    11291156  global $conf;
    1130   //@TODO: maybe cache for 10 minutes the result set to avoid many expensive sql calls when navigating the pictures
     1157
    11311158  $q = trim(stripslashes($q));
    11321159  $search_results =
Note: See TracChangeset for help on using the changeset viewer.