From 60c15d7deb9c53bcb1cf7881f441744bb29a6b63 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 15 Feb 2008 18:46:53 +0100 Subject: better highlighting for phrase searches FS#1193 This patch makes the highlighting of phrases in search snippets and on the pages itself much better. Now a regexp gets passed to the ?s darcs-hash:20080215174653-7ad00-cd2d6f7d408db7b7dd3cb9974c3eb27f3a9baeac.gz --- inc/html.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'inc/html.php') diff --git a/inc/html.php b/inc/html.php index caf52b85c..148d111aa 100644 --- a/inc/html.php +++ b/inc/html.php @@ -262,13 +262,12 @@ function html_draft(){ * @author Andreas Gohr * @author Harry Fuecks */ -function html_hilight($html,$query){ - //split at common delimiters - $queries = preg_split ('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$query,-1,PREG_SPLIT_NO_EMPTY); - foreach ($queries as $q){ - $q = preg_quote($q,'/'); - $html = preg_replace_callback("/((<[^>]*)|$q)/i",'html_hilight_callback',$html); - } +function html_hilight($html,$regex){ + // strip everything that's special except pipes: + $regex = preg_replace('![\[\]()/\\\\?\.+*]+!','',$regex); + + if ($regex === '') return $html; + $html = preg_replace_callback("/((<[^>]*)|$regex)/i",'html_hilight_callback',$html); return $html; } @@ -343,15 +342,15 @@ function html_search(){ flush(); //do fulltext search - $data = ft_pageSearch($QUERY,$poswords); + $data = ft_pageSearch($QUERY,$regex); if(count($data)){ $num = 1; foreach($data as $id => $cnt){ print '
'; - print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords); + print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$regex); print ': '.$cnt.' '.$lang['hits'].'
'; if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ? - print '
'.ft_snippet($id,$poswords).'
'; + print '
'.ft_snippet($id,$regex).'
'; } print '
'; flush(); -- cgit v1.2.3