SOLR旅游网站:日期查询 [英] SOLR travel site: on date queries

查看:18
本文介绍了SOLR旅游网站:日期查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为酒店预订网站实施 SOLR.基于位置、酒店名称、设施的搜索效果很好,分面也是如此.我无法弄清楚的是如何在给定入住和退房日期的情况下搜索酒店.

I was looking to implement SOLR for a Hotel bookings site. Search based on location, hotel names, facilities works very well and so does the faceting. What I have not been able to figure out is how to search for a hotel given Checkin and Checkout dates.

例如:用户将搜索搜索查询 -纽约酒店"并从日期选择框中选择入住日期:2012 年 2 月 10 日和退房日期:2012 年 2 月 12 日.

Eg: User will search for search query - "Hotels in Newyork" and select CheckIn Date: 10th Feb 2012 and CheckOut Date: 12 Feb 2012 from the date selection box.

这就是我获得数据的方式 -

This is how I have the data -

Hotel_Name 10thFeb2012    11thFEB2012 ........   31DEC2012
Hotel1      2room            3room                  10rooms
Hotel2      1room            4room    ........      12rooms

现在,如果查询从入住日期 10thFeb2012 到 11thFeb2012 的 3 个房间的 Hotel2,它不匹配,因为只有一个房间可用于 10thFeb.如果 Hotel2 的查询是从入住日期 10thFeb2012 到 11thFeb2012 的 1 个房间,那么它应该是搜索结果的一部分.

Now if the query is for Hotel2 for 3rooms from checkin Date 10thFeb2012 to 11thFeb2012 it shdnt match because there is only one room available for 10thFeb. IF the query for Hotel2 is for 1 room from checkin Date 10thFeb2012 to 11thFeb2012 then it should be part of search result.

推荐答案

使用 ISO 8601 格式 用于您的日期时间.

Use the ISO 8601 format for your date-times.

 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 都将从符合该格式的字符串中理解日期时间.

Both your database and Solr will understand date-times from strings that conform to that format.

所以,

  1. 使用兼容的日期时间格式将数据存储在 DB 和 Solr 中.(在我的脑海里,Solr 必须有一个 Z 附加到日期时间,否则它是无效的).
  2. 您的搜索界面必须以该格式格式化所有日期才能查询 solr.
  1. store the data in DB and Solr with compatible date-time formats. (On the back of my head, Solr must have a Z appended to the date-time, else its invalid).
  2. your search interface must format all dates in that format to query solr.

Solr 可以对日期进行条件表达式、分面、范围分面等.

Solr can do conditional expressions, facets, range bucket faceting etc with dates.

我会采用以下架构:

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 之间的房间.

For each room you are ever tracking, store the date-times between which it is free. You can search for rooms between the start_date and end_date.

hotel_name 进行分面,以便您搜索入住日期为 10thFeb2012 至 11thFeb2012"的房间:

Do faceting on hotel_name so your search for rooms "checkin Date 10thFeb2012 to 11thFeb2012" gets you:

Hotel1:[r1,r2,r3]
Hotel2:[r8]
Hotel3:[r2,r3,r4]

面向 hotel_name 过滤器到一个酒店,room_id 上的 facet.mincount 可以返回具有所需房间数的酒店.

Faceting on hotel_name filters to one hotel, facet.mincount on room_id can return hotels having the required number of rooms.

一点警告:我可能对刻面有点生疏,因为我过去常常对 Solr 结果本身进行大量处理.

A little warning: I may be a bit rusty on faceting, as I used to do a lot of processing on Solr results itself.

这篇关于SOLR旅游网站:日期查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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