summaryrefslogtreecommitdiff
path: root/inc/fulltext.php
diff options
context:
space:
mode:
authorChuck Kollars <ckollars9@yahoo.com>2009-05-04 20:38:35 +0200
committerChuck Kollars <ckollars9@yahoo.com>2009-05-04 20:38:35 +0200
commitb571ff2dc2f7b3db879de14daefb02597190ca13 (patch)
tree87c0b01eec056b606633d8d0f5ca589fb486ef7c /inc/fulltext.php
parent850c2e7c4319efcacd94ee246c3290f81e27769a (diff)
downloadrpg-b571ff2dc2f7b3db879de14daefb02597190ca13.tar.gz
rpg-b571ff2dc2f7b3db879de14daefb02597190ca13.tar.bz2
better search snippets FS#1669
Ignore-this: fdf33ea5a6c50a597bd432c0da98e927 Snippets containing more of the seached words are preferred over ones containing less search keywords darcs-hash:20090504183835-a07b1-7b0da249fcb5680019fc3032dfd6fb063e94576a.gz
Diffstat (limited to 'inc/fulltext.php')
-rw-r--r--inc/fulltext.php20
1 files changed, 14 insertions, 6 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php
index 3badb757c..a1b8a1541 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -303,10 +303,18 @@ function ft_snippet($id,$highlight){
$len = utf8_strlen($text);
// build a regexp from the phrases to highlight
- $re = join('|',array_map('preg_quote_cb',array_filter((array) $highlight)));
-
- for ($cnt=3; $cnt--;) {
- if (!preg_match('#('.$re.')#iu',$text,$match,PREG_OFFSET_CAPTURE,$offset)) break;
+ $re1 = '('.join('|',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";
+
+ for ($cnt=4; $cnt--;) {
+ if (0) {
+ } else if (preg_match('/'.$re3.'/iu',$text,$match,PREG_OFFSET_CAPTURE,$offset)) {
+ } else if (preg_match('/'.$re2.'/iu',$text,$match,PREG_OFFSET_CAPTURE,$offset)) {
+ } else if (preg_match('/'.$re1.'/iu',$text,$match,PREG_OFFSET_CAPTURE,$offset)) {
+ } else {
+ break;
+ }
list($str,$idx) = $match[0];
@@ -357,8 +365,8 @@ function ft_snippet($id,$highlight){
}
$m = "\1";
- $snippets = preg_replace('#('.$re.')#iu',$m.'$1'.$m,$snippets);
- $snippet = preg_replace('#'.$m.'([^'.$m.']*?)'.$m.'#iu','<strong class="search_hit">$1</strong>',hsc(join('... ',$snippets)));
+ $snippets = preg_replace('/'.$re1.'/iu',$m.'$1'.$m,$snippets);
+ $snippet = preg_replace('/'.$m.'([^'.$m.']*?)'.$m.'/iu','<strong class="search_hit">$1</strong>',hsc(join('... ',$snippets)));
return $snippet;
}