如何设置全文索引

发布于 2024-11-18 21:23:17 字数 646 浏览 0 评论 0原文

我想要一些关于如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聚集的泪 2024-11-25 21:23:17

这不是 FULLTEXT 索引的工作原理。 FULLTEXT 索引必须位于 MyISAM 表中的单个文本 (CHAR / VARCHAR / TEXT) 列上,并允许搜索匹配该列内容中的单词。例如,您可以在课程目录中使用 FULLTEXT 索引,以允许用户在课程描述中搜索文本。

在您的情况下,您可能想要做的是为每个 students.namecourses.nameprograms.nameuniversities.name,然后对每个表执行一个查询并自行合并结果。 (例如,您可能必须以不同于匹配大学的方式显示匹配学生的结果。)将现有的 student.name 字段分解为单独的名字和姓氏可能会有所帮助。 -name 字段,因为这将允许您分别搜索这两个字段。

That's not how FULLTEXT indexes work. A FULLTEXT 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, and universities.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 existing student.name field up into a separate first-name and last-name field, as that'll allow you to search those two separately.

乖乖兔^ω^ 2024-11-25 21:23:17

在 PHP 中,

 $query= "SELECT * FROM students,courses,programes,universities WHERE MATCH(students.name,courses.name,programs.name,universities.name) AGAINST('$keyword' IN BOOLEAN MODE)"
 $result = mysql_query($query);

$keyword 是您要搜索的单词。

编辑

根据评论,认为这就是您所需要的

 SELECT name from student where name like %key% OR 
    course_id IN (SELECT id FROM course WHERE name like %key%) OR 
    course_id IN (SELECT id FROM course WHERE program_id IN (
           SELECT id FROM program WHERE name Like %key%)) OR
    course_id IN (SELECT id FROM course WHERE program_id IN (
      SELECT id FROM program WHERE university_id in (
         SELECT id from university where name like %$key%))) 

,其中key是您正在搜索的单词。

In PHP

 $query= "SELECT * FROM students,courses,programes,universities WHERE MATCH(students.name,courses.name,programs.name,universities.name) AGAINST('$keyword' IN BOOLEAN MODE)"
 $result = mysql_query($query);

$keyword is the word you want to search for.

EDIT

Based on the comment, Think this is what you need

 SELECT name from student where name like %key% OR 
    course_id IN (SELECT id FROM course WHERE name like %key%) OR 
    course_id IN (SELECT id FROM course WHERE program_id IN (
           SELECT id FROM program WHERE name Like %key%)) OR
    course_id IN (SELECT id FROM course WHERE program_id IN (
      SELECT id FROM program WHERE university_id in (
         SELECT id from university where name like %$key%))) 

Where key is the word you are searching for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文