在 FTS 条件下,我会如何做类似的事情:
从学生中选择*,其中student_first_name LIKE“%”或student_last_name LIKE“%”...
我当前的查询是:
SELECT *
FROM
(SELECT cs.student_id,
cs.class_id,
s.student_id_no,
s.student_image,
s.student_first_name,
s.student_middle_name,
s.student_last_name,
s.student_year,
s.student_section,
s.student_email_address,
s.student_contact_no
FROM `class_students` cs
JOIN classes cls ON cs.class_id = cls.class_id
JOIN students s ON cs.student_id = s.student_id
WHERE cls.class_id = 1
AND cls.teacher_id = 1
AND is_enrolled = 1) AS s
WHERE MATCH(s.student_id_no, s.student_first_name, s.student_middle_name, s.student_last_name, s.student_email_address, s.student_contact_no) AGAINST ('*' IN BOOLEAN MODE)
但它给了我一个错误。
#1064 - 语法错误,意外的 $end,需要 FTS_TERM 或 FTS_NUMB 或“*”
我尝试删除IN BOOLEAN MODE
,它有效,但没有检索到任何记录。
如果搜索文本为空,我想检索所有记录。
AGAINST
子句中的 *
将与搜索字符串连接。
例如AGAINST('mysearch*' 在 bool 模式下)
。顺便说一句,我正在使用 PDO。
最佳答案
不要使用“%”或“*”来表示“未选择条件”。相反,修改查询以删除 WHERE...
。是的,这将需要应用程序代码,但它将避免您的问题并加快速度。
关于MySQL 全文搜索。获取所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40831047/