簡單的 FULLTEXT 搜尋

    SET @searchTerm= 'Database Programming';
 SELECT MATCH (Title) AGAINST (@searchTerm IN NATURAL LANGUAGE MODE) Score,
        ISBN, Author, Title 
   FROM book
  WHERE MATCH (Title) AGAINST (@searchTerm IN NATURAL LANGUAGE MODE)
  ORDER BY MATCH (Title) AGAINST (@searchTerm IN NATURAL LANGUAGE MODE) DESC;

給定一個名為 book 的表,其中包含名為 ISBN,‘Title’和’Author’的列,它會查詢與'Database Programming'匹配的書籍。它首先顯示最佳匹配。

為此,必須提供 Title 列上的全文索引:

ALTER TABLE book ADD FULLTEXT INDEX Fulltext_title_index (Title);