如何按日期过滤solr中的查询? [英] How to filter query in solr by date?

查看:21
本文介绍了如何按日期过滤solr中的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 SOLR 中有日期字段(published_date)并且值采用这种格式2012-09-26T10:08:09.123Z"

In my SOLR there is date field(published_date) and values are in this format "2012-09-26T10:08:09.123Z"

如何通过简单的输入(例如2012-09-10"而不是完整的 ISO 日期格式)进行搜索.

How I can search by simple input like "2012-09-10" instead of full ISO date format.

在SOLR中可以吗?我已经尝试过

Is it possible in SOLR?I have tried with

fq=[2012-09-24%20TO%20NOW]

它应该通过过滤大于发布日期 2012-09-24 且小于 NOW 的结果返回.

It should return by filtering results greater than published date 2012-09-24 and less than NOW.

但它返回发布日期为 2012-09-23 的数据,如下所示

But it returns data with published date with 2012-09-23,like below

<float name="score">2.8183863</float>
<str name="name">Local Team Inspires Obama</str>
<date name="published_date">2012-09-23T07:44:53.123Z</date>

我错过了什么吗?

提前致谢.

推荐答案

如果您想获得上周的出版物,您可以这样做:

If you want to get last week publications you can do somehting like:

&fq=published_date:[NOW-7DAY/DAY TO NOW]

但是如果你想要一个具体的日期,你必须使用 SOLR 日期格式:

But if you want a concrete date you must do it in the SOLR date format:

&fq=published_date:[2013-07-17T00:00:00Z TO NOW]

最后但并非最不重要的.

Last but not least.

  • 使用 [ ] 表示包含范围
  • { } 用于独占范围
  • 您可以像 [ } 一样将它们混合在一起,用于包含 - 独占,反之亦然 { ]
  • use [ ] for inclusive ranges
  • use { } for exclusive ranges
  • you can mix them like [ } for inclusive - exclusive and vice versa { ]

希望能帮到你

这篇关于如何按日期过滤solr中的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