Forum: Ruby on Rails Site Search

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1f8292347187d0cb3767d3e860926924?d=identicon&s=25 Scott (Guest)
on 2008-10-20 11:07
(Received via mailing list)
Hello, if anyone can help implement/develop a site's SEARCH feature
please reply. Thanks.
29ebf90af6107d2eb39b587c7972639c?d=identicon&s=25 Mukund (Guest)
on 2008-10-20 11:20
(Received via mailing list)
Why don't you use Google or Yahoo!'s site search feature?  It is as
simple as plugging in a javascript.

http://code.google.com/apis/customsearch/
2d8132658d56e51f19ace1c68e48b6aa?d=identicon&s=25 Thorsten Mueller (thorsten)
on 2008-10-20 13:30
(Received via mailing list)
> Hello, if anyone can help implement/develop a site's SEARCH feature
> please reply. Thanks.

Mean something like fulltext search on your database content?

I would use sphinx for that.
Together with ultrasphinx that would take just a few lines of code
(ok, a few more to get the config files right)

that would be all you need in the model:

  is_indexed :fields => [:title, :text, :updated_at, :created_at],
             :conditions => "draft = 0",
             :delta => {:field => "updated_at"}

this would be the controller:

  def show
    @search = Ultrasphinx::Search.new(:query => params[:keywords],
                                      :page => 1,
                                      :per_page => 50,
                                      :class_name => "pages",
                                      :sort_mode => "relevance")
    @results = @search.excerpt
  end

the searchbox for the view:

        <% form_tag(search_path, :method => :get) do %>
          <input type="submit" class="submit" value="zoek" /><input
name="keywords" class="keywords" value=<%= params[:keywords] %> />
        <% end %>

ok, there would be lots(!) of further options and features,
what to index, when to index and so on, but this is a working
example i took from one of our sites.
This topic is locked and can not be replied to.