1

I've hit a snag in pset8 rather early on. My code, for some reason, does not seem to like admin_code1 in search.php. Here's the relevant code so far:

if(strstr($loc, ","))
{
    if(strstr($loc, " "))
    {
        $geo = explode(", ", $loc);
        $places = query("SELECT * FROM places WHERE MATCH (postal_code,place_name,admin_name1,admin_code1) AGAINST (? IN BOOLEAN MODE)", "+".$geo[0]." +".$geo[1]); 
    }
    else
    {
        $geo = explode(",", $loc);
        $places = query("SELECT * FROM places WHERE MATCH (postal_code,place_name,admin_name1,admin_code1) AGAINST (? IN BOOLEAN MODE)", "+".$geo[0]." +".$geo[1]); 
    }
}
else if(strpos($loc, " "))
{
    $geo = explode(" ", $loc);
    $places = query("SELECT * FROM places WHERE MATCH (postal_code,place_name,admin_name1,admin_code1) AGAINST (? IN BOOLEAN MODE)", "+".$geo[0]." +".$geo[1]); 
}
else
{
    $geo = $loc;

    $places = query("SELECT * FROM places WHERE MATCH (postal_code,place_name,admin_name1,admin_code1) AGAINST (? IN BOOLEAN MODE)", $geo); 
}

I know there's still a lot to do, but I can't seem to get it to recognize when I pass it, for example MA. It accepts Massachusetts with no problem, but any of the state abbreviations don't work at all. I copied the code into a command-line php program just to see if it would spit out +Cambridge +MA or anything else like that, and it does with no problem. I checked my SQL database using SELECT * FROM places WHERE admin_code1 = "MA". Again, no issues there. Even if I only pass it MA, I'm given an empty JSON array.

Am I missing something obvious?

Thanks in advance!

1

You are missing something, but it is not obvious. There is a mysql setting called ft_min_word_len (the minimum length of words to be indexed), which defaults to 4. MySQL doc is here. See this post for details on how to change it. (Of course you would want the minimum to be 2). Also from MySQL doc:

Note
FULLTEXT indexes on MyISAM tables must be rebuilt after changing this variable.
Use REPAIR TABLE tbl_name QUICK.

All other things being equal, this should fix your problem.

| improve this answer | |
  • That did it! Thanks!! – Chris Dec 6 '15 at 6:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .