Solr-多值日期字段,范围查询以匹配“任何"/“计数"? [英] Solr- multivalued date field, range queries to match "any"/"count"?

查看:489
本文介绍了Solr-多值日期字段,范围查询以匹配“任何"/“计数"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Solr用作属性预订引擎的一部分-我的输入有一个多值日期字段,该字段存储属性已经预订的日期,因此不可用.我希望能够对此进行查询,并在指定的窗口中返回没有日期的条目.

I'm using Solr as part of a property booking engine- my entries have a multivalued date field which stores the dates that the property is already booked, and thus, not available. I want to be able to query against this, and return entries that have no dates within the window specified.

我已经走了一半-但是现在Solr似乎要返回该条目,即使它有一个空闲日期-我希望它只返回该范围内完全 为空的条目.我的实体的示例:

I'm half way there- but right now Solr appears to be returning the entry if it has even one free date- I want it to only return entries that are totally empty within the range. Example of my entity:

<doc>
    <arr name="DateBlockDates">
        <date>2011-02-25T00:00:00Z</date>
        <date>2011-02-26T00:00:00Z</date>
        <date>2011-02-27T00:00:00Z</date>
    </arr>
</doc>

在这种情况下,查询效果很好:

The query works great in this instance:

-DateBlockDates:[2011-02-25T00:00:00Z TO 2011-02-27T00:00:00Z]

因为该实体确实在那一天的每一天都有日期限制.但是,当我运行时:

Because the entity does have date blocks for every one of those days. However, when I run:

-DateBlockDates:[2011-02-25T00:00:00Z TO 2011-02-28T00:00:00Z]

该实体被返回,因为它没有2011-02-28的条目.

The entity gets returned, because it doesn't have an entry for 2011-02-28.

要将我的问题放入老式SQL中,我想执行一个"count(DateBlockDates)= 0".有什么想法吗?

To put my question into old-school SQL, I want to do a "count(DateBlockDates) = 0". Any ideas?

推荐答案

这是我想出的最佳解决方案-不使用日期查询范围,而是使用:

This is the best solution I've come up with- not using a range for the date query, and instead using:

-DateBlockDates:"2011-02-25T00:00:00.000Z"
AND -DateBlockDates:"2011-02-26T00:00:00.000Z"
AND -DateBlockDates:"2011-02-27T00:00:00.000Z"
AND -DateBlockDates:"2011-02-28T00:00:00.000Z"

这很麻烦,但是可以.值得庆幸的是,我将处理相对较小的日期范围,因此查询不会太长.但是,如果有更好的解决方案,我很想听听.

It's messy, but it works. Thankfully I'm going to be dealing with relatively small date ranges, so the query won't get too long. But if there is a better solution out there I'd love to hear it.

这篇关于Solr-多值日期字段,范围查询以匹配“任何"/“计数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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