From 3180f1638a28182941dcdb4e3b295e0a50c3e24a Mon Sep 17 00:00:00 2001 From: rvelices Date: Mon, 24 Sep 2012 20:50:24 +0000 Subject: quick search - better handling of wildcard begin/end in tag names (technically rewrote parts of query analser) still to do: exclusion of matching tags git-svn-id: http://piwigo.org/svn/trunk@18207 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions_search.inc.php | 156 ++++++++++++++++++++++++++------------- 1 file changed, 103 insertions(+), 53 deletions(-) diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index db54dc767..fec019f81 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -271,6 +271,23 @@ function is_word_char($ch) return ($ch>='0' && $ch<='9') || ($ch>='a' && $ch<='z') || ($ch>='A' && $ch<='Z') || ord($ch)>127; } +function is_odd_wbreak_begin($ch) +{ + return strpos('[{<=*+', $ch)===false ? false:true; +} + +function is_odd_wbreak_end($ch) +{ + return strpos(']}>=*+', $ch)===false ? false:true; +} + +define('QST_QUOTED', 0x01); +define('QST_NOT', 0x02); +define('QST_WILDCARD_BEGIN',0x04); +define('QST_WILDCARD_END', 0x08); +define('QST_WILDCARD', QST_WILDCARD_BEGIN|QST_WILDCARD_END); + + /** * analyzes and splits the quick/query search query $q into tokens * q='john bill' => 2 tokens 'john' 'bill' @@ -283,66 +300,66 @@ function analyse_qsearch($q, &$qtokens, &$qtoken_modifiers) $tokens = array(); $token_modifiers = array(); $crt_token = ""; - $crt_token_modifier = ""; - $state = 0; + $crt_token_modifier = 0; for ($i=0; $i<~')==0 ) + elseif ( strcspn($ch, '*+-><~')==0 ) { //special full text modifier if (strlen($crt_token)) { - $tokens[] = $crt_token; $token_modifiers[] = $crt_token_modifier; - $crt_token = ""; $crt_token_modifier = ""; + $crt_token .= $ch; + } + else + { + if ( $ch=='*' ) + $crt_token_modifier |= QST_WILDCARD_BEGIN; + if ( $ch=='-' ) + $crt_token_modifier |= QST_NOT; } - $crt_token_modifier .= $ch; } elseif (preg_match('/[\s,.;!\?]+/', $ch)) { // white space if (strlen($crt_token)) { $tokens[] = $crt_token; $token_modifiers[] = $crt_token_modifier; - $crt_token = ""; $crt_token_modifier = ""; + $crt_token = ""; } + $crt_token_modifier = 0; } else { $crt_token .= $ch; } - break; - case 1: // qualified with quotes - switch ($ch) + } + else // qualified with quotes + { + if ($ch=='"') + { + if ($i+1 < strlen($q) && $q[$i+1]=='*') { - case '"': - $tokens[] = $crt_token; $token_modifiers[] = $crt_token_modifier; - $crt_token = ""; $crt_token_modifier = ""; - $state=0; - break; - default: - $crt_token .= $ch; + $crt_token_modifier |= QST_WILDCARD_END; + $i++; } + $tokens[] = $crt_token; $token_modifiers[] = $crt_token_modifier; + $crt_token = ""; $crt_token_modifier = 0; + $state=0; break; + } + else + $crt_token .= $ch; } } if (strlen($crt_token)) @@ -382,7 +399,7 @@ function get_qsearch_like_clause($tokens, $token_modifiers, $field) for ($i=0; $i array('q'=>stripslashes($q)), ); $q = trim($q); - if (empty($q)) + analyse_qsearch($q, $tokens, $token_modifiers); + if (count($tokens)==0) { return $search_results; } + $debug[] = ''; + global $template; + $template->append('footer_elements', implode(', ', $debug) ); + if ( $super_order_by or empty($by_weights) ) { $search_results['items'] = $allowed_images; -- cgit v1.2.3