Forum Moderators: coopster

Message Too Old, No Replies

Php & MYSQL - Was SearchWord not found or too common

How to differentiate between a word not being found or being too common

         

thing3b

3:39 am on Dec 5, 2003 (gmt 0)

10+ Year Member



I am aware that when using the following sql in mysql, that it will not return results where the word is too short or too common:

SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('MySQL');

How would I go about telling if a word has been excluded because it is too common, or because it was not found?

coopster

1:32 pm on Dec 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, thing3b!

If you are on MySQL Version 4.0.1 you can use the IN BOOLEAN MODE modifier:


SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('+MySQL' IN BOOLEAN MODE);

A leading plus sign (+) indicates that this word must be present in every row returned. If you really need to search for what you believe may be common words it would be better to search using IN BOOLEAN MODE instead which does not observe the 50% threshold.

Now, you might be thinking, "Well, I can't be running a search over my entire database twice every time I get no result set returned! That would be way too intensive." True. Then you may want to offer an Advanced Search on your search page so your user can force a find on certain words. You know, an input field stating, "Search must return words:" and then you would prepend the plus sign to the text string entered by the user prior to running your database search.

Or, you may want to use a different approach altogether ;)

[edited by: jatar_k at 8:18 pm (utc) on Dec. 5, 2003]
[edit reason] changed wmv to w m w [/edit]