diff --git a/inc/fulltext.php b/inc/fulltext.php index 5399989faebe82ea570ece18688922e1d75b9533..3badb757c7f494ac488bce3b97837700ae3ea024 100644 --- a/inc/fulltext.php +++ b/inc/fulltext.php @@ -78,6 +78,16 @@ function _ft_pageSearch(&$data){ } } + // filter unwanted namespaces + if(!empty($q['notns'])) { + $pattern = implode('|^',$q['notns']); + foreach($docs as $key => $val) { + if(preg_match('/^'.$pattern.'/',$key)) { + unset($docs[$key]); + } + } + } + // remove negative matches foreach($not as $n){ unset($docs[$n]); @@ -402,17 +412,12 @@ function ft_queryParser($query){ $q = array(); $q['query'] = $query; $q['ns'] = array(); + $q['notns'] = array(); $q['phrases'] = array(); $q['words'] = array(); $q['and'] = array(); $q['not'] = array(); - // strip namespace from query - if(preg_match('/([^@]*)@(.*)/',$query,$match)) { - $query = $match[1]; - $q['ns'] = explode('@',preg_replace("/ /",'',$match[2])); - } - // handle phrase searches while(preg_match('/"(.*?)"/',$query,$match)){ $q['phrases'][] = $match[1]; @@ -425,6 +430,12 @@ function ft_queryParser($query){ if($w{0} == '-'){ $token = idx_tokenizer($w,$stopwords,true); if(count($token)) $q['not'] = array_merge($q['not'],$token); + } else if ($w{0} == '@') { // Namespace to search? + $w = substr($w,1); + $q['ns'] = array_merge($q['ns'],(array)$w); + } else if ($w{0} == '^') { // Namespace not to search? + $w = substr($w,1); + $q['notns'] = array_merge($q['notns'],(array)$w); }else{ // asian "words" need to be searched as phrases if(@preg_match_all('/(('.IDX_ASIAN.')+)/u',$w,$matches)){ diff --git a/inc/html.php b/inc/html.php index 114bdad9d9a8c3166b0c9a7b7a10a467f5967836..b1e755cd34e9c4455512d42608215c450c3f4c17 100644 --- a/inc/html.php +++ b/inc/html.php @@ -302,7 +302,7 @@ function html_search(){ flush(); //check if search is restricted to namespace - if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) { + if(preg_match('/@([^@]*)/',$QUERY,$match)) { $id = cleanID($match[1]); if(empty($id)) { print '<div class="nothing">'.$lang['nothingfound'].'</div>';