summaryrefslogtreecommitdiff
path: root/inc/fulltext.php
diff options
context:
space:
mode:
authorAdrian Lang <mail@adrianlang.de>2010-10-07 09:44:02 +0200
committerAdrian Lang <mail@adrianlang.de>2010-10-07 09:44:02 +0200
commitd9c8ae6b7379d7b64d4817dbd5cca276b45a9dd5 (patch)
tree39c26d5412170ca4fa176962e60e9962dc643667 /inc/fulltext.php
parent2c053ed58376c6709596ab48fc40dceb90d4e89d (diff)
parent85dd53ceb1c2d9a7abe01b5ec50d155dcb142c59 (diff)
downloadrpg-d9c8ae6b7379d7b64d4817dbd5cca276b45a9dd5.tar.gz
rpg-d9c8ae6b7379d7b64d4817dbd5cca276b45a9dd5.tar.bz2
Merge branch 'master' into stable
Diffstat (limited to 'inc/fulltext.php')
-rw-r--r--inc/fulltext.php24
1 files changed, 21 insertions, 3 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php
index e90205e9c..943a5d401 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -313,7 +313,7 @@ function ft_snippet($id,$highlight){
$len = utf8_strlen($text);
// build a regexp from the phrases to highlight
- $re1 = '('.join('|',array_map('preg_quote_cb',array_filter((array) $highlight))).')';
+ $re1 = '('.join('|',array_map('ft_snippet_re_preprocess', array_map('preg_quote_cb',array_filter((array) $highlight)))).')';
$re2 = "$re1.{0,75}(?!\\1)$re1";
$re3 = "$re1.{0,45}(?!\\1)$re1.{0,45}(?!\\1)(?!\\2)$re1";
@@ -387,6 +387,24 @@ function ft_snippet($id,$highlight){
}
/**
+ * Wraps a search term in regex boundary checks.
+ */
+function ft_snippet_re_preprocess($term) {
+ if(substr($term,0,2) == '\\*'){
+ $term = substr($term,2);
+ }else{
+ $term = '\b'.$term;
+ }
+
+ if(substr($term,-2,2) == '\\*'){
+ $term = substr($term,0,-2);
+ }else{
+ $term = $term.'\b';
+ }
+ return $term;
+}
+
+/**
* Combine found documents and sum up their scores
*
* This function is used to combine searched words with a logical
@@ -678,7 +696,7 @@ function ft_queryParser($query){
break;
case 'W+:':
$q['words'][] = $body;
- $q['highlight'][] = str_replace('*', '', $body);
+ $q['highlight'][] = $body;
$q['and'][] = $body; // for backward compatibility
break;
case 'P-:':
@@ -686,7 +704,7 @@ function ft_queryParser($query){
break;
case 'P+:':
$q['phrases'][] = $body;
- $q['highlight'][] = str_replace('*', '', $body);
+ $q['highlight'][] = $body;
break;
}
}