簡單的 BOOLEAN 搜尋
SET @searchTerm= 'Database Programming -Java';
SELECT MATCH (Title) AGAINST (@searchTerm IN BOOLEAN MODE) Score,
ISBN, Author, Title
FROM book
WHERE MATCH (Title) AGAINST (@searchTerm IN BOOLEAN MODE)
ORDER BY MATCH (Title) AGAINST (@searchTerm IN BOOLEAN MODE) DESC;
給定一個名為 book
的表,其名稱為 ISBN
,Title
和 Author
,這將搜尋標題中包含'Database'
和'Programming'
字樣的書籍,但不會搜尋單詞'Java'
。
為此,必須在 Title 列上提供全文索引:
ALTER TABLE book ADD FULLTEXT INDEX Fulltext_title_index (Title);