Use the ISO 8601 格式为您的约会时间。
Complete date plus hours, minutes, seconds and a decimal fraction of a second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45Z)
您的数据库和 Solr 都会从符合该格式的字符串中理解日期时间。
So,
- 使用兼容的日期时间格式将数据存储在 DB 和 Solr 中。 (在我的脑海里,Solr 一定有一个
Z
附加到日期时间,否则无效)。
- 您的搜索界面必须将所有日期格式化为该格式才能查询 solr。
Solr 可以对日期进行条件表达式、分面、范围桶分面等。
我会采用以下模式:
hotel_name : string (for faceting)
hotel_name_searchable : text (for searching, this is a copy field:look it up)
room_id : string
start_date : date (when the room is availabe)
end_date : date (if not booked, set it to an infinite date, say 2040)
对于您跟踪的每个房间,存储其空闲的日期时间。
您可以搜索 start_date 和 end_date 之间的房间。
进行刻面处理hotel_name
因此,您搜索房间“入住日期为 2012 年 2 月 10 日至 2012 年 2 月 11 日”会得到:
Hotel1:[r1,r2,r3]
Hotel2:[r8]
Hotel3:[r2,r3,r4]
刻面于hotel_name
筛选到一家酒店,facet.mincount
on room_id
可以返回具有所需房间数量的酒店。
一点警告:我可能对分面有点生疏,因为我过去常常对 Solr 结果本身进行大量处理。