Search Hi-Lite Plugin

19th Jan 2006 stk

Phoenix (v1.7 CVS+)

The "Search Hi-lite" plug-in was originally designed and tested on on a "Phoenix" CVS v1.7 b2evolution install. It is anticipated that it will work with any newer installation, but no other versions are currently available to test. (Hover over the green "information" button, on the left, for information regarding using this plugin with v1.6 "Alpha").

Two Steps to a Better Search

  1. Download and Install the Search Plugin: This is the easy part, because plugins are a one-click operation. Just download the following file:

    AstonishMe! Search Plugin

    Move the downloaded file to your /plugins folder and make sure that the name of the file is _am_search.plugin.php.

    To install, log into your b2evolution administration back office. There, go to SETTINGS -> PLUGINS and you should see "AM! Search Hi-lite" on the list of available plug-ins. Just click the "install" option and BOOM, it's installed. How easy is that?

  2. Modify Your Skin: You will need to edit the main template file (i.e., _main.php) for each skin in which you want to utilize highlighted search. The modifications are not difficult to do and consist of 4 separate parts, shown in the two code blocks below.

    Yabbio likes his porridge cold.

    The modifications call the new search plugin and allow for a more accurate search, by fixing the default behavior of the b2evolution search.

?php // Start AM! Search Hack (Part 1 of 4)
      // Put above - "if( isset($MainList) ) $MainList->display_if_empty();" 
			//
$amSrch_cnt=0;
?>    <!-- End AM! Search Hack (Part 1 of 4) -->

<?php
// ------------------------------------ START OF POSTS ----------------------------------------
if( isset($MainList) ) $MainList->display_if_empty(); // Display message if no post
if( isset($MainList) ) while( $Item = $MainList->get_item() )
{ 
?>

<?php // Start AM! Search Hack (Part 2 of 4) 
      // Put just below:
      // "if( isset($MainList) ) while( $Item = $MainList->get_item() )
      //  { " 
			//
$am_search_flag = true;
$am_search = $Plugins->get_by_name( 'am_search_plugin' );
if( isset( $s ) and $s ) $Plugins->call_method( $am_search->ID, 'CorrectSearch');
  if ( isset( $Item ) )
    { $amSrch_cnt++;
                       // End AM! Search Hack (Part 2 of 4) ?>

PHP:

<?php // Start AM! Search Hack (Part 3 of 4) 
      // (A close curly brace, before "end of posts" closing curly brace)
            //
    
    //<!-- End AM! Search Hack (Part 3 of 4) ?>    
 
<span style="color:#aaa"><?php</span>
    <span style="color:red"><strong>}</strong></span><span style="color:#aaa"// ---------------------------------- END OF POSTS ------------------------------------</span>
<span style="color:#aaa">?></span>
    
<?php // Start AM! Search Hack (Part 4 of 4) 
      // (Place after the "end of posts" closing curly brace)
            //
  if ( isset( $MainList ) and !$amSrch_cnt & isset( $am_search_flag ) ) 
  echo T_('Sorry, those keywords weren&#039;t found.').'<br /><br /><small><ins><div style="display:table;border:1px solid black;width:60%;text-align:center;margin:auto;padding:10px 0;background:#ffa;color:#000">'.T_('Get your').'<a class="ext" href="http://astonishme.co.uk" title="'.T_(' Offsite link to Plugin Article &#40;Info, Demo &amp; Download&#41; ').'">Astonish Me! "'.T_('Search Hi-Lite').'" '.T_('Plug-in').'</a>'.T_('Today').'.<br />Improve your blog&#039;s search capability!</div></ins></small><br /><br /><br />';
                 //End AM! Search Hack (Part 4 of 4) ?>
Contents
  1. Introduction & Comparison
  2. Install Instructions
  3. Usage & Considerations
  4. FAQs & Something Else
 
 
 
 

12 comments

Comment from: Danny
Any chance this plugin could include comment searching? A lot of people have asked for that.
 
02/04/06 @ 16:51
Comment from: stk
And retain highlighting for multiple pages? (Hey ... why not ask?)
 
02/05/06 @ 02:47
Comment from: stk
Note to self ... just noticed returns for the all_blog in the [css] [/css] section ... I remember that we were going to find (had?) a user-defined array where we could strip tags (and everything in between) to keep OUT of the search text??

JUst need to figure out where and HOW.

PS ... I added "special" blog to Randsco. (With a little help from my friends).

Steps (for an aging mind) ...

1) Make blog ... stub file about.php
2) For search to span ALL blogs ... add to search form
3) Make sure ALL blog has right skin :|
4) search returns now span more than one skin
5) set up skin for this new blog (title and such)
6) KEY (for me anyway) ... did not WANT sidebar elements to CHANGE (archives/categories always the same ... i.e., main blog)
7) use dirty little trick from multiblogs.php (to set $blog to be one I want ... right before archives ... and reset after categories.
8) Works ... BUT ... the links are a tad rough ... cats go to:

