- Timestamp:
- Jul 7, 2014, 10:39:29 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_search.inc.php
r28709 r28992 296 296 return true; 297 297 } 298 299 function process_char(&$ch, &$crt_token) 300 { 301 return false; 302 } 298 303 } 299 304 … … 310 315 { 311 316 $str = $token->term; 317 $strict = array(0,0); 312 318 if ( ($pos = strpos($str, '..')) !== false) 313 319 $range = array( substr($str,0,$pos), substr($str, $pos+2)); 314 320 elseif ('>' == @$str[0])// ratio:>1 321 { 315 322 $range = array( substr($str,1), ''); 323 $strict[0] = 1; 324 } 316 325 elseif ('<' == @$str[0]) // size:<5mp 326 { 317 327 $range = array('', substr($str,1)); 328 $strict[1] = 1; 329 } 318 330 elseif( ($token->modifier & QST_WILDCARD_BEGIN) ) 319 331 $range = array('', $str); … … 350 362 if (is_numeric($val)) 351 363 { 352 if ($i )364 if ($i ^ $strict[$i]) 353 365 $val += $this->epsilon; 354 366 else … … 359 371 if (!$this->nullable && $range[0]=='' && $range[1] == '') 360 372 return false; 361 $token->scope_data = $range;373 $token->scope_data = array( 'range'=>$range, 'strict'=>$strict ); 362 374 return true; 363 375 } … … 366 378 { 367 379 $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].' '; 372 384 373 385 if (empty($clauses)) … … 393 405 { 394 406 $str = $token->term; 407 $strict = array(0,0); 395 408 if ( ($pos = strpos($str, '..')) !== false) 396 409 $range = array( substr($str,0,$pos), substr($str, $pos+2)); 397 410 elseif ('>' == @$str[0]) 411 { 398 412 $range = array( substr($str,1), ''); 413 $strict[0] = 1; 414 } 399 415 elseif ('<' == @$str[0]) 416 { 400 417 $range = array('', substr($str,1)); 418 $strict[1] = 1; 419 } 401 420 elseif( ($token->modifier & QST_WILDCARD_BEGIN) ) 402 421 $range = array('', $str); … … 412 431 array_shift($matches); 413 432 if (!isset($matches[1])) 414 $matches[1] = !$i ? 1 : 12;433 $matches[1] = ($i ^ $strict[$i]) ? 12 : 1; 415 434 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'; 418 439 } 419 440 elseif (strlen($val)) … … 432 453 $clauses = array(); 433 454 if ($token->scope_data[0]!=='') 434 $clauses[] = $field.' >= \'' . implode('-',$token->scope_data[0]).'\'';455 $clauses[] = $field.' >= \'' . $token->scope_data[0].'\''; 435 456 if ($token->scope_data[1]!=='') 436 $clauses[] = $field.' <= \'' . implode('-',$token->scope_data[1]).' 23:59:59\'';457 $clauses[] = $field.' <= \'' . $token->scope_data[1].'\''; 437 458 438 459 if (empty($clauses)) … … 579 600 break; 580 601 case ':': 581 $scope = @$root->scopes[ $crt_token];602 $scope = @$root->scopes[strtolower($crt_token)]; 582 603 if (!isset($scope) || isset($crt_scope)) 583 604 { // white space … … 621 642 // else white space go on.. 622 643 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; 626 652 } 627 else628 $crt_token .= $ch;629 653 break; 630 654 } … … 1118 1142 $res = get_quick_search_results_no_cache($q, $options); 1119 1143 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 } 1121 1148 return $res; 1122 1149 } … … 1128 1155 { 1129 1156 global $conf; 1130 //@TODO: maybe cache for 10 minutes the result set to avoid many expensive sql calls when navigating the pictures 1157 1131 1158 $q = trim(stripslashes($q)); 1132 1159 $search_results =
Note: See TracChangeset
for help on using the changeset viewer.