如何生成无前缀自动完成建议?
我想将自动完成功能添加到我的标记功能中。
有几个问题:
如何生成自动完成建议列表,其中包含字符串前缀和中间的匹配项?例如,如果用户键入“auto”,则自动完成建议应包括“自动完成”和“构建自动化”等术语。
我想允许多字标签并使用逗号(“,”)作为标签的分隔符。因此,当用户按下空格键时,他仍然会输入相同的标签,但当他按下逗号键时,他会开始一个新标签。我该怎么做?
我正在使用 Django、jQuery、MySQL 和 Solr。实现上述两个功能的最佳方法是什么?
I would like to add autocomplete to my tagging functionality.
A couple of questions:
How do I generate a list of autocomplete suggestions that includes matches in both the prefix and the middle of string? For example, if the user type "auto", the autocomplete suggestions should include terms such as "autocomplete" and "build automation".
I would like to allow multi-word tags and use comma (",") as a separator for tags. So when the use hits the space bar, he is still typing out the same tag, but when he hits the comma key, he's starting a new tag. How do I do that?
I am using Django, jQuery, MySQL, and Solr. What is the best way to achieve to implement the above 2 features?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经完全实现了您所要求的内容,并且效果非常好。有两个问题需要注意:
与之前的答案一样,我将从上面链接的同一篇文章开始,但您确实需要 Edge NGram 分析器。您要添加的内容是还要进行空格标记化。
然后您将对 schema.xml 文件进行这些更改。此示例假设您已经定义了一个名为“title”的字段,并且它也是您想要显示的内容。我创建第二个字段,仅用于自动完成前缀匹配。
步骤 1:定义 Edge NGram 文本字段类型
步骤 2:定义新字段
步骤 3:在索引期间将标题的内容复制到前缀字段
这对于架构来说就差不多了。请记住:
I've implemented exactly what you're asking about and it works really well. There's two issues to be aware of:
Like the previous answer, I'd start with the same article linked above, but you DO want the Edge NGram analyzer. The thing you'll add is to ALSO do whitespace tokenization.
And then you'd make these changes to your schema.xml file. This example assumes you already have a field called "title" defined, and it's what you'd like to display as well. I create a second field, which is ONLY used for autocomplete prefix matching.
Step 1: Define Edge NGram Text field type
Step 2: Define the New Field
Step 3: Copy the Title's content over to the prefix field during indexing
That's pretty much it for the schema. Just remember: