I know there’s a wizard out there who can answer this …
I have a PHP / MySQL database that lists over 500 wines. Using a form, web visitors can search the database by wine name, country, vintage, etc.
I have tested two (2) different queries.
The one I want to use refuses to return a country specific search for USA, but has NO problem with Spain, Australia, Italy, Canada or Chile (or even United States – which I tested) .
USA only shows up when the user enters a wine name or vintage, etc., that happens to match a USA product. Otherwise, it treats USA like it doesn’t exist.
The other code (bottom block) returns all USA searches, but does not search across multiple columns / terms, which I need.
-
This code WILL NOT find a country-specific search for USA
$cob=mysql_real_escape_string($_POST['user-entry']); // remove the line below to prevent searching multiple terms $cob = '+' . str_replace(' ',' +',$cob); $sql = sprintf ( "SELECT CSPC, Country, Producer, Wine, Year, Price, MATCH ( CSPC, Country, Producer, Wine, Year ) AGAINST ( '&s' IN BOOLEAN MODE ) FROM winecellar WHERE MATCH ( CSPC, Country, Producer, Wine, Year ) AGAINST ( '%s' IN BOOLEAN MODE )", $cob, $cob ) . $pricerange; -
This code WILL find a country-specific search for USA
$cob=mysql_real_escape_string($_POST['user-entry']); $sql="SELECT ID, CSPC, Country, Producer, Wine, Year, Price FROM winecellar WHERE ( CSPC LIKE '%" . $cob . "%' OR Country LIKE '%" . $cob ."%' OR Producer LIKE '%" . $cob ."%' OR Wine LIKE '%" . $cob ."%' OR Year LIKE '%" . $cob ."%' )" . $pricerange;- MySQL Server version: 5.1.65-cll
- Country = varchar (20)
- Country = NULL No
- Full-Text Index: Country, Producer, Wine, Year
So my question is, what is preventing the multi-term code (in the top block) from recognizing USA as a valid query?
Any help would be greatly appreciated, thanks guys.
Chris
You’re using a
FULLTEXTindex. The default minimum word length is 4. Three letter words are ignored. Here is the reference for changing defaults.