将 Algolia 自动搜索延迟到第三个字符
我有一个与我合作构建客户网站的开发人员(我是一名具有一定 CSS 技能的设计师),它使用了 algolia,这很棒,但我正在尝试找到一种方法,使 Algolia 在输入 3 个字符之前不会开始自动搜索,然后它可以搜索远方。
我相信这就是执行此操作的代码。我需要找出一种方法来延迟查询变得有效?直到输入3个字符
export default function SearchPlaceholder({toggleAlgolia, query}) {
return (
<div className={styles.searchPlaceholder}>
<div className={styles.searchBox}>
<div
role="button"
tabIndex="0"
className={styles.trigger}
onClick={() => {
toggleAlgolia(true)
}}
onKeyPress={(event) => {
if (event.key === 'Enter') {
toggleAlgolia(true)
}
}}
>
<span>Click to Search Glossary</span>
</div>
<input
tabIndex="-1"
type="search"
value={query}
placeholder="Search our glossary..."
readOnly
/>
<button type="button" tabIndex="-1" disabled>
<SearchIcon />
</button>
</div>
</div>
)
}
I had a developer I worked with to build a client site (Im a designer with some CSS skills) and it uses algolia which is great but I am trying to find a way to make Algolia not start autosearching until 3 characters have been entered, then it can search away.
I believe this is the code doing it. I need to figure out a way to delay query into becoming valid? Until 3 characters are entered
export default function SearchPlaceholder({toggleAlgolia, query}) {
return (
<div className={styles.searchPlaceholder}>
<div className={styles.searchBox}>
<div
role="button"
tabIndex="0"
className={styles.trigger}
onClick={() => {
toggleAlgolia(true)
}}
onKeyPress={(event) => {
if (event.key === 'Enter') {
toggleAlgolia(true)
}
}}
>
<span>Click to Search Glossary</span>
</div>
<input
tabIndex="-1"
type="search"
value={query}
placeholder="Search our glossary..."
readOnly
/>
<button type="button" tabIndex="-1" disabled>
<SearchIcon />
</button>
</div>
</div>
)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些不是典型的 Algolia 库——我怀疑与 Algolia 的实际连接在您的代码中更深一些。
尝试找到您的应用导入
algoliasearch
的位置,这应该会让您更接近连接到服务的位置。我应该指出,我们通常不鼓励延迟搜索,因为它会在搜索结果中引入明显的“滞后”,您的用户可能会将其解释为响应缓慢。它不再成为“键入时搜索”,但如果您确实希望仅在达到一定数量的最小字符后才触发搜索,您可以通过使用我们的 helper.js 82 库拦截搜索来更改此默认行为。
同样,这可能会导致用户感觉搜索滞后,但会减少搜索操作的次数并降低成本。
Those aren't the typical Algolia libraries -- I suspect the actual connection to Algolia is sitting a little deeper in your code based.
Try to find where your app is importing
algoliasearch
and that should get you closer to where you are connecting to the service.I should point out we typically discourage delaying search because it introduces a perceived “lag” in search results that your users might interpret as a slow response. It no longer becomes search-as-you-type, but if you do want to trigger a search only after a certain number of minimum characters you can change this default behavior by intercepting the search using our helper.js 82 library.
Again, this may cause users to perceive the search to be lagging, but will reduce the number of search operations and reduce the cost.