Topic: Faster Search Query

Hey Folks,

Really looking for some advise on how you would tackle this problem. I am building a hotel room search system. So basically a user can come to the site and search for available room's for a given area, city etc.

Doing the search based on location or facilities is not a problem but only showing available rooms is. A room would already have multiple future bookings so basically a bunch of blackout dates. A good example of what I mean would be like the airbnb site. You can search for properties and give checking-checkout dates. It will then only show you the available rooms.

While I don't think the query wouldn't be that bad I can see it being slow when you have 1000's of blackouts across many rooms.

Can you suggest any good workarounds for performance ie using other technologies like redis, elasticsearch?  If so how can you explain how you would achieve such a thing.

Really hope someone can advice and thanks for your time.

Re: Faster Search Query

I'm not 100% sure I understand your question completely, but one way to model the rooms in order to make the searching easy would be (not full code and untested, you will probably need to modify):

Room.rb

has_many :bookings

Booking.rb

belongs_to :room

rooms_controller.rb

# create a scope or a method to check if a date is between 2 days (start and end). If true, then the room is available

Make sense? Hopefully this gives you some insight on what direction to go

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!