开发者

solr: multivalued dateranges (representing opening hours)

开发者 https://www.devze.com 2023-04-07 04:11 出处:网络
Consider a bar which might have multiple openinghours, depending on the day of week (+ some special days when it might be closed)

Consider a bar which might have multiple openinghours, depending on the day of week (+ some special days when it might be closed)

I want to be able to lookup all bars that are currently open and that will be open for the next, say, 3 hours. (or be able to ask: 'open on 18-10-2011 from 7 until (at least) 10 )

The best thing I believe would be to have a 'open,close'-tuple for each date (other suggestions welcome)

Without, as far as I know ?, a fieldtype that combines open/close hours in 1 field, I can naively (but wrongly) define this structure using 2 fields: 'open' and 'closed', which need to be multivalued.

Now index them like:

open: 2011-11-08:1800 - close: 2011-11-09:0300
open: 2011-11-09:1700 - close: 2011-11-10:0500
open: 2011-11-10:1700 - close: 2011-11-11:0300

And queries would be of the form:

open < now && close > now+3h

But since there is no way to indicate that 'open' and 'close' are pairwise related I will get a lot of false positives, e.g the above document would be returned for:

open < 2011-11-09:0100 && close > 2011-11-09:0600

because SOME opendate is before 2011-11-09:0100 (i.e: 2011-11-08:1800) and SOME closedate is after 2011-11-09:0600 (for example: 2011-11-11:0300) but these open and close-dates are not pairwise related.

I have been thinking about a totally different approach using Solr dynamic fields, in which each and every opening and closing-date gets it's own dynamic field, e.g:

  • _date_2011-11-09_open: 1800
  • _date_2011-11-09_close: 0300
  • _date_2011-11-09_open: 1700
  • _date_2011-11-10_close: 0500
  • _date_201开发者_C百科1-11-10_open: 1700
  • _date_2011-11-11_close: 0300

Then, the client should know the date to query, and thus the correct fields to query. This would solve the problem, since startdate/ enddate are nor pairwise -related, but I fear this can be a big issue from a performance standpoint (especially memory consumption of the Lucene fieldcache)

Thusfar, I haven't found a satisfactory solution. Any help highly appreciated.


While keeping granularity on Bars like I want (instead of BarsxDate) it's possible to use the expirimental Lucene Spatial Playground implementation.

The use-case + general solution is here: https://issues.apache.org/jira/browse/SOLR-2155?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=comment-13115244#comment-13115244


First a question - do you really have open times for dates? not days of the week? but leaving that aside (it doesn't change the answer in any important way), what you should do is create a document for every bar/date combination. In each of these documents you will need all the fields you are planning to search on; maybe that includes location, bar name, etc. So those fields will be denormalized (duplicated across many related documents).

That way you can do the query you describe and get precise results.

0

精彩评论

暂无评论...
验证码 换一张
取 消