Solr- multivalued date field, range queries to match “any”/“count”?

天涯浪子 提交于 2019-12-24 01:44:58

问题


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.

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]

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/5914083/solr-multivalued-date-field-range-queries-to-match-any-count

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!