diff options
author | Andreas Gohr <andi@splitbrain.org> | 2008-03-10 22:49:39 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2008-03-10 22:49:39 +0100 |
commit | 546d3a9994d9f365f75e55f2f22601dc4941f5d5 (patch) | |
tree | a01027133c05b3e2fb39b081c814613a35909397 /inc/fulltext.php | |
parent | 68c26e6d2ab4feaf957863bcf5ba379036c014d3 (diff) | |
download | rpg-546d3a9994d9f365f75e55f2f22601dc4941f5d5.tar.gz rpg-546d3a9994d9f365f75e55f2f22601dc4941f5d5.tar.bz2 |
another change in highlight handling
Now higlighting phrases are passed as an array which then is quoted correctly
when used in a regexp. This should make phrase highlighting work completely
correct.
Please everyone test it.
darcs-hash:20080310214939-7ad00-1abefb02dde40edeead50b4fa5c866c46b95ca3a.gz
Diffstat (limited to 'inc/fulltext.php')
-rw-r--r-- | inc/fulltext.php | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php index a0be280bf..59053cb59 100644 --- a/inc/fulltext.php +++ b/inc/fulltext.php @@ -11,23 +11,20 @@ /** - * Wrapper around preg_quote adding the default delimiter - */ -function ft_preg_quote_cb($string){ - return preg_quote($string,'/'); -} - -/** * The fulltext search * * Returns a list of matching documents for the given query * */ -function ft_pageSearch($query,&$regex){ +function ft_pageSearch($query,&$highlight){ $q = ft_queryParser($query); + $highlight = array(); + // remember for hilighting later - $regex = str_replace('*','',join('|',$q['words'])); + foreach($q['words'] as $wrd){ + $highlight[] = str_replace('*','',$wrd); + } // lookup all words found in the query $words = array_merge($q['and'],$q['not']); @@ -76,12 +73,10 @@ function ft_pageSearch($query,&$regex){ if(!count($docs)) return array(); // handle phrases if(count($q['phrases'])){ - //build a regexp $q['phrases'] = array_map('utf8_strtolower',$q['phrases']); - $q['phrases'] = array_map('ft_preg_quote_cb',$q['phrases']); // use this for higlighting later: - if($regex !== '') $regex .= '|'; - $regex .= join('|',$q['phrases']); + $highlight = array_merge($highlight,$q['phrases']); + $q['phrases'] = array_map('preg_quote_cb',$q['phrases']); // check the source of all documents for the exact phrases foreach(array_keys($docs) as $id){ $text = utf8_strtolower(rawWiki($id)); @@ -250,13 +245,16 @@ function ft_pageLookup($id,$pageonly=true){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function ft_snippet($id,$re){ +function ft_snippet($id,$highlight){ $text = rawWiki($id); $match = array(); $snippets = array(); $utf8_offset = $offset = $end = 0; $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; |