summaryrefslogtreecommitdiff
path: root/inc/fulltext.php
diff options
context:
space:
mode:
authordaniel.lindgren <daniel.lindgren@tullverket.se>2009-03-11 17:02:55 +0100
committerdaniel.lindgren <daniel.lindgren@tullverket.se>2009-03-11 17:02:55 +0100
commitb42bcfe76a8bf94574aebbbe4f9cf31d37b65553 (patch)
tree803c2bbafa714b52ed4f36813428bf37e393375a /inc/fulltext.php
parent6080c584e81927b2263267822e3ebc1e553662ec (diff)
downloadrpg-b42bcfe76a8bf94574aebbbe4f9cf31d37b65553.tar.gz
rpg-b42bcfe76a8bf94574aebbbe4f9cf31d37b65553.tar.bz2
Search function update
Ignore-this: 4cd6bddacb795ef15f133559c223ac1f * Adds the possibility to exclude namespace(s) from search, by preceding them with "^". * Changed handling of search parameters to allow any order of words and namespaces. darcs-hash:20090311160255-13810-c2e00cc7764d180967b4c6f22e17b1c0dafe36f4.gz
Diffstat (limited to 'inc/fulltext.php')
-rw-r--r--inc/fulltext.php23
1 files changed, 17 insertions, 6 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php
index 5399989fa..3badb757c 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)){