我有一个包含书籍章节的MySQL表。全文MySQL搜索 - 返回片段
Table: book_chapter
--------------------------
| id | book_id | content |
--------------------------
我目前能够使用全文搜索这样的搜索内容:
SELECT * FROM book_chapter WHERE book_chapter.book_id="2" AND
MATCH (book_chapter.content) AGAINST ("unicorn hair" IN BOOLEAN MODE)
不过,我想知道是否有可能搜索的内容,并已返回的结果30个字符的片段,让用户可以感受到这个要点。因此,例如,如果我搜索“独角兽毛”,我想有这样的结果:
-------------------------------------------------
| id | book_id | content |
-------------------------------------------------
| 15 | 2 | it isn't unicorn hair. You kno |
-------------------------------------------------
| 15 | 2 | chup and unicorn hair in soup |
-------------------------------------------------
| 27 | 2 | , should unicorn hair be used |
-------------------------------------------------
| 31 | 2 | eware of unicorn hair for bal |
注意,有来自同一记录两个结果。这可能吗?
也可以使用GREATEST防止欠载。 –
这只适用于确切的短语。那么两个词分开的时候呢? MATCH .. AGAINST也会返回这些。 – jor