标签建议(不是标签自动完成)

发布于 2024-08-29 08:47:30 字数 537 浏览 9 评论 0原文

AJAX 自动完成的实现相当简单。但是,我想知道如何处理这样的智能标签建议。

澄清自动完成建议之间的区别:

  • 自动完成:foo [foobar,foobaz]
  • 建议:foo [barfoo , foobar, foobaz],或者甚至更好,带有“你是说”功能吗:[barfoo, foobar, foobaz, fobar, fobaz]

我想我需要在标签中进行一些全文搜索(所有字母都被索引,而不仅仅是单词)。对于有限数量的标签(甚至是客户端),使用正则表达式或其他模式来做到这一点是没有问题的。

但是如何针对大量标签实现此功能?
SO 上的标签是用破折号分隔的,是否有任何特殊原因(除了 URL 之外)?标签中的 Unicode 字符怎么样?

我将标签存储在具有以下列的表中:id、标签名。 我的 SQL 查询返回具有以下字段的对象:id、标记名、计数

(我使用 Doctrine ORM 和 pgsql 作为默认数据库驱动程序。)

AJAX autocomplete is fairly simple to implement. However, I wonder how to handle smart tag suggestion like this on SO.

To clarify the difference between autocomplete and suggestion:

  • autocomplete: foo [foobar, foobaz]
  • suggestion: foo [barfoo, foobar, foobaz], or even better, with 'did you mean' feature: [barfoo, foobar, foobaz, fobar, fobaz]

I suppose I need some full text search in tags (all letters indexed, not just words). There would be no problem to do it witch regex or other patterns for limited number of tags (even client side).

But how to implement this feature for big number of tags?
Is there any particular reason (besides URL) the tags on SO are dash separated? What about Unicode characters in tags?

I store the tags in the table with the following columns: id, tagname.
My SQL query returns objects with following fields: id, tagname, count

(I use Doctrine ORM and pgsql as default db driver.)

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

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

发布评论

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

评论(1

药祭#氼 2024-09-05 08:47:30

我会在每次按键时通过 REGEXP 从数据库中选择它们。我在我的网站上执行了此操作,并且没有预执行问题(我没有认为服务器负载很重)。如果您不喜欢这个想法,我会兑现用户输入的所有 1-5 个字母组合,并每天在单独的表中刷新它们。如果该表已建立索引,那么您的实施速度会非常快。

详细说明第二个方法:

简单地说: 1. 创建一个表 SEA​​RCHTABLE,表示关键字(限制为 3-4 个字母)和标签的主 ID 之间的 1-n 关系。 2. 两个字段上的索引。 3. 每次用户进行搜索时,请查看搜索表,如果存在组合,则使用它 - 速度非常快,因为所有内容都已编入索引。如果没有,则进行正则表达式搜索并将所有结果放入 SEARCHTABLE。

注意:

  1. 如果出现以下情况,则应使表无效:
    您添加标签,但这应该很多
    比搜索频率低。什么时候
    使您不做的表无效
    必要时截断它,你可以
    轻松重建它
    关键词考虑在内。
  2. 如果你想加快速度,你可以“预生成”所有两个甚至三个
    字母搜索。
  3. 如果您足够关心,您应该使用 n-1 个字母关键词的信息来生成
    n 个字母的关键字。它极大地加快了速度。假设用户输入了“mo”
    并且您已经向他们展示了 SEARHTABLE 的适当结果。比她输入“n”时
    给它“mon”,您只需要搜索已经选定的项目即可生成新的
    回复。

希望现在更全面了。

I would go with SELECTING them from database by REGEXP at every keypress. I did this on my sites and the was no prefrormance problem (I do not have heavy loaded server thought). If you do not like this idea, I would cash all 1-5 letters combinations which will users enter and refresh them on daily basis in separate table. If this table is indexed than you have very fast implementation.

To elaborate more on the second appreach:

Briefly: 1. Make a table SEARCHTABLE representing 1-n relationship betwean keywords (limit it to 3-4 letters) and primary IDs of tags. 2. INDEX on both fields. 3. Everytime the user makes a search do look at the SEARCHTABLE and if the combination is there, use that - very fast, as everything is indexed. If not do the regexp search and put all results to SEARCHTABLE.

Notes:

  1. You should invalidate the table if
    you add tags, but this should much
    less often than a search. When
    invalidating table you do not
    necesarilly TRUNCATE it, you can
    easily rebuild it taking all
    keywords into account.
  2. If you want to speed it up, you can "pregenerate" all two or even three
    letters searches.
  3. If you care enough, you should be using information from n-1 letter kewords to generate
    the n letter keyword. It speeds the things tremendously. Imagine that user has typed "mo"
    and you have shown them appropriate result from SEARCHTABLE. Than when she types "n"
    giving it "mon" you need only serach trough already selected items to generate new
    response.

Hope it is more comprehensive now.

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