tags:

views:

15

answers:

1

I am trying to follow: http://dev.mysql.com/doc/refman/4.1/en/fulltext-natural-language.html

in an attempt to improve search queries, both in speed and the ability to order by score.

However when using this SQL ("skitt" is used as a search term just so I can try match Skittles).

SELECT 
    id,name,description,price,image, 
    MATCH (name,description) 
    AGAINST ('skitt') 
    AS score 
FROM 
    products 
WHERE 
    MATCH (name,description)
AGAINST ('skitt')

it returns 0 results. I am trying to find out why, I think I might have set my index's up wrong I'm not sure, this is the first time I've strayed away from LIKE!

Here is my table structure and data:

alt text

Thank you!

+1  A: 

By default certain words are excluded from the search. These are called stopwords. "a" is an example of a stopword. You could test your query by using a word that is not a stopword, or you can disable stopwords:

If you want to also match prefixes use the truncation operator in boolean mode:

*

The asterisk serves as the truncation (or wildcard) operator. Unlike the other operators, it should be appended to the word to be affected. Words match if they begin with the word preceding the * operator.

Mark Byers
even if I replace "a" with "skitt" (to match Skittles) it still returns 0
Alex Crooks
@Alex Crooks: Why would you expect "skitt" to match "Skittles"? It's not the same word.
Mark Byers
Ah OK so I'm being a complete idiot, I thought it did partial word matches too, if I change it to "skittles" it works, which is what I want anyway I guess. Thank you and sorry for wasting your time :)
Alex Crooks
@Alex Crooks: I added some information about the truncation operator which you might find interesting.
Mark Byers
Ah thank you, the * boolean mode works very well in my original question, thank you very much for the help!
Alex Crooks
@Alex Crooks: You're welcome.
Mark Byers
@Mark Byers in boolean mode the score is always returned as 1, whereas before it was more accurate to several decimal places (eg. 0.5332221) and I could order by relevance in my search results. Is this still possible in boolean mode?
Alex Crooks
@Alex Crooks: No, but you can look at Richard's comment on this page: http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html starting 'To enhance sorting of the results in boolean mode you can do the following:'
Mark Byers