sbrattla
sbrattla

Reputation: 5396

Solr : any way to "on the fly" add external data to results?

I'll use an example to explain my question:

I'm about to create a booking website for a hotel. The hotel has 1000 rooms. Availability may change from minute to minute, and the same goes for prices as this depends on availability.

Now, I'm thinking about using Solr as the website's search engine as it provides a whole lot of functionality "out of the box". For starters, it provides filtering and faceting functionality which I will need.

However, a major headache is how I should deal with availability and prices. I could always, once a day, generate a price for each room X number of days ahead starting at any given day Y number of days ahead. This means that if I'd like customers to be offered the option to book a room for anything between 1 and 14 days starting at any day from today and 365 days from today, that will result in a lot of calculations. This does not seem to be an efficient approach.

Is there a way I could plug a custom "price calculator" into Solr? I'm thinking that Solr could hold "static" room data such as number of beds and room size and then plug a "price calculator" into Solr which transparently would calculate prices on the fly and simply return the calculated price along with the search result response. Using the approach, I could also implement filtering and faceting on price.

Is this bordering to abuse of what Solr is meant to handle? Would Solr in any way be capable of this?

Upvotes: 2

Views: 338

Answers (1)

cheffe
cheffe

Reputation: 9500

Solr is index-centric. If prices and availability are not indexed, but calculated on the fly, it will be computational expensive (=> slow) to search and filter by them. As Solr will be forced to loop through the whole result or as worst case through the whole index instead of doing an index lookup.

Since doing things with the index is the core of the system, this is why I say yes to your question

Is this bordering to abuse of what Solr is meant to handle?

But there are means and ways to do this, which I would not recommend to use. I would prefer to answer to your later question

Would Solr in any way be capable of this?

I would have a look at Solr's Near Real Time Feature for this.

Near Real Time (NRT) search means that documents are available for search almost immediately after being indexed: additions and updates to documents are seen in 'near' real time. Solr 4 no longer blocks updates while a commit is in progress. Nor does it wait for background merges to complete before opening a new search of indexes and returning.

With NRT, you can modify a commit command to be a soft commit, which avoids parts of a standard commit that can be costly. You will still want to do standard commits to ensure that documents are in stable storage, but soft commits let you see a very near real time view of the index in the meantime. However, pay special attention to cache and autowarm settings as they can have a significant impact on NRT performance.

That way you can have your price calculation where ever you want, but manifest price and availability into your index fast. You will have to tweak around a bit to have optimal index settings, but it will pay out as you are still using Solr the way its' meant to be.

This is explained to some extend in the SO questions How to update bigger solr index efficiently and Real Time Searching of a Lucene Index that is Updated Frequently - Is this practical?

Of course more information can be found on the web

Upvotes: 1

Related Questions