【问题标题】:Algolia InstantSearch default Parameters / ScopeAlgolia InstantSearch 默认参数/范围
【发布时间】:2018-10-23 11:05:05
【问题描述】:

我有一个使用 Algoia InstantSearch 库的 React 应用程序。这个https://community.algolia.com/react-instantsearch/

  <InstantSearch
    appId="KJH78673IUH"
    apiKey="e55e048w7fh8wh8wrgh834c3ea51e3"
    indexName="Events"
  >
    <Configure hitsPerPage={10} />
    <SearchBox />
    <h3>Latest Events</h3>
    <Hits />
    <Index indexName="Venues">
      <h3>Latest Venues</h3>
      <Hits />
    </Index>
    <Index indexName="Users">
      <h3>Latest Users</h3>
      <Hits />
    </Index>
  </InstantSearch>

这工作正常,并在我输入时提取结果。然而。在每个事件、地点和用户记录上,我都有一个属性site_id。我很难弄清楚如何将site_id 设置为搜索查询的默认范围。与default_scope 在 Rails 中的工作方式类似。我确信这是可能的,但无法弄清楚。

任何帮助将不胜感激!

【问题讨论】:

  • 签出this
  • 谢谢。我还是不太明白……对不起。我尝试添加 但它无法识别密钥。
  • 我试图在codesandbox上复制这个问题,但您的app id似乎是错误的。
  • @bobylito 我更改了这些细节只是因为我不希望它暴露给公众。

标签: reactjs algolia


【解决方案1】:

我想出了如何使用 VirtualWidgets 来做到这一点。

https://community.algolia.com/react-instantsearch/connectors/connectMenu.html

特定属性的索引范围我使用了以下方法:

import { connectMenu } from 'react-instantsearch/connectors';
const VirtualMenu = connectMenu(() => null);
// RESET OF COMPONENT CODE
<InstantSearch
    appId="KJH78673IUH"
    apiKey="e55e048w7fh8wh8wrgh834c3ea51e3"
    indexName="Events"
  />
    <Configure hitsPerPage={10} />
    <VirtualMenu attribute="site_id" defaultRefinement="1" />
    <SearchBox />
    <h3>Latest Events</h3>
    <Hits />
    <Index indexName="Venues">
      <h3>Latest Venues</h3>
      <Hits />
    </Index>
    <Index indexName="Users">
      <h3>Latest Users</h3>
      <Hits />
    </Index>
  </InstantSearch>

您也可以将 VirtualWidget 添加到 Index 块本身。

【讨论】:

    猜你喜欢
    • 2018-05-03
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 2018-06-28
    • 2017-12-07
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多