Thinking Sphinx Tutorial with Delta Indexing

ruby script/plugin install git://github.com/freelancing-god/thinking-sphinx.git
ruby script/plugin install git://github.com/mislav/will_paginate.git # to use will_paginate

In Model
define_index do
indexes searchable_fields, :sortable => true # to sort the fields
set_property :delta => true # no need to run rake ts:index everytime there is a new data entry, but its really recommend to run rake ts:index everyhour or everyday
end

In Controller
def search
@string = Model.search params[:search], :page => params[:page], :per_page => no_of_page, :order => :sortable_fields
end

In View
<% for person in @Person %>
<%= person.name -%> <%= link_to "show", {:action => 'show', :id => person.id} -%>
<% end %>

<%= will_paginate @person %> # to activate pagination

Create boolean delta in model
ruby script/generate migration add_boolean_data

def self.up
add_column :model, :delta, :boolean, :default => false
end

rake db:migrate

Terminal Commands # run this command to activate delta indexing
rake ts:stop # ts or thinking_sphinx
rake ts:index
rake ts:start

Railscasts
Resources

0 comments:

Post a Comment