简体   繁体   English

如何在Algolia中创建相对日期/时间过滤器(即“一天前”,“两天前”,“三天前”)?

[英]How can i create relative-date/time filter in Algolia (i.e. “a day ago”, “2 days ago”, “3 days ago”)?

In my hits, i have a prop that contains added .. and when i try to make a filter on date added, list of common date appears. 在我的热门歌曲中,我有一个包含添加的道具..当我尝试对添加的日期进行过滤时,会出现常见日期列表。 How can I make a filter that says.. 1 day ago, 2 days ago, 1 week ago etc.. then filter the results. 我如何制作一个过滤器,说.. 1天前,2天前,1周前,等等。然后过滤结果。

so instead of showing full list of dates as filter, i can just personalize it depending on what i want. 因此,除了显示完整的日期列表作为过滤器之外,我还可以根据自己的需要对其进行个性化设置。

Script: 脚本:

//Algolia Widget for Date Added.
search.addWidget(
  instantsearch.widgets.menu({
    container: '#added-menu',
    attributeName: 'added',
    limit: 10,
    templates: {
      header: 'Added'
    }
  })
);

//Date added will display the whole list of common dates. 

Update : I was able to find solution for handling the relative date and it is by the use filter named numericSelector found in algolia documentation. 更新:我能够找到解决相对日期的解决方案,这是通过在阿尔戈利亚文档中找到名为usenumSelector的使用过滤器进行的。 the situation is, i just need to copy the relative dates we have in our old App. 情况是,我只需要复制旧应用程序中的相对日期。

here are the constraints : 这里是约束:

  • Use a relative time/date filter. 使用相对时间/日期过滤器。
  • Do not display the common dates in the hits. 不要在匹配中显示常用日期。
  • Use a dropdown. 使用下拉菜单。
search.addWidget(
      instantsearch.widgets.numericSelector({
       container: '#added-menu',
        attributeName: 'added',
        templates: {
          header: 'Added'
        },
        operator: '>=',
        options: [
          {label: 'Anytime', value: 0 },
          {label: 'Today', value: daysBefore(1) },
          {label: 'Within 3 Days', value: daysBefore(3)},
          {label: 'Within 1 week', value: daysBefore(7)},
          {label: 'Within 2 weeks', value: daysBefore(14)},
          {label: 'Within 1 Month', value: daysBefore(30)},
          {label: 'Within 3 Months', value: daysBefore(90)},
          {label: 'Within 6 Months', value: daysBefore(183)}
        ]
      })
    );

daysBefore() is a function that returns the current date minus the number of days and then converted to a linux timestamp. daysBefore()是一个返回当前日期减去天数然后转换为linux时间戳的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何过滤从当前日期到 90 天前的 createdAt? - How to filter createdAt from current date to 90 days ago? ReactJS:将 EpochTime 从 1970 年到现在,1 小时前,2 小时前,1 天前,3 天前 - ReactJS: Convert EpochTime since 1970 to just now, 1 hour ago, 2 hours ago, 1 day ago, 3 days ago 如何使用 moment.js 将日期时间字符串转换为一分钟前/一天前/一个月前/一年前格式 - How do I convert a datetime string to a mins ago/day ago/month ago/ year ago format using moment.js 计算和显示前几天 - Calculating and displaying the days ago Moment.js中的相对日期使用.fromNow() - 如何在几年,几个月和几天前聚在一起? - Relative Date in Moment.js using .fromNow() - how to get together years, months and days ago? 过滤具有 2 天前时间戳的对象 - Filter objects that have a timestamp from 2 days ago 我怎样才能获得显示“昨天”而不是“一天前”的时间? - How can I get moment to display "yesterday" and not "a day ago"? 如何使用 javascript 获取 4 年 5 个月 3 天前的日期 - how to get what date was 4 years 5 months 3 days ago with javascript 如何将“日期”转换为“天,小时或秒前”字符串? - How to turn a Date into a 'days, or hours, or seconds ago' string? 获取日期之前多少天/小时/秒 - Get how many days/hours/seconds ago from date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM