使用 Algolia 和 Typeahead 在网站中提及用户

User Mentions in Website Using Algolia & Typeahead

我目前正在使用 Algolia 为我的用户数据编制索引,并使用 Typeahead 提供自动完成搜索结果,我真的很喜欢它的工作方式。

现在,我对在文本区域中向我的网站添加提及 (@user) 感到好奇,并认为应该有一个 "fairly" 简单的方法来使用 javascript 来识别我何时使用文本区域中的“@”符号,初始化 Typeahead,并允许我在我的文本中自动完成用户。

有人对此有任何想法吗?可能使用:

if (string.indexOf("@") > -1 )
{
   // initialize typeahead
}

不确定是否可以这么简单...

谢谢!

我想你应该能在这里找到你需要的一切:https://www.algolia.com/doc/search/autocomplete-textarea

One approach is to use Javascript plugins & scripts that perform, most of the time, very basic text search (based on regex) on items already pre-populated in the HTML, or dynamically retrieved from the database via AJAX requests. Those solutions work OK, but quickly show their limits as soon as you want to offer to your users a search experience that handles their typos, is fast, and can work on hundreds, thousands or millions of items.