You are invited to Log in or Register a free Frihost Account!

Creating a good search engine

Hi, I am going to build an search engine which perfoming database queries for my semester project in university.. Does anyone know how to build an advance search engine which has the option such as filter, search through category and keyword. I am using PHP and MySQL.
well building the search engine has some easy parts which you can find over the internet and one difficult thing, which you need to develop yourself.

The difficult thing you are going to have to develop is a way of sorting your search results by relevance. Creating a good algorithm to do that is very very hard, and it will take you long...

The easy part is the sql queries and everything... Here I'll post you an example of a "medium level" search engine I did for a web page, based on keyword search...
So how it works is I have a mysql table with all "indexed" stuff I have, which is the one I will be querying. In there there is a column with "keywords", which are generated by a python robot from crawled text...
As I said, it is not the most efficient way to do it, but I didnt need any sort of complex search engine, so it worked for me. You can probably improve it if you need to...
           $string= strtolower(trim($_GET['string']));
      if(!get_magic_quotes_gpc()) {
         $string= addslashes($string);
      $keyword = $suser;
      if($keyword == '%'){
      echo 'Error occurred';
      return false;
      $search = preg_replace('/\s+/', ' ', $keyword);
      $keywords = explode(" ", $search);
      $keywords = array_diff($keywords, array(""));
           //Set the MySQL query
      if ($search == NULL or $search == '%'){
               echo 'Error occurred';
               return false;
      } else {
         for ($i=0; $i<count($keywords); $i++) {
               $query[$i] = "SELECT * FROM `indexed` WHERE `keyword` LIKE \'%'.$keywords[$i].'%\' ORDER BY `title` LIMIT 0,10';
      for ($i=0; $i<count($query); $i++) {
         $result = mysql_query($query[$i]);
                        $num_rows = mysql_numrows($result);
                        if(!$num_rows || $num_rows < 1){
                                echo 'Error occurred';
                                return false;
                        echo 'Found '.$num_rows.' matches';
                        echo '<p class='search_result'>'.mysql_result($result,$i,"title").'</p>'; //display title of
                } //close for
               } //close if

If you dont underdstand any part of the code ask me, Ive tested it and it workds pretty good. On multiple search terms it only displays the titles with all the keywords, that can be corrected but I dont have the time or the need to do it, so I'll leave it up to you...

If you improve the search code and want to share it here I would be more than glad Wink

Hope you like it
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

© 2005-2011 Frihost, forums powered by phpBB.