summaryrefslogtreecommitdiff
path: root/inc/search.php
diff options
context:
space:
mode:
authormatthiasgrimm <matthiasgrimm@users.sourceforge.net>2005-06-04 21:46:21 +0200
committermatthiasgrimm <matthiasgrimm@users.sourceforge.net>2005-06-04 21:46:21 +0200
commit4735a94937a223969f852e122716d4a56e141afd (patch)
tree404217e469b473db2bd7d2bd667652438eb8b4cf /inc/search.php
parent56c1874e2aaf8d8e59d21b4d305eb63a392ab7fa (diff)
downloadrpg-4735a94937a223969f852e122716d4a56e141afd.tar.gz
rpg-4735a94937a223969f852e122716d4a56e141afd.tar.bz2
UNDO: extended search fix
This patch fixes a bug in the search code and did some small optimizations. The possibility to start a search with _only_ excluded words (only words start with a minus sign) was disabled because this seem to crash PHP 4.3.10 (at least the ppc version :-() darcs-hash:20050604194621-7ef76-c240e1089df10645f5ea959a7ccb664a50afde7a.gz
Diffstat (limited to 'inc/search.php')
-rw-r--r--inc/search.php13
1 files changed, 4 insertions, 9 deletions
diff --git a/inc/search.php b/inc/search.php
index 6a0b8fbd7..654f1ab69 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -318,21 +318,17 @@ function search_fulltext(&$data,$base,$file,$type,$lvl,$opts){
}
}
- // if only negwords are given the preg_match_all() call will
- // crash libapache-mod-php4 v4.3.10-13 (segfault). Until we
- // got to the bottom of this problem, at least one posword is
- // required.
- if(!count($poswords)) return true;
-
- $reg = count($poswords) ? '^(?=.*?'.join(')(?=.*?',$poswords).')' : '^';
+ $req = count($poswords) ? $reg .= '^(?=.*?'.join(')(?=.*?',$poswords).')' : '^';
$reg .= count($negwords) ? '((?!'.join('|',$negwords).').)*$' : '.*$';
+ $mark = '('.join('|',$poswords).')';
//do the fulltext search
$matches = array();
if($cnt = preg_match_all('#'.$reg.'#usi',$lctext,$matches)){
//this is not the best way for snippet generation but the fastest I could find
//split query and only use the first token
- $q = $poswords[0];
+ $q = preg_split('/\s+/',$opts['query'],2);
+ $q = $q[0];
$p = utf8_strpos($lctext,$q);
$f = $p - 100;
$l = utf8_strlen($q) + 200;
@@ -340,7 +336,6 @@ function search_fulltext(&$data,$base,$file,$type,$lvl,$opts){
$snippet = '<span class="search_sep"> ... </span>'.
htmlspecialchars(utf8_substr($text,$f,$l)).
'<span class="search_sep"> ... </span>';
- $mark = '('.join('|',$poswords).')';
$snippet = preg_replace('#'.$mark.'#si','<span class="search_hit">\\1</span>',$snippet);
$data[] = array(