简单的 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);