gpt4 book ai didi

php - 重复使用关键字进行搜索

转载 作者:行者123 更新时间:2023-11-29 14:26:12 25 4
gpt4 key购买 nike

我必须创建一个搜索功能,用户可以搜索附加到不同文章的标签,例如:PC、健康、时尚服装...等。我当前的表是这样的:

Tag_id  | Tag            | Article_id
-----------------------------------
1 | scary | 2
-----------------------------------
2 | daunting | 2
-----------------------------------
3 | chilling | 2
-----------------------------------
4 | creepy | 2
-----------------------------------
5 | scary | 5
-----------------------------------
6 | daunting | 5
-----------------------------------
7 | chilling | 5
-----------------------------------
8 | creepy | 5

正如您所看到的,每个标签都有同义词,必须在共享相同标签的每篇文章中重复这些同义词。我的问题是:什么样的表结构允许重复使用标签(没有重复的标签),同时不利于搜索。 (不能使用普通的同义词库,因为标签是一些短语和俚语)

最佳答案

您需要三个表:

ARTICLE
id (a primary uid)
link (links to the article)

TAG
id (a primary uid)
name (ie 'chilling')

ARTICLETAG
article (a foreign key: a uid that exists in ARTICLE)
tag (a foreign key: a uid that exists in TAG)

每次您想要标记一篇文章时,您都可以在 ARTICLETAG 中插入一个新行,其中包含您想要标记的文章以及您想要标记的标签的 ID。根据新文章和标签的需要添加到 TAGARTICLE

关于php - 重复使用关键字进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10917547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com