ThinkingSphinx Site Search

biv edited this page Sep 13, 2010 · 3 revisions
Clone this wiki locally

Some brief notes on setting up Thinking Sphinx site search in a BCMS implementation.

First, learn about and install “thinking sphinx”: .

The hooks between TS and BCMS models can be created very easily by subclassing whatever you want to index in your search.

class SphinxPage < Page
  define_index do
    indexes name
    indexes title
    indexes keywords
    indexes connector.connectible

    has published

This file is in my lib directory, and I require it in my environment.rb . From here on in, I only have to ‘rake ts:rebuild’ (to get the sphinx configuration set up) and ‘rake ts:in’ to reindex new data.

Everything is straightforward usage for ThinkingSphinx. I set up a search controller at the front:

  map.connect "/search", :controller => "search", :action => "search" 
  map.namespace('cms') do |cms| 
    cms.resources :datasets, :only => [:show, :index], :member => {:hide => :get, :publish => :get}, 
                    :has_many => :annotations

It my go without saying, but in addition I hang a search form on the default cms template (in my case app/views/layouts/templates/ as well as the application layout. The search form posts to the search controllers, which renders on a results action and template. This is bog standard search stuff which doesn’t have to be explained here.