# Site Search

**URL:** <https://www.ruby-forum.com/t/site-search/151317>\
**Category:** Rails\
**Created:** [October 20, 2008, 11:07am UTC](https://www.ruby-forum.com/t/site-search/151317 "2008-10-20T11:07:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [October 20, 2008, 11:07am UTC](https://www.ruby-forum.com/t/site-search/151317/1 "2008-10-20T11:07:53Z")

</div>

Hello, if anyone can help implement/develop a site’s SEARCH feature  
please reply. Thanks.

---

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [October 20, 2008, 11:20am UTC](https://www.ruby-forum.com/t/site-search/151317/2 "2008-10-20T11:20:51Z")

</div>

Why don’t you use Google or Yahoo!'s site search feature? It is as  
simple as plugging in a javascript.

> **[Programmable Search Engine  |  Google for Developers](https://developers.google.com/custom-search/?csw=1)**
>
> Build and manage a search engine for your site.

---

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [October 20, 2008, 1:30pm UTC](https://www.ruby-forum.com/t/site-search/151317/3 "2008-10-20T13:30:41Z")

</div>

> 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.
