Jump to content

boolean full-text search not working right


watts

Recommended Posts

I've just uploaded my site from my local server, where everything worked fine, to a new remote server and my full-text search is no longer working properly.  It's not using boolean mode and it's only returning results for the first word in the search string so if the search string is "abstract vertical" it returns the same number of results as "abstract"

Here's code for the search:

[code]
function searchForm()
{
//reusable form

//variable setup for the form
$searchwords = (isset($GET['newWords']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) :'');

echo "<div id='searchField'>\n";
echo "<form method='get' action='".$_SERVER['PHP_SELF']."'>\n";
echo "<input type='hidden' name='cmd' value='search' />\n";
echo "Search for: <input type='text' name='words' value='".$searchwords."' />&nbsp;\n";
echo "<input type='submit' value='SEARCH' />\n";
echo "</form>\n";
echo "<p>Enter your keywords separated by spaces.  The search will only return exact matches (no partial word matches) for all words present and display the thumbnails.</p>\n";
echo "</div>\n"; //END DIV FOR SEARCHFIELD
}

//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'];
  $newWords = str_replace(' ','+',$words);
  $newWords = str_replace($newWords,'+'.$newWords,$newWords);
} elseif (isset($_GET['newWords'])) {
  $newWords = $_GET['newWords'];
}


// CREATE THE NAVIGATION SWITCH
$cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : '');

switch($cmd)
{
  default;
    echo "<h2>Search Images</h2>";
    searchForm();

  break;
  case "search";
    searchForm();

//OPEN DIV FOR DISPLAYED RESULTS

    echo "<div id=searchResults>\n";

    $searchstring = mysql_escape_string($newWords);


//SET LIMIT AND DETERMINE NUMBER OF IMAGES
$limit = 20;
$perRow = 4;

    $limitValue=($page*$limit)-($limit);
    $table_row=1;

        $sql = "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 LIMIT $limitValue, $limit";

    $result = mysql_query($sql) or die (mysql_error('Could not connect to database'));
    $countImg = mysql_num_rows($result);

[/code]

This works fine on my local server which is running mysql 5 but it doesn't work properly on the remote server which is running mysql 4.1.10.
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.