john-formby Posted July 2, 2006 Share Posted July 2, 2006 Hi,I have a search script running on my website but it does not support boolean operators. I am finding that the results I am getting are very limited and many are being ignored as the words are not next to each other in the keyword row.I have tried to follow a couple of tutorials I found on the net but have been unsuccessful in implementing them. What I want is to be able to search through the keywords row in my database using boolean operators and display the results as my current search does, but in order of relevance.I would really appreciate some help with this as I am not having any success.Here is my search form:[code]<form name="search" method="post" action="srch.php"> <input class="form3" type="text" name="find" maxlength="255" /><input style="vertical-align: top;" class="submit" type="submit" name="search" value="Go" /><input type="hidden" name="searching" value="yes" /></form>[/code]Here is my search processing / results page[code]<?//This is only displayed if they have submitted the formif ($searching =="yes"){//If they did not enter a search term we give them an errorif ($find == ""){echo "<p>You forgot to enter a search term";exit;}// Otherwise we connect to our Databasemysql_connect("localhost", "USER", "PASS") or die(mysql_error());mysql_select_db("pagelinks") or die(mysql_error());// We preform a bit of filtering$find = strtoupper($find);$find = strip_tags($find);$find = trim ($find);//Now we search for our search term, in the field the user specified$data = mysql_query("SELECT * FROM links WHERE keywords LIKE '%$find%'");$num_per_page=10;$num=mysql_num_rows($data);$num_pages=ceil($num/$num_per_page);$pages=Array();for ($i=0;$i<$num_pages;$i++)$pages[]="<a href=\"?searching=yes&find=$find&start=".$i."\">[".($i+1)."] </a>";$pages=implode(" ",$pages); #Here's your string with the page links, output where everif ($start<0)$start=0;$x=($start*$num_per_page);$y=$num_per_page;$query="SELECT * FROM links WHERE keywords LIKE '%{$find}%' LIMIT {$x},{$y}";$data = mysql_query($query);//And we display the resultswhile($result = mysql_fetch_array( $data )){echo "<hr /><br />";if ($result['new_window'] == 1) {echo "<b><a href=\"".$result['url']."\" target=\"_new\">".$result['link_text']."</a></b>";} else {echo "<b><a href=\"".$result['url']."\">".$result['link_text']."</a></b>";}echo "<br />";echo $result['description'];echo "<br />";if ($result['new_window'] == 1) {echo "<a href=\"".$result['url']."\" target=\"_new\">".$result['url']."</a>";} else {echo "<a href=\"".$result['url']."\">".$result['url']."</a>";}echo "<br /><br />"; }echo "<hr /><br />";//This counts the number or results - and if there wasn't any it gives them a little message explaining that$anymatches=mysql_num_rows($data);if ($anymatches == 0){echo "Sorry, but we can not find an entry to match your query<br><br>";}//And we remind them what they searched forecho "<b>Searched For:</b> " .$find;}echo "<br /><br />";echo $pages;?>[/code]Thanks,John Quote Link to comment https://forums.phpfreaks.com/topic/13463-adding-boolean-search-to-existing-search-script/ Share on other sites More sharing options...
karthikeyan_coder Posted July 2, 2006 Share Posted July 2, 2006 hello, http://www.joedolson.com/Search-Engine-in-PHP-MySQL.php this will help you. Quote Link to comment https://forums.phpfreaks.com/topic/13463-adding-boolean-search-to-existing-search-script/#findComment-52062 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.