summaryrefslogtreecommitdiff
path: root/inc/html.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2008-02-15 18:46:53 +0100
committerAndreas Gohr <andi@splitbrain.org>2008-02-15 18:46:53 +0100
commit60c15d7deb9c53bcb1cf7881f441744bb29a6b63 (patch)
tree7e26e3ef7b12d426002f181164311c68df73e3c5 /inc/html.php
parentdf466c7aec2704406e008f31924afa8b80c259ab (diff)
downloadrpg-60c15d7deb9c53bcb1cf7881f441744bb29a6b63.tar.gz
rpg-60c15d7deb9c53bcb1cf7881f441744bb29a6b63.tar.bz2
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
Diffstat (limited to 'inc/html.php')
-rw-r--r--inc/html.php19
1 files changed, 9 insertions, 10 deletions
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 <andi@splitbrain.org>
* @author Harry Fuecks <hfuecks@gmail.com>
*/
-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 '<div class="search_result">';
- print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords);
+ print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$regex);
print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
- print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>';
+ print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
}
print '</div>';
flush();