Solene索引的DateField上的Lucene查询 [英] Lucene Query on a DateField indexed by Solr

查看:51
本文介绍了Solene索引的DateField上的Lucene查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将solr索引用于各种搜索应用程序.在大多数情况下,我们就像在管理界面中一样使用它. 例如:

We are using a solr index for various search applications. In most cases we use it just as you would with the admin interface. for example:

+text:Mr +text:burns +publish_date[2012-09-10T00:00:00Z TO 2012-10-10T00:00:00Z]

这很好用.
我的问题是,在一个应用程序中,我们直接对索引使用复杂的Lucene查询(不使用solr),而在这些查询中,我找不到如何在日期字段上进行搜索.
在schema.xml中:

This works fine.
My problem is that in one app we use complex lucene Queries directly against the index (without using solr) and in these queries i cant find how to search on a date field.
In schema.xml:

<field name="publish_date" type="date" indexed="true" stored="true"/>

似乎solr以毫秒为单位将日期存储为unix时间,当从索引中拉出字段时,它看起来像是 1336867200000

It seems that solr stores the date as unix time in milliseconds, when pulling the field from the index it looks like that 1336867200000

在lucene中,我尝试了所有我能想到的查询:

In lucene I've tried every query I can think of:

TermRangeQuery nq1 = new TermRangeQuery("publish_date",  "1299628800000", "1336867200000", true, true);
TermRangeQuery nq1 = new TermRangeQuery("publish_date",  "1299628800", "1336867200", true, true);
TermRangeQuery nq1 = new TermRangeQuery("publish_date",  "2012-09-10T00:00:00Z", "2012-10-10T00:00:00Z", true, true);
TermRangeQuery nq1 = new TermRangeQuery("publish_date",  "20120910", "20121010", true, true);
NumericRangeQuery nq1 = NumericRangeQuery.newLongRange("publish_date", 1299628800, 1336867200, true, true);

和其他一些尝试...
唯一返回结果的查询是

and a few other tries...
The only query that did return results was

TermRangeQuery nq1 = new TermRangeQuery("publish_date",  null, null, true, true);

这当然是带有开放端点"的查询,但似乎确实适用于该字段被索引为字符串(对于int-range或long-range而言,这是不起作用的).
令人沮丧的是,这显然是可能的,我只需要弄清楚剂量solr预成型的日期范围是什么.
有人知道如何执行此搜索吗?
任何帮助将不胜感激.

Of course this is a query with "Open endpoints" but it does seem to apply that the field is indexed as string (the same didn't work with int-range or long-range).
The frustrating thing is that it is obviously possible, I just have to figure out how dose solr preforms it's date range.
Anyone knows how to perform this search?
Any help would be appreciated.

推荐答案

"1336867200000"是一个时间戳,是的.

The "1336867200000" is a timestamp, yes.

TermRangeQuery nq1 = new TermRangeQuery("publish_date",  "1299628800000", "1336867200000", true, true);
TermRangeQuery nq1 = new TermRangeQuery("publish_date",  "1299628800", "1336867200", true, true); 
TermRangeQuery nq1 = new TermRangeQuery("publish_date",  "2012-09-10T00:00:00Z", "2012-10-10T00:00:00Z", true, true); 
TermRangeQuery nq1 = new TermRangeQuery("publish_date",  "20120910", "20121010", true, true);

由于您使用数字数据的字符串参数,因此上述方法均无效.

Above ones won't work because you are using string parameter for numeric data.

NumericRangeQuery nq1 = NumericRangeQuery.newLongRange("publish_date", 1299628800, 1336867200, true, true);

此代码无效,因为您没有用足够的零填充它. 1970年1月16日星期五12:00:28代表1299628800.

This one wouldn't work because you didn't pad it with enough zeroes. 1299628800 stands for Fri Jan 16 02:00:28 GMT 1970.

如果您有日期为2011年9月3日至2012年5月13日之间的文档,则应该可以进行以下操作:

If you have document(s) dated between 09/03/2011 and 13/05/2012, the following should work:

NumericRangeQuery nq1 = NumericRangeQuery.newLongRange("publish_date", 1299628800000L, 1336867200000L, true, true);

这篇关于Solene索引的DateField上的Lucene查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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