使用替代结果标记数据库

发布于 2024-09-14 07:46:45 字数 745 浏览 4 评论 0原文

我正在开发一个 PHP/Jquery 自动建议工具,它将查询一个大的标签表,但我需要 对数据库模式的一些建议将返回相关标签以及基于匹配的结果。

例如:

我输入“Web”:

结果

'Web Developer'

'Web Designer'

'Web Analyst'

以及相关标签...

'PHP 开发人员'

'Flash 程序员'

显然,每个标签都需要有一列,具有某种关系或亲缘关系值......最好的方法是什么关于这个?

谢谢!

--- 更新 ------------------

当然 - 再次感谢您的所有帮助!

这里是表格..

标签

Id TagName

1 Web 开发人员

2 Web 设计师

3 Web 分析师

4 PHP 开发人员

5 Flash 程序员

相关标签

TagId 相关标签Id 强度

1 4 0

1 5 7

由于“Flash 程序员”的强度值为 7,我喜欢它出现在PHP程序员面前..(希望格式足够清晰..)

再次感谢!

I'm working on an PHP/Jquery autosuggest tool that'll query a large table of tags but I need
some suggestions for the db schema that'll return related tags as well as match-based results.

For example:

I type 'Web':

Results

'Web Developer'

'Web Designer'

'Web Analyst'

and also related tags...

'PHP Developer'

'Flash Programmer'

So obviously there needs to be a column for each tag with some sort of relational or parentage value... Whats the best way to go about this?

Thanks!

--- UPDATE -----------------

certainly - and thanks again for all your help!

here are the tables..

Tags

Id TagName

1 Web Developer

2 Web Designer

3 Web Analyst

4 PHP Developer

5 Flash Programmer

RelatedTags

TagId RelatedTagId Strength

1 4 0

1 5 7

Since the Strength value of 'Flash Programmer' is 7 i'd like it to appear before PHP programmer..(hopefully the format is clear enough..)

thanks again!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

再见回来 2024-09-21 07:46:45

表标签

Create Table Tags (Id int, TagName varchar(50))

表相关标签(两个字段 FK 到标签(Id))

Create Table RelatedTags(TagId int, RelatedTagId int)

用于选择标签匹配输入和相关标签的查询

SELECT Id, TagName, Strength
FROM Tags
WHERE TagName LIKE 'Web%'
UNION
SELECT Id, TagName, Strength
FROM Tags 
WHERE tags.Id IN (SELECT RelatedTagId
       FROM Tags t
       JOIN RelatedTags r
       ON (t.Id = r.TagId)
       WHERE t.tagName LIKE 'Web%')
ORDER By 3 DESC

Table Tags

Create Table Tags (Id int, TagName varchar(50))

Table RelatedTags (both fields FK to Tags(Id) )

Create Table RelatedTags(TagId int, RelatedTagId int)

Query for selecting tag matched input and related tags

SELECT Id, TagName, Strength
FROM Tags
WHERE TagName LIKE 'Web%'
UNION
SELECT Id, TagName, Strength
FROM Tags 
WHERE tags.Id IN (SELECT RelatedTagId
       FROM Tags t
       JOIN RelatedTags r
       ON (t.Id = r.TagId)
       WHERE t.tagName LIKE 'Web%')
ORDER By 3 DESC
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文