Say I'm building a hotel booking platform, and each room record has an availability calendar. A common search criterion is duration search. When the user enters a start date and an end date, and the database selects rooms that are not occupied with this duration.
I implemented a very naive approach when I store busy days as an array of days.
attribute :occupied_at_i do array = [] if !occupied_at.empty? occupied_at.each do |date| array << Time.parse(date).to_i end end array end
And then on the client side, I add the following javascript code to cross check if the day is in numericRefinement
// Date Filters $('.date-field') .on('change', function() { if(_.every(_.map($('.date-field'), function(date) {return _.isEmpty(date.value) }), function(n) {return n==false;})) { helper.clearRefinements('occupied_at_i'); var arrayOfDates = addDateFilters(); _.forEach(arrayOfDates, function(n) { helper.addNumericRefinement('occupied_at_i', '!=', n); }); showClearAllFilters(); helper.search(); } });
So, this is obviously not a very good way to do this, I wonder what is better to use on algolia and search by duration?
thanks
javascript ruby-on-rails search algolia
Chris yeung
source share