Ignore:
Timestamp:
Apr 4, 2014, 6:14:38 AM (10 years ago)
Author:
rvelices
Message:

bug 3056: quick search - fixes and better numeric range searches examples:
ratio:0.9..1.1
ratio:0.9..
ratio:>0.9
ratio:<1.1
ratio:>3/2
ratio:16/9

File:
1 edited

Legend:

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

    r28065 r28066  
    316316class QNumericRangeScope extends QSearchScope
    317317{
    318   function __construct($id, $aliases, $allow_empty=false)
     318  private $epsilon;
     319  function __construct($id, $aliases, $allow_empty=false, $epsilon=0)
    319320  {
    320321    parent::__construct($id, $aliases, $allow_empty, false);
     322    $this->epsilon = $epsilon;
    321323  }
    322324
     
    327329      $range = array( substr($str,0,$pos), substr($str, $pos+2));
    328330    else
    329       $range = array($str, $str);
     331    {
     332      if ('>' == @$str[0])// ratio:>1
     333        $range = array( substr($str,1), '');
     334      elseif ('<' == @$str[0]) // size:<5mp
     335        $range = array('', substr($str,1));
     336      else
     337        $range = array($str, $str);
     338    }
     339
    330340    foreach ($range as $i =>&$val)
    331341    {
    332       if (preg_match('/^([0-9.]+)([km])?/i', $val, $matches))
     342      if (preg_match('#^([0-9.]+)/([0-9.]+)$#i', $val, $matches))
     343      {
     344        $val = floatval($matches[1]/$matches[2]);
     345      }
     346      elseif (preg_match('/^([0-9.]+)([km])?/i', $val, $matches))
    333347      {
    334348        $val = floatval($matches[1]);
     
    349363      else
    350364        $val = '';
     365      if (is_numeric($val))
     366      {
     367        if ($i)
     368          $val += $this->epsilon;
     369        else
     370          $val -= $this->epsilon;
     371      }
    351372    }
    352373
     
    584605            {
    585606              if ($i+1 < count($this->tokens))
    586                 $this->token[$i+1]->modifier |= QST_OR;
     607                $this->tokens[$i+1]->modifier |= QST_OR;
    587608              $token->term = "";
    588609            }
     
    619640  }
    620641
     642  private function apply_scope(QSearchScope $scope)
     643  {
     644    for ($i=0; $i<count($this->tokens); $i++)
     645    {
     646      if ($this->tokens[$i]->is_single)
     647      {
     648        if (!isset($this->tokens[$i]->scope))
     649          $this->tokens[$i]->scope = $scope;
     650      }
     651      else
     652        $this->tokens[$i]->aooky_scope($scope);
     653    }
     654  }
     655
    621656  private static function priority($modifier)
    622657  {
     
    727762function qsearch_get_images(QExpression $expr, QResults $qsr)
    728763{
    729   $qsr->images_iids = array_fill(0, count($expr->tokens), array());
     764  $qsr->images_iids = array_fill(0, count($expr->stokens), array());
    730765
    731766  $inflector = null;
     
    830865  foreach ($tokens as $token)
    831866  {
    832     if (!isset($token->scope) || 'tag' == $token->scope)
     867    if (!isset($token->scope) || 'tag' == $token->scope->id)
    833868    {
    834869      $transliterated_tokens[] = transliterate($token->term);
     
    10881123  $scopes[] = new QNumericRangeScope('width', array());
    10891124  $scopes[] = new QNumericRangeScope('height', array());
    1090   $scopes[] = new QNumericRangeScope('ratio', array());
     1125  $scopes[] = new QNumericRangeScope('ratio', array(), false, 0.001);
    10911126  $scopes[] = new QNumericRangeScope('size', array());
    10921127  $scopes[] = new QNumericRangeScope('filesize', array());
Note: See TracChangeset for help on using the changeset viewer.