1

Forgive this super basic question, from a search newbie.

I want to implement a site that makes use of faceted search. For example, it's a site with a database of hotels, and I want to allow users to search for hotels within a price range, with a swimming pool, with either three or four stars.

Clearly I can return results to users with a simple database query.

Should I use ElasticSearch or Solr to implement this instead of using a database query? If so, why?

Richard
  • 62,943
  • 126
  • 334
  • 542

1 Answers1

6

Yes you should use ES or Solr. Reasons: primarily performance and the ability to change (think config) 'types of faceting' easily.

Faceting is no small feat and although you could do it with a RDBMS, to do it fast requires hard thinking. Why do it yourself if you can use the gazillions of hours Solr / ES (+ Lucene) teams have worked to optimize it.

As for the 'types of faceting' I mentioned:

  1. perhaps you want to do hierarchical faceting. Select price-category > display smaller price categories. How are the bucketed: fixed range, evenly distributed, etc. Solr / ES provide these options from within a config.
  2. Perhaps instead you implement price-faceting with a slider with min/max handles? Do you want to display the nr of hotels while you slide (histogram/facetstats in SOlr / ES)
  3. While you've faceted on price, perhaps you still want to know the min and max-value of the priceslider as if you DIDN't filter on price. This is needed if you want to be able to draw the slider-handles proportionally. (see my question on SO as part of considering a switch from Solr to ES: Elasticsearch: excluding filters while faceting possible? (like in Solr) )
  4. faceting on stars? Perhaps you want to show the best price per stars-facet if the user would select that star (again histogram/ stats)

Seriously, don't even consider doing the above with a RDBMS. You'll go insane.

Hope that helps, and yes I'm familiar with the domain :)

Additional questions, just ask.

Community
  • 1
  • 1
Geert-Jan
  • 18,623
  • 16
  • 75
  • 137
  • 1
    Thanks! What I'd really like to do is have an Ajax front-end where (say) the user can slide the slider and everything is updated instantly. I was thinking of building a JavaScript front-end and returning database results via a JSON API: but can ES/Solr expose a JSON API? Or even better, do they offer Ajax front-ends out of the box? Forgive me asking these simple questions. – Richard Aug 08 '12 at 18:42
  • Well, one of reasons I've switched to ES: it talks JSON natively :).. And yes what you suggest makes perfect sense (we do it), although I'm not aware of any out-of-the-box ajax front-ends – Geert-Jan Aug 08 '12 at 19:01
  • 2
    What you DO want to probably do is hook up a client-side MVC framework such as backbone (or spine.js that I use) .. See this post (plus my answer) for what I consider a good process of setting up a search-page this way > http://stackoverflow.com/questions/7370056/accessibility-and-all-these-javascript-frameworks/7371629#7371629 . This doesn't talk about the backend btw. – Geert-Jan Aug 08 '12 at 19:10
  • Fantastic - that's what I'll do (I like Angular.js personally). Thanks for a really helpful answer! – Richard Aug 08 '12 at 20:38
  • for solr ajax see https://github.com/evolvingweb/ajax-solr (never tried it but the demo looks interesting) – montrealmike Sep 18 '12 at 21:08