|
Cookbook /
SearchHighLightSummary: Highlight keywords when coming from a search page
Version: 1.16 - 10 July 2005
Prerequisites: Last tested with PmWiki version: 2.0.10
Status:
Maintainer:
Categories: Searching
GoalHighlight keywords when coming from a search page, PmWiki, Google, etc. SolutionBased on a nice bit of code found on the internet: http://suda.co.uk/projects/SEHL/ The searchhightlight code has been reworked. Since the code is quite different I removed the old discussion comments and bugs. DiscussionUsageDownload : searchhighlight_1_16.phpΔ Install the script in your local or cookbook directory and include it from the farmconfig.php or config.php. There are three ways to use the script. The script depends on the refer-header. If for any reason ( firewall, plug-in,configuration) the refer is not send. searchhighlight will hightlight nothing, zip, nada higtlight everythingSearch items found in the entire <body> section are highlighted $EnableShel = 1;
$ShelPageTextOnly = 0;
Highlight PageText onlyOnly keywords in the PageText section get highlighted. $EnableShel = 1;
$ShelPageTextOnly = 1;
Custom$EnableShel = 0;
$ShelPageTextOnly = 0;
Use <!--function:sehl_start--> and <!--function:sehl_stop--> in your template to select part to highlight. Example below highlights PageText and RightBar but ommits SideBar <!-- function:sehl_start --> ColorsThe colors for highlighting are defined in EnableIMSCaching and other cachingI case the visitor return to a page using a query (s)he should not get a cached page but a new one. The script will turn off IMSCaching in case there is a query string in the refer, ensure the flag is not set on after calling the searchhightlight script. History
Comments & Bugs
Call to undefined function: ob_flush_contents() in \cookbook\searchhighlight.php on line 134
I had two problems with the existing code:
Slash Bug Fix: When searching for anything containing a forward slash(/), SearchHighLight will trip a preg_replace error on line 307. The line should be as follows: $holder = preg_replace('/(.*?)('.preg_quote($q, '/' ).')(.*?)/iu',"\$1<span class=\"hl$colour\">\$2</span>\$3",' '.$tag_matches[3][$i].' '); The seccond paramater to preg_quote() is important. Without it, the forward slash in the search is interpreted as the delimiter to the expression. ~InternetAdvisor ExampleTry a google on kaasfondue+kruiden , my site (brambring.nl) should be in the top: http://www.google.com&q=kaasfondue+kruiden(approve links)
Or try a wiki search on my page directly: Contributors
|