tags:

views:

95

answers:

2

I am a bit lost, this looks like some silly mistake - but I have no clue what that can be. Here is the test session:

mysql> drop table articles;
Query OK, 0 rows affected (0.02 sec)

mysql> CREATE TABLE articles (body TEXT, title VARCHAR(250), id INT NOT NULL auto_increment, PRIMARY KEY(id)) ENGINE = MYISAM;
Query OK, 0 rows affected (0.02 sec)

mysql> ALTER TABLE articles ADD FULLTEXT(body, title);
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> insert into articles(body) values ('Maya');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM articles  WHERE MATCH(title, body) AGAINST('Maya');
Empty set (0.00 sec)

mysql> select * from articles
    -> ;
+------+-------+----+
| body | title | id |
+------+-------+----+
| Maya | NULL  |  1 |
+------+-------+----+
1 row in set (0.00 sec)

This is on "mysqld Ver 5.1.37-1ubuntu5 for debian-linux-gnu on i486 ((Ubuntu))".

Here is the script for simple cut and paste (please try it and verify if it works on your system):

CREATE TABLE articles (body TEXT, title VARCHAR(250), id INT NOT NULL auto_increment, PRIMARY KEY(id)) ENGINE = MYISAM;
ALTER TABLE articles ADD FULLTEXT(body, title);
insert into articles(body) values ('Maya');
SELECT * FROM articles  WHERE MATCH(title, body) AGAINST('Maya');     
+1  A: 

Words in 50% of rows or more do not match. See mysql doc: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

David
+1  A: 

In MySQL there are three types of full-text searches:

  • boolean search
  • natural language search (used by default)
  • query expansion search

From MySQL manual entry:

A natural language search interprets the search string as a phrase in natural human language (a phrase in free text). There are no special operators. The stopword list applies. In addition, words that are present in 50% or more of the rows are considered common and do not match. Full-text searches are natural language searches if the IN NATURAL LANGUAGE MODE modifier is given or if no modifier is given.

For example, try to add two more records:

INSERT INTO articles(body) VALUES ('Some text'), ('Another text');

And run the same SELECT again - it will work.

As a workaround, you can use boolean mode, which doesn't have this "50%" rule:

SELECT * FROM articles  WHERE MATCH(title, body) AGAINST('Maya' IN BOOLEAN MODE);
Alexander Konstantinov