Changeset 28128
- Timestamp:
- Apr 8, 2014, 10:45:48 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_search.inc.php
r28092 r28128 485 485 var $modifier; 486 486 var $term; /* the actual word/phrase string*/ 487 var $variants = array(); 487 488 var $scope; 488 489 … … 834 835 var $images_iids; 835 836 var $iids; 836 837 var $variants;838 837 } 839 838 … … 842 841 $qsr->images_iids = array_fill(0, count($expr->stokens), array()); 843 842 844 $inflector = null; 845 $lang_code = substr(get_default_language(),0,2); 846 include_once(PHPWG_ROOT_PATH.'include/inflectors/'.$lang_code.'.php'); 847 $class_name = 'Inflector_'.$lang_code; 848 if (class_exists($class_name)) 849 { 850 $inflector = new $class_name; 851 } 852 853 $query_base = 'SELECT id from '.IMAGES_TABLE.' i WHERE '; 843 $query_base = 'SELECT id from '.IMAGES_TABLE.' i WHERE 844 '; 854 845 for ($i=0; $i<count($expr->stokens); $i++) 855 846 { 856 847 $token = $expr->stokens[$i]; 857 $term = $token->term;858 848 $scope_id = isset($token->scope) ? $token->scope->id : 'photo'; 859 849 $clauses = array(); 860 850 861 $like = addslashes($t erm);851 $like = addslashes($token->term); 862 852 $like = str_replace( array('%','_'), array('\\%','\\_'), $like); // escape LIKE specials %_ 863 853 $file_like = 'CONVERT(file, CHAR) LIKE \'%'.$like.'%\''; … … 868 858 $clauses[] = $file_like; 869 859 870 $variants = array(); 871 if (strlen($term)>2 872 && ($expr->stoken_modifiers[$i] & (QST_QUOTED|QST_WILDCARD))==0 873 && strcspn($term, '\'0123456789') == strlen($term) ) 860 $variants = array_merge(array($token->term), $token->variants); 861 $fts = array(); 862 foreach ($variants as $variant) 874 863 { 875 if ($inflector!=null) 876 $variants = array_unique( array_diff( $inflector->get_variants($term), array($term) ) ); 877 $variants = trigger_event('qsearch_get_variants', $variants, $token, $expr); 878 $variants = array_unique( array_diff( $variants, array($term) ) ); 879 $qsr->variants[$term] = $variants; 880 } 881 882 if (strlen($term)>3) // default minimum full text index 864 if (mb_strlen($variant)<=3 865 || strcspn($variant, '!"#$%&()*+,./:;<=>?@[\]^`{|}~') < 3) 866 {// odd term or too short for full text search; fallback to regex but unfortunately this is diacritic/accent sensitive 867 $pre = ($token->modifier & QST_WILDCARD_BEGIN) ? '' : '[[:<:]]'; 868 $post = ($token->modifier & QST_WILDCARD_END) ? '' : '[[:>:]]'; 869 foreach( array('i.name', 'i.comment') as $field) 870 $clauses[] = $field.' REGEXP \''.$pre.addslashes(preg_quote($variant)).$post.'\''; 871 } 872 else 873 { 874 $ft = $variant; 875 if ($expr->stoken_modifiers[$i] & QST_QUOTED) 876 $ft = '"'.$ft.'"'; 877 if ($expr->stoken_modifiers[$i] & QST_WILDCARD_END) 878 $ft .= '*'; 879 $fts[] = $ft; 880 } 881 } 882 883 if (count($fts)) 883 884 { 884 $ft = $term; 885 if ($expr->stoken_modifiers[$i] & QST_QUOTED) 886 $ft = '"'.$ft.'"'; 887 if ($expr->stoken_modifiers[$i] & QST_WILDCARD_END) 888 $ft .= '*'; 889 foreach ($variants as $variant) 890 { 891 $ft.=' '.$variant; 892 } 893 $clauses[] = 'MATCH(i.name, i.comment) AGAINST( \''.addslashes($ft).'\' IN BOOLEAN MODE)'; 894 } 895 else 896 { 897 foreach( array('i.name', 'i.comment') as $field) 898 { 899 $clauses[] = $field.' REGEXP \'[[:<:]]'.addslashes(preg_quote($term)).'[[:>:]]\''; 900 } 885 $clauses[] = 'MATCH(i.name, i.comment) AGAINST( \''.addslashes(implode(' ',$fts)).'\' IN BOOLEAN MODE)'; 901 886 } 902 887 break; … … 937 922 if (!empty($clauses)) 938 923 { 939 $query = $query_base.'('.implode( ' OR ', $clauses).')';924 $query = $query_base.'('.implode("\n OR ", $clauses).')'; 940 925 $qsr->images_iids[$i] = query2array($query,null,'id'); 941 926 } … … 1231 1216 $scopes = trigger_event('qsearch_get_scopes', $scopes); 1232 1217 $expression = new QExpression($q, $scopes); 1218 1219 // get inflections for terms 1220 $inflector = null; 1221 $lang_code = substr(get_default_language(),0,2); 1222 @include_once(PHPWG_ROOT_PATH.'include/inflectors/'.$lang_code.'.php'); 1223 $class_name = 'Inflector_'.$lang_code; 1224 if (class_exists($class_name)) 1225 { 1226 $inflector = new $class_name; 1227 foreach( $expression->stokens as $token) 1228 { 1229 if (isset($token->scope) && !$token->scope->is_text) 1230 continue; 1231 if (strlen($token->term)>2 1232 && ($token->modifier & (QST_QUOTED|QST_WILDCARD))==0 1233 && strcspn($token->term, '\'0123456789') == strlen($token->term) ) 1234 { 1235 $token->variants = array_unique( array_diff( $inflector->get_variants($token->term), array($token->term) ) ); 1236 } 1237 } 1238 } 1239 1240 1233 1241 trigger_action('qsearch_expression_parsed', $expression); 1234 1242 //var_export($expression); … … 1252 1260 { 1253 1261 $debug[] = $expression->stokens[$i].': '.count($qsr->tag_ids[$i]).' tags, '.count($qsr->tag_iids[$i]).' tiids, '.count($qsr->images_iids[$i]).' iiids, '.count($qsr->iids[$i]).' iids' 1254 .( !empty($ qsr->variants[$expression->stokens[$i]->term]) ? ' variants: '.implode(', ',$qsr->variants[$expression->stokens[$i]->term]): '');1262 .( !empty($expression->stokens[$i]->variants) ? ' variants: '.implode(', ',$expression->stokens[$i]->variants): ''); 1255 1263 } 1256 1264 $debug[] = 'before perms '.count($ids); -
trunk/index.php
r27884 r28128 247 247 if (empty($page['items'])) 248 248 { 249 $template->append( 'no_search_results', $page['qsearch_details']['q']);249 $template->append( 'no_search_results', htmlspecialchars($page['qsearch_details']['q'])); 250 250 } 251 251 elseif (!empty($page['qsearch_details']['unmatched_terms']))
Note: See TracChangeset
for help on using the changeset viewer.