Jump to content

full text searches


fooDigi

Recommended Posts

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 firefox

i 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.
Link to comment
Share on other sites

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 ADDED
if (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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.