如何设置全文索引
我想要一些关于如何在 phpMyAdmin 中设置全文索引的指导,如下所示:
表
universities:
id
name
programs:
id
name
university_id
courses:
id
name
program_id
students:
id
name
course_id
搜索功能 用户只需要搜索学生,但我想创建与students.course_id等匹配的students.name和courses.name的全文,以便学生姓名,课程名称(学生参加),课程名称(课程所在)和大学名称(课程所属)均可搜索。
询问 如果我按照上面的方式构建它,将创建全文,以便可以像标准一样进行搜索,例如使用 PDO:
$STH = $DBH->prepare('SELECT * FROM students WHERE MATCH(fulltext) AGAINST(:query IN BOOLEAN MODE));
$STH->bindParam(':query', $query);
或者如何在 php 中查找 pdo 查询?
这也是一个繁重的搜索功能吗?
大约数量:5 所大学、100 个项目、1 000 门课程和 20 000 名学生。
I would like some guidance in how to set the full text index in phpMyAdmin like following:
Tables
universities:
id
name
programs:
id
name
university_id
courses:
id
name
program_id
students:
id
name
course_id
Search function
User needs only to serach for students but I would like to create a full text of the students.name and the courses.name that match the students.course_id and so on so that the students name, course name (student participate in), program name (course is given in) and university name (program belongs to) is all searchable.
Query
If I construct it as above will the full text be created so that it is searchable like standard, e.g. with PDO:
$STH = $DBH->prepare('SELECT * FROM students WHERE MATCH(fulltext) AGAINST(:query IN BOOLEAN MODE));
$STH->bindParam(':query', $query);
or how would the pdo query in look in php?
Also will this be a heavy search function?
Approx numbers: 5 universities, 100 programs 1 000 courses and 20 000 students.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是
FULLTEXT
索引的工作原理。FULLTEXT
索引必须位于 MyISAM 表中的单个文本 (CHAR
/VARCHAR
/TEXT
) 列上,并允许搜索匹配该列内容中的单词。例如,您可以在课程目录中使用 FULLTEXT 索引,以允许用户在课程描述中搜索文本。在您的情况下,您可能想要做的是为每个
students.name
、courses.name
、programs.name
和universities.name
,然后对每个表执行一个查询并自行合并结果。 (例如,您可能必须以不同于匹配大学的方式显示匹配学生的结果。)将现有的student.name
字段分解为单独的名字和姓氏可能会有所帮助。 -name 字段,因为这将允许您分别搜索这两个字段。That's not how
FULLTEXT
indexes work. AFULLTEXT
index must be on a single textual (CHAR
/VARCHAR
/TEXT
) column in a MyISAM table, and allow searches to match words within the contents of that column. For instance, you might use a FULLTEXT index in a course catalog to allow users to search for text within the course descriptions.In your case, what you probably want to do is to create one "normal" (non-fulltext) index on each of
students.name
,courses.name
,programs.name
, anduniversities.name
, then perform one query for each of those tables and merge the results yourself. (You will probably have to display results for a matched student differently than a matched university, for instance.) It may help somewhat to break the existingstudent.name
field up into a separate first-name and last-name field, as that'll allow you to search those two separately.在 PHP 中,
$keyword
是您要搜索的单词。编辑
根据评论,认为这就是您所需要的
,其中
key
是您正在搜索的单词。In PHP
$keyword
is the word you want to search for.EDIT
Based on the comment, Think this is what you need
Where
key
is the word you are searching for.