【问题标题】:React Algolia InstantSearch - Is it possible to add a daterange?React Algolia InstantSearch - 是否可以添加日期范围?
【发布时间】:2018-05-03 07:23:27
【问题描述】:

我正在阅读我的项目的 React InstantSearch 的文档,我找不到的一件事是添加日期范围以对我的命中列表进行排序的方法。有没有人有运气这样做?假设我有一个字段createdAt,其值为2017-11-08T09:19:46.310Z,另一个字段createdAt,其值为2017-11-10T09:19:46.310Z。有没有办法在这两个日期之间获得结果?

提前致谢!

更新:我尝试添加<Configure /> 代码,如下所示:

<InstantSearch
    appId={'appId'}
    apiKey={'my-api-key'}
    indexName={'storeName'}
>
   <Configure filters="createdAt: 1503406467899 TO 1509950548555" />
   <SearchHit user={this.props.user} />
</InstantSearch>

现在我收到此错误,我的列表不再加载:

warning.js:36 Warning: Failed prop type: Required prop `searchForItems` was not specified in RefinementList. in RefinementList (at translatable.js:22)

这可能与过时的 React Instant Search 有关吗?

【问题讨论】:

    标签: reactjs algolia react-instantsearch


    【解决方案1】:

    您可以先将字符串日期转换为时间戳,然后使用 Configure widget,您可以这样做:

    <Configure filters="createdAt: 1511184231 TO 1511185231" />
    

    (虚构的时间戳)

    【讨论】:

    • 嘿,感谢您让我找到正确的方向!我用我的数据中的真实时间戳尝试了这一点,但现在当我添加 &lt;Configure&gt; 代码时,我得到了一个错误。我已经更新了我的问题以解决这个问题。有什么想法吗?
    • 我应该注意到我尝试使用 &lt;Configure hitsPerPage={10} /&gt; 并且效果很好。我还添加了“createdAt”作为 algolia 中的刻面属性 hmmm
    • 我也刚升级到"react-instantsearch": "^4.2.0", 仍然有这个问题:/
    • 可以添加&lt;SearchHit/&gt;的代码吗?似乎错误在于这些模块的实现。
    • 好吧,问题是我删除了react-instantsearch 并重新安装了它,现在错误消失了,但我仍然没有得到任何结果。没有错误,没有结果。我什至试过&lt;Configure filters="createdAt&gt;=1501688239.446 AND createdAt&lt;=1510132435.88" /&gt; 仍然没有结果。我可能会错过什么?
    猜你喜欢
    • 2018-10-23
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 1970-01-01
    相关资源
    最近更新 更多