summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2010-10-03 12:53:41 +0200
committerAndreas Gohr <andi@splitbrain.org>2010-10-03 12:53:41 +0200
commit2237b4fa4c84beb06a92308a19e45027e2bdc131 (patch)
treef1d956d6376837a6d272de016a1cd7b0dcc6bfc4 /inc
parent433445eb4175714188d048b7d6cb731ddd3385bf (diff)
downloadrpg-2237b4fa4c84beb06a92308a19e45027e2bdc131.tar.gz
rpg-2237b4fa4c84beb06a92308a19e45027e2bdc131.tar.bz2
correctly handle highlighting of partial searches FS#1353
Diffstat (limited to 'inc')
-rw-r--r--inc/fulltext.php21
-rw-r--r--inc/html.php9
2 files changed, 17 insertions, 13 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php
index 7dae183c8..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('_ft_snippet_re_preprocess', 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";
@@ -389,8 +389,19 @@ function ft_snippet($id,$highlight){
/**
* Wraps a search term in regex boundary checks.
*/
-function _ft_snippet_re_preprocess($term) {
- return '\b'.$term.'\b';
+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;
}
/**
@@ -685,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-:':
@@ -693,7 +704,7 @@ function ft_queryParser($query){
break;
case 'P+:':
$q['phrases'][] = $body;
- $q['highlight'][] = str_replace('*', '', $body);
+ $q['highlight'][] = $body;
break;
}
}
diff --git a/inc/html.php b/inc/html.php
index e1478b0a8..968a63e4e 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -285,7 +285,7 @@ function html_draft(){
*/
function html_hilight($html,$phrases){
$phrases = array_filter((array) $phrases);
- $regex = join('|',array_map('_html_hilight_re_preprocess', array_map('preg_quote_cb',$phrases)));
+ $regex = join('|',array_map('ft_snippet_re_preprocess', array_map('preg_quote_cb',$phrases)));
if ($regex === '') return $html;
$html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
@@ -293,13 +293,6 @@ function html_hilight($html,$phrases){
}
/**
- * Wraps a search term in regex boundary checks.
- */
-function _html_hilight_re_preprocess($term) {
- return '\b'.$term.'\b';
-}
-
-/**
* Callback used by html_hilight()
*
* @author Harry Fuecks <hfuecks@gmail.com>