开发者

What is MySql equivalent of Sql Server Full Text Search?

开发者 https://www.devze.com 2022-12-30 10:36 出处:网络
I have worked with Sql Server in past and used it\'s very nice feature called Sql Full Text Search. Now i have to work with MySql. Can anybody tell me what is equivalent of Full Text Search in MySq开发

I have worked with Sql Server in past and used it's very nice feature called Sql Full Text Search. Now i have to work with MySql. Can anybody tell me what is equivalent of Full Text Search in MySq开发者_StackOverflowl? I am using free edition of MySql and not a commercial one. If not, then what else can we do to mimic Full Text Search and get over the limitations of LIKE operator?

Thanks in advance :)


See the documentation on the full-text search support in mysql:

http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html

You will want to apply full text indexes to columns in order to support full text search on those columns. Note that mysql only supports full-text indexing on MyISAM tables.

As an example, and just in case the above link goes dead at some point, see a full example, from the documentation:

mysql> CREATE TABLE articles (
    ->   id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    ->   title VARCHAR(200),
    ->   body TEXT,
    ->   FULLTEXT (title,body)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> 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 ...');
Query OK, 6 rows affected (0.00 sec)
Records: 6  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM articles
    -> WHERE MATCH (title,body)
    -> AGAINST ('database' IN NATURAL LANGUAGE MODE);
+----+-------------------+------------------------------------------+
| id | title             | body                                     |
+----+-------------------+------------------------------------------+
|  5 | MySQL vs. YourSQL | In the following database comparison ... |
|  1 | MySQL Tutorial    | DBMS stands for DataBase ...             |
+----+-------------------+------------------------------------------+

Ref http://dev.mysql.com/doc/refman/5.1/en/fulltext-natural-language.html


On MyISAM tables, MySQL supports FULLTEXT indexes:

CREATE TABLE mytable (id INT, caption TEXT, content TEXT, FULLTEXT KEY fx_mytable_caption_content (caption, content)) ENGINE=MyISAM;

SELECT  *
FROM    mytable
WHERE   MATCH(caption, content) AGAINST ('my search query')


You can create a Full-Text index over one or more columns. You can then use Full-Text search queries to query the table. See MySQL Full-Text index and MySQL Full-text Search functions.

A typical query looks like:

 SELECT * FROM books
 WHERE    MATCH (title, summary) AGAINST ('harry potter')
 ORDER BY MATCH (title, summary) AGAINST ('harry potter')
 LIMIT 0, 10
0

精彩评论

暂无评论...
验证码 换一张
取 消