fooDigi Posted November 28, 2006 Share Posted November 28, 2006 my single word searches return near perfect results. the problem arises with multiple word searches. especially if one word exists in many places. say i search for...mozilla firefoxi will get results from all fields that contain the keywords mozilla OR firefox. and i only want to return the results that contain mozilla AND firefox. thx for any help. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 29, 2006 Share Posted November 29, 2006 What search? Where's the query? Quote Link to comment Share on other sites More sharing options...
fooDigi Posted November 29, 2006 Author Share Posted November 29, 2006 this is my querySELECT id FROM t_prods WHERE MATCH (name, brand_name, descr, sku, cat_name, series_name) AGAINST ('mozilla firefox') AND ORDER BY rank DESC LIMIT 0, 12 Quote Link to comment Share on other sites More sharing options...
watts Posted December 1, 2006 Share Posted December 1, 2006 My recommendation is to check out the "mysql full-text searching with php" tutorial. I used this but removed the choice between "normal" and "boolean mode" so it was only boolean. The default is to use normal mode where it searches for "any words" as opposed to "all words." If you use a boolean mode query you can then force it to look for all words by using a little str_replace to add boolean operators to the search string and specifying boolean mode in your query. I did this and it worked like a charm (on my local server). Unfortunately it seems to only search for the first word on my remote server but that's another problem that has yet to be explained. This is what I did:[code]//ADD BOOLEAN OPERATORS//CHECK IF IT'S FIRST SEARCH PAGE OR IF BOOLEAN OPERATORS HAVE ALREADY BEEN ADDEDif (isset($_GET['words'])){ $words=$_GET['words']; // the $words variable was defined in the search form (see tutorial) $newWords = str_replace(' ','+',$words); $newWords = str_replace($newWords,'+'.$newWords,$newWords);} elseif (isset($_GET['newWords'])) { $newWords = $_GET['newWords'];}$searchstring = mysql_escape_string($newWords); $sqlCount = "SELECT imgID, imgURL, imgThbURL, imgLabel, imgCaption, imgTitle, imgTitleMeta, imgDescription, MATCH(imgTitle, imgCaption, imgDescription) AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM images WHERE MATCH(imgTitle, imgCaption, imgDescription) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC"; $result = mysql_query($sqlCount) or die (mysql_error('There were no items to match your search, please use exact words.')); $searchRows = mysql_num_rows($result);[/code]hope that helps! Quote Link to comment 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.