Mysql
 sql >> Database >  >> RDS >> Mysql

mysql ft_min_word_len change su Ubuntu non funziona

Sono riuscito a trovare il problema e la soluzione.

L'impostazione di ricerca del testo completo era buona poiché volevo cercare con alt east 2 parole e avevo ft_min_word_len = 2

Ora, mentre facevo più test, ho scoperto che cerca casualmente alcune parole di 2 caratteri e ne ignora altre.

Ecco un esempio

CREATE TABLE articles (
    id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    title VARCHAR(200),
    body TEXT,
    FULLTEXT (title,body)
);

INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');

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

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

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

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

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

Ma il seguente funziona

mysql> SELECT * FROM articles
    -> WHERE MATCH (title,body) AGAINST ('run');
+----+-------------------+-------------------------------------+
| id | title             | body                                |
+----+-------------------+-------------------------------------+
|  4 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... |
+----+-------------------+-------------------------------------+

Quindi è qualcos'altro e apparentemente ha trovato il ft_stopword_file che ha un elenco di parole e non fa nulla se viene eseguita una ricerca con una di esse.

L'elenco è qui http://dev.mysql.com /doc/refman/5.1/en/fulltext-stopwords.html

Quindi in questo caso per consentire qualsiasi ricerca di parole di lunghezza almeno 2 caratteri

  • Imposta ft_min_word_len su 2
  • Quindi nel file di configurazione mysql, per debian /etc/mysql/my.cnf aggiungi ft_stopword_file='path/to/stopword_file.txt'
  • Possiamo lasciare questo file vuoto se necessario.

Oh, un'altra cosa una volta eseguite le impostazioni di cui sopra, dobbiamo riavviare mysql e se cambiamo ft_min_word_len quindi dobbiamo ricostruire l'indice o riparare la tabella.