I am working on an Airbnb-like website and I am in the process of rewriting our in-house, SQL-based search system with Algolia. It's been a really pleasant journey so far, as I have managed to remove a lot of legacy code and outsource it, with awesome results. However, there is one critical piece of our search system which I am not sure can be implemented with Algolia.
Internally, we store the availability/unavailability (and price) of each date for each asset as a single row in the database. This means our availabilities
table looks like this:
asset_id | date | status | price_cents
-------- | ---------- | ----------- | -----------
1 | 2017-02-09 | available | 15000
1 | 2017-02-10 | available | 15000
1 | 2017-02-11 | unavailable | NULL
1 | 2017-02-12 | available | 20000
When a user searches for available properties, they enter a date range and, optionally, a price range.
What we're doing now is simply querying the availabilities
table and making sure that all dates in the date range are available for that asset (i.e. the count of available dates is equal to the number of days in the range). If the user enters a price range, we also make sure that the average price for those dates is within the requested range. The SQL query is fairly complex, but this is what it does at the end of the day.
I have been trying to replicate this with Algolia, but couldn't find any documentation about a similar feature. In fact, I am facing two separate issues right now:
- I have no way to ensure all dates in the provided date range are available, because Algolia has little to no knowledge about associations, and
- I have no way to calculate (and query) the average price for the provided date range, because it depends on user input (i.e. the date range).
Is there a way to achieve this with Algolia? If not, is it feasible to use SQL or another tool in combination with Algolia to achieve the desired result? Of course, I could do all of this with Elasticsearch, but Algolia is so fast and easy that I'd hate to step away from it because of these issues.