RE: searchengine input split

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



here is something similar. you should be able to adapt this easily

<?

//Google like search engine for your site,
//the $not_search_word array can be added to,
//to limit the results even further for those
//common words that should not be searched for.


foreach ($searchwords as $word) {
/*
For each word, include any records that have all of the words in the field anywhere,
but the problem is, after this how to tell sql to combine all of these (if there were
several words) and then insert them into sql statement.
*/


$not_search_word = array('if', 'for', 'in', 'on','and','with'); //add words as needed

echo "Only relevant search terms are searched. They are shown in bold below.
Words like in, for etc are not searched on as they are common words
and will skew results";


   echo "Search results for :";

   if (!in_array($word,$not_search_word)){  //relevant search term only
       echo " <b>$word</b> ";
       if ($x==1){
         $sql.= " fieldname like '%$word%' ";
         $x++; //increase the counter
       }else
         $sql .= "OR fieldname like '%$word%' ";
       }//close if then
   }else{
       echo $word;
   }//end if
}//close foreach loop

//do the query
//report the results
?>


bastien


From: "Murat BIYIKLI" <admin@xxxxxxxxxxxxxxxxxxxx>
To: php-db@xxxxxxxxxxxxx
Subject:  searchengine input split
Date: Thu, 30 Sep 2004 13:59:59 +0300

I need to split the keyword on search input and generate an sql query,
for ex: the input value is: europe+america,asia
so I want to generate an sql like this:
SELECT * FROM mytable WHERE message LIKE %europe% AND message LIKE %america%
OR message LIKE %asia%


The + (plus) means AND and , (comma) means OR. Also I need to control input
variables to prevent error on sql query forexample an input value like:
,,,europe+america,+asia+    should not generate an error.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


_________________________________________________________________
MSN® Calendar keeps you organized and takes the effort out of scheduling get-togethers. http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux