FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


advanced search engine





alalex
Hi guys, I am trying to build some kind of "advanced" search engine for my website. Not like google of course, but just advanced enough to have some of google's features.
What I mean by this is I want to enable multiple keyword search, and also if possible to display results based on appearances. And another thing I was looking forward was the typical "Myabe you meant to say..."

Ok, so my actual code is this:
Code:
$suser = strtolower(trim($_GET['suser']));
   if(!get_magic_quotes_gpc()) {
       $suser = addslashes($suser);
   }
   $keyword = $suser;
   if($keyword == '%'){
       echo 'Falló la búsqueda...';
      return;
   }
   $search = preg_replace('/\s+/', ' ', $keyword);
   $keywords = explode(" ", $search);
   $keywords = array_diff($keywords, array(""));
   //Set the MySQL query
   if ($search == NULL or $search == '%'){
   } else {
      global $database;
      for ($i=0; $i<count($keywords); $i++) {
         $query = "SELECT * FROM `users` " .
         'WHERE `username` LIKE CONVERT(_utf8 \'%'.$keywords[$i].'%\' USING latin1) COLLATE latin1_spanish_ci'.
         ' OR `email` LIKE CONVERT(_utf8 \'%'.$keywords[$i].'%\' USING latin1) COLLATE latin1_spanish_ci' .
         ' OR `name` LIKE CONVERT(_utf8 \'%'.$keywords[$i].'%\' USING latin1) COLLATE latin1_spanish_ci' .
         ' OR `last_name` LIKE CONVERT(_utf8 \'%'.$keywords[$i].'%\' USING latin1) COLLATE latin1_spanish_ci' .
         ' ORDER BY `username`';
      }
}

This code works perfectly, so dont worry if you see something missing, I just copied and pasted it and I may have left out some } or whatever...
And after all this I run the query and get the result, and I display the results.

If anyone knows how to add to this, or modify to make it faster/better please feel free to post! Wink
Thanks alot

EDIT:
All the latin1 and COLLATE and stuff dont worry about it, is just that my site is in spanish and I dont want mysql filled with errors because of special characters... Confused
alalex
I was googling around for ways to improve it, and I came across the MATCH()... AGAINST
I'm not sure how it works, but looks like it is exactly what I need.. But i dont know how to use it!

Well, still, any comments really appreciated!
manav
i guess it will be better to use a free intra site search engine generator to generate some code for ur site and then perfecting that code to get better results....

there r many search engine generators.. cn google them...
Related topics
Yahoo developing an audio search engine!
Basic Search Engine Optimizing
Make search engine With PHP and mySQL, for your site
Search Engine Scrips
submit to search Engine
What Did We Learn From The Great Search Engine Experiment
Google's Search Engine Performance Drop
Search Engine optimisation tutorial.
Integrate Personal search engine
Is Google really a great search engine?
role on advertisements on the search engine rankings
search engine?
Search Engine Optimization some Mistakes
Search Engine Hits
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.