boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[MOD] Improved Search

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
Cyberian75



Joined: 26 Sep 2002
Posts: 1283
Location: Oregon

PostPosted: Fri Nov 19, 2004 4:34 am    Post subject: [MOD] Improved Search Reply with quote

I've modified the search "engine" using the REGEXP operator; therefore, it now can search for exact matches which can lessen the workload of the database.

In the "blog.header.php" file, replace the "search" section with the following:
Code:

// if a search pattern is specified, load the posts that match
if (!empty($s)) {
   //gets rid of non-alphanumeric characters excluding spaces
   $s = eregi_replace("[^a-z0-9\ ]+", " ", $s);

   $s_array = explode(" ", trim($s));

   $search .= ' AND (';
   for ($i = 0; $i < count($s_array); $i++) {
      if ($i > 0) {
         $search .= ' '.$scond.' ';
      }
      if ($exact) {
         $search .= '(post_title REGEXP \'[[:<:]]'.$s_array[$i].'[[:>:]]\' OR post_content REGEXP \'[[:<:]]'.$s_array[$i].'[[:>:]]\')';
      }
      else {
         $search .= '(post_title LIKE \'%'.$s_array[$i].'%\' OR post_content LIKE \'%'.$s_array[$i].'%\')';
      }
   }
   $search .= ')';
}


And add the following to the search form:
Code:

<input type="checkbox" name="exact" value="1">exact word match<br>
<input type="radio" name="scond" value="AND" checked>AND
<input type="radio" name="scond" value="OR">OR


Lastly, if you want to highlight searched words, replace "the_content" function in the "b2template_functions.php" with the following:
Code:

function the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
    global $HTTP_GET_VARS, $s_array;
    $content = get_the_content($more_link_text,$stripteaser,$more_file);

    if(isset($HTTP_GET_VARS["s"]) && count($s_array) > 0) {
       $s = $HTTP_GET_VARS["s"];
       $exact = $HTTP_GET_VARS["exact"];

       foreach ($s_array AS $word) {
         if ($exact) {
            $search = "[[:<:]]".$word."[[:>:]]";
         } else {
            $search = $word;
         }
         $replace = "<span class = \"search\">".$word."</span>";
         $content = eregi_replace($search, $replace, $content);
       }
    }

   $content = convert_bbcode($content);
   $content = convert_gmcode($content);
   $content = convert_smilies($content);
   $content = convert_chars($content, 'html');
   $content = apply_filters('the_content', $content);
   echo $content;
}


EDIT: Seperate words with spaces. Smile
_________________
Michael P.



Last edited by Cyberian75 on Fri Nov 19, 2004 8:58 pm; edited 7 times in total
Back to top
View user's profile Send private message AIM Address
Sigg3



Joined: 03 Jul 2003
Posts: 898
Location: Oslo, Norway

PostPosted: Fri Nov 19, 2004 8:59 am    Post subject: Reply with quote

Is this like google's search, like you have to enclose it in quotation marks?

And: This is for the b2 form, right? Not the b2edit form? Both?
_________________
Sigg3.net - You know you're worth it! | b2 Cafelog Resource Center | Fight my BattleImp!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Cyberian75



Joined: 26 Sep 2002
Posts: 1283
Location: Oregon

PostPosted: Fri Nov 19, 2004 9:11 am    Post subject: Reply with quote

Sigg3 wrote:
Is this like google's search, like you have to enclose it in quotation marks??


You seperate words with spaces, not quotes.

Sigg3 wrote:
And: This is for the b2 form, right? Not the b2edit form? Both?


Both -- if you put that "exact word match" input tag in the edit page.

Smile
_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
Cyberian75



Joined: 26 Sep 2002
Posts: 1283
Location: Oregon

PostPosted: Fri Nov 19, 2004 7:06 pm    Post subject: Reply with quote

Bugs fixed. Smile
_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
Sigg3



Joined: 03 Jul 2003
Posts: 898
Location: Oslo, Norway

PostPosted: Mon Nov 22, 2004 10:37 am    Post subject: Reply with quote

Sexy.

I'll make a mirror to b2CRC.
_________________
Sigg3.net - You know you're worth it! | b2 Cafelog Resource Center | Fight my BattleImp!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
sh0ck



Joined: 02 May 2004
Posts: 52
Location: Norway

PostPosted: Thu Nov 25, 2004 9:26 am    Post subject: Reply with quote

Bug: The highlight feature breaks up links with a url matching the search term.
_________________
http://www.licklinux.com
Back to top
View user's profile Send private message Visit poster's website
Cyberian75



Joined: 26 Sep 2002
Posts: 1283
Location: Oregon

PostPosted: Thu Nov 25, 2004 6:44 pm    Post subject: Reply with quote

I know. You can use strip_tags function to strip HYML tags.
_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
sh0ck



Joined: 02 May 2004
Posts: 52
Location: Norway

PostPosted: Thu Dec 02, 2004 3:05 pm    Post subject: Reply with quote

how?
_________________
http://www.licklinux.com
Back to top
View user's profile Send private message Visit poster's website
Cyberian75



Joined: 26 Sep 2002
Posts: 1283
Location: Oregon

PostPosted: Thu Dec 02, 2004 5:26 pm    Post subject: Reply with quote

Code:
$content = strip_tags($content);

_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group