http://randsco.com/index.php/all.php?cat=33

(instead of)

http://randsco.com/index.php?cat=33

... same with archives ...
9) AND the "All Entries" (the all option in cats) ... goes to the http://randsco.com/all.php (which is totally wrong and had to hard-code the cats_plugin file.

Wonder if there is a better way to get the all out of the links after a search throws one into the all blog?
 
03/02/06 @ 23:20
Comment from: MrDav
I was going to ask for comment searching too, but Danny beat me.
 
09/23/06 @ 19:57
I tried setting this on b2evo 1.8.5 but it didn't work for me. Have the instructions been updated for 1.8.5?

Thanks.

Edgar
 
01/01/07 @ 22:15
I'm afraid we haven't got round to converting this to 1.8.6 yet.

As an aside you should upgrade to 1.8.6, see this security alert

¥
 
01/02/07 @ 11:11
Comment from: Michael Watson
Has anyone been able to successfully install this plugin in b24evolution 1.9.2 as yet? I am able to run the install script without problems, but when I try to make the necessary changes to ../skins/custom/_main.php, it causes my blog to break, displaying only a blank page. I've looked pretty carefully to be sure I'm putting the changes in the right place, paying careful attention to closing braces & such. I'm wondering whether there's been a change in 1.9.2 that just makes it incompatible with am search hi-lite. By remming out various lines, I found that the problem seems to involve a line in the 2nd code block:

$am_search = $Plugins->get_by_name( 'am_search_plugin' );

 
01/31/07 @ 17:37
You might like to test out the beta 1.9.2 version which you can find here

You'll need to undo all the skin changes you made for this version as the new version doesn't require them ;)

If you find any problems with it then please leave a comment on that thread

¥
 
02/01/07 @ 08:11
Comment from: Michael Watson
Thanks for the suggestion. I was able to install the beta 1.9.2 version without difficulty. I've managed to get it working after a fashion, but I think I'm missing an important detail on installation.

I restored the original _main.php before installing the plugin. After I installed the plugin, my blog displayed properly, and the search function did work, but search results still weren't highlighted.

I looked at the html source and noted that search words were enclosed in SPAN tags with class search_hit0, so I thought I'd missed instructions somewhere to modify the skin's stylesheet. I manually added a class of .search_hit0 with a background-color attribute to my skin's stylesheet. This did indeed make the search results highlight properly. But I'm not sure what other classes I might need to add. On examining _am_search.plugin.php, it looks like search results are tagged search_hit0, search_hit1, search_hit2 based on incrementing values of a variable etc. But I'm not sure how high the values of that variable might go, so I'm not sure what classes I need to create and assign a background-color attribute.

Did I miss documentation somewhere concerning required edits to the stylesheet?

Many thanks for your help on this, it's looking very promising!
 
02/01/07 @ 17:56
Hi Michael,
The most important thing you missed about the instructions is that they were written by an absent minded blonde :P

As you found out the plugin wraps the search terms in a span with a classname of search_hit# where # is a pointer for the keyword found ( 2 keywords == search_hit0 && search_hit1 ), so you need to add classes to your style sheet to cover what you think will be the maximum number of keywords that somebody might search for ( *note to self* add some sort of cap and re-use the classes for > ## keywords).

I'll upgrade the plugin to include some default styles so that it works straight out of the box, I warn you though I tend to pick gaudy colours ;)

¥

*edit*
The plugin has been upgraded (and the zip file on the original link has been updated). The keyword classes have been limited to 0 -> 6 ( after that they're re-used ).

Let me know if you have any further problems with it.
 
02/02/07 @ 08:04
Comment from: sam2kb
Hi

Download link is dead. ;)

http://astonishme.co.uk/media/chat/dl/_am_search.plugin.php
 
02/11/08 @ 06:46
Ahh bugger, yet another broken link :-S

It's a good job really because we've done a complete recode for the 2.x series and need to update this post badly. I should get round to it in the next couple of days and I'll also add it to B.O.P.I.T so you'll know when it's updated ;)

¥
 
02/11/08 @ 13:31

Comments are closed for this post.

 

B.O.P.I.T