减少自动完成术语
我有一个非常大的术语列表,用于自动完成框中。我一直在考虑如何修剪它们的几种不同方案,但我还没有想出任何好的方案。
基本上,结构与唱片公司非常相似 -
- 艺术家有专辑 专辑有歌曲
- 个别歌曲可能很受欢迎,专辑主要是其基础歌曲受欢迎程度的总和
- 专辑中的歌曲数量也有很大差异 - 所以如果一张专辑有数百首歌曲,很可能有人想要搜索它,而可能性则较小 如果它的歌曲较少
- 随着自动完成变得更加具体(更多字母),我希望显示不太可能的术语
我在想这样的事情:
Apple 10
Banana 10
Crab 20
Diner 30
Dish 20
Daily 10
Diver 20
Dice 10
如果这是专辑列表,并且我为它们分配“分数” ,我只需根据我显示的列表的长度(例如 3)然后按分数弹出选择列表 - 我点击上面的“D”,然后显示“Diner”、“Dish”和“Diver”,然后“i”就变成“Diner”、“Dish”和“Diver”。
是否有特定的算法可以做到这一点?或者为此构建 AJAX 自动完成器?我目前正在使用 Prototype/Scriptaculous,但我似乎无法正确使用它。
I have a very large list of terms for use in an autocomplete box. I've been mulling over a few different scenarios for how to prune them down, but I haven't come up with anything great yet.
Basically, the structure is very similar to a record label -
- An artist has albums An album has songs
- Individual songs could be popular, albums are mostly sums of their underlying song popularity
- Albums also have highly variable number of songs in them - so if an album has hundreds of song, it's very likely that someone would want to search for it, and much less likely
if it has less songs - As the autocomplete becomes more specific (more letters), I'd like less likely terms to be shown
I'm thinking something like this:
Apple 10
Banana 10
Crab 20
Diner 30
Dish 20
Daily 10
Diver 20
Dice 10
If this is the list of albums, and the "score" i assign them, I simply pop choose the list based on the length of the list I'm showing (3 for example) and then by score - I hit "D" above, and "Diner", "Dish" and "Diver" show up, and then "i" and it becomes "Diner", "Dish" and "Diver".
Is there a particular algorithm that does this? Or an AJAX autocompleter built for this? I'm currently using Prototype/Scriptaculous but I can't seem to get it right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚在 Google 代码上发布了服务器端自动完成实现。该项目包括一个可以集成到现有应用程序中的 java 库和一个独立的 HTTP AJAX 自动完成服务器。踢轮胎!
I just posted a server-side autocomplete implementation on Google Code. The project includes a java library that can be integrated into existing applications and a standalone HTTP AJAX autocomplete server. Kick the tires!
这不是一个容易实现的算法,因为您尝试以两种方式对数据结构进行索引 - 按字典顺序和按流行度。
一种方法可能是构建歌曲的压缩 trie,其中每个节点都存储一个预先构建的列表,其中包含以该前缀开头的 N 首最流行的歌曲。这将占用大量存储空间 (O(NUM_SONGS * N)),但允许快速查找 (O(PREFIX))。
This is not an easy algorithm to implement, since you are trying to index a data structure in two ways - lexicographically and by popularity.
One way to do it might be to build a compressed trie of the songs, where at each node you store a pre-built list of the N most popular songs beginning with that prefix. This would take a lot of storage (O(NUM_SONGS * N)), but would allow fast lookup (O(PREFIX)).
您可以尝试闭包自动完成 。
You could give the closure autocomplete a try.