Facetting:Killer featureSolr has facetting.Solrfacetting has great support on the client side (sunspot)In Sphinx it is just not really thereFacets can only be ids and it requires multiple client side callsIncremental updates:Update a model, changes can be instantly in the indexTrivial to controlScalabilitySolr master with two slaves, fronted by varnishTrivial replicationEasy to add new fieldsDynamic fieldsNo need to recreate indexNo need to sync code with Solr, gracefully ignores extra valuesCan add new classes to index with no restartDo everything in Ruby:Derived fieldsRelationshipsDecoupled from DBSignificant model refactoring which didn’t require changes to indexing codeComms between app and SolrMakes most of the above much simpler having only two parties involvedHTTP interface for both indexing and searchingNo SQL involved
Index column typeDerivable dataMultiple value columns, used for facetting
From the user perspective, faceted search (also called faceted navigation, guided navigation, or parametric search) break up search results into multiple categories, typically showing counts for each, and allow the user to "drill down" or further restrict their search results based on those facets.Used on e-Commerce sites for categorisation/refinementUsed on RedBubble for top tags and available products
Solr and sunspot
Solr and sunspot
Learnings from RedBubble
Who am I?
What are Solr and sunspot?
Why do we use them?
What is Solr?
Solr is Apache’s search engine
Wraps and enhances Lucene
Java webapp (Tomcat)
sunspot: Gem for Solr communication
sunspot-rails: Plugin for Rails
(Magic) Dynamic index schema for Solr
Development convenience scripts
What attracted us to Solr?
Incremental index updates
Scalability, master + slave(s)
Easy to add new fields (sunspot magic schema)
Do everything in Ruby
Communication between app and Solr (no DB)
DSL - Indexing
class Post < ActiveRecord::Base
string :sort_title do
string :tags, :multiple => true do
tags.split(",") unless tags.nil?
DSL - Searching
@search = Post.search(:include => :comments) do |s|
s.fulltext params[:q], :fields => [:title, :body]
s.facet :tags, :sort => :count
s.order_by :sort_title, :asc
@search.results.each do |result|