1

I am using this to search my table:

  if ($querystring!=''){$query_cont .= " AND MATCH (headline) AGAINST ('$querystring')"; }

Thing is, in the 'headline' field I have a value of say 'BMW'. Then when I enter BMW in the search field, that is "$querystring = 'BMW'", no results are found.

I have set the index of the 'headline' field to 'fulltext', and I insert values to that table with the simple 'INSERT INTO' statement.

Please help me out with this one...

Let me know if you need more input!

3 Answers3

3

Change your ft_min_word_len to 3 or less and rebuild your index.

The words shorter than ft_min_word_len (which is 4 by default) do not get indexed.

Update:

It's considered a good habit to hotlink this obligatory XKCD comic to the questions containing the code like yours:

Community
  • 1
  • 1
Quassnoi
  • 413,100
  • 91
  • 616
  • 614
2

There are two things you have to know:

I suspect one of these things is preventing you from getting the results you expect.

Also please make sure your application is protected from Sql injections

TomHastjarjanto
  • 5,386
  • 1
  • 29
  • 41
2

MySQL's fulltext indexer ignores three-letter words by default. To get 3-letter words indexed you will need to change the ft_min_word_len config and re-index the columns (see this question for more; there are also many more stopwords than you might expect).

(You will also need to use mysql_real_escape_string or parameterised queries to stop your above code being an SQL injection vulnerability.)

Community
  • 1
  • 1
bobince
  • 528,062
  • 107
  • 651
  • 834