# Best way and practices to implement search

**URL:** <https://www.ruby-forum.com/t/best-way-and-practices-to-implement-search/158175>\
**Category:** Rails\
**Created:** [January 20, 2009, 5:21am UTC](https://www.ruby-forum.com/t/best-way-and-practices-to-implement-search/158175 "2009-01-20T05:21:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gustav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@gustav](https://www.ruby-forum.com/u/gustav)\
**Post date:** [January 20, 2009, 5:21am UTC](https://www.ruby-forum.com/t/best-way-and-practices-to-implement-search/158175/1 "2009-01-20T05:21:43Z")

</div>

I’m trying to implement a search engine to look thru some stuff in my  
models. Is there a way I can do something similar to Model.find, but  
that is more “forgiving” (poor spelling etc.) and also leverages the  
relationships that I’ve specified (so that it also searches has\_many or  
belongs\_to models)?

Do you have any suggestions on how to implement this. Are there any good  
plugins or do I have to write it by myself?

Thanks!

---

<div class="post-metadata">

**Author:** ![gustav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@gustav](https://www.ruby-forum.com/u/gustav)\
**Post date:** [January 20, 2009, 6:17am UTC](https://www.ruby-forum.com/t/best-way-and-practices-to-implement-search/158175/2 "2009-01-20T06:17:41Z")

</div>

Thinking Sphinx seems to be way to go for a configurable real text  
search engine. Here’s a [railscasts.com](http://railscasts.com) screencast with links:

> **[\#120 Thinking Sphinx - RailsCasts](http://railscasts.com/episodes/120-thinking-sphinx)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Sheldon Finlay

---

<div class="post-metadata">

**Author:** ![gustav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@gustav](https://www.ruby-forum.com/u/gustav)\
**Post date:** [January 20, 2009, 6:32am UTC](https://www.ruby-forum.com/t/best-way-and-practices-to-implement-search/158175/3 "2009-01-20T06:32:18Z")

</div>

Sheldon Finlay wrote:

> Thinking Sphinx seems to be way to go for a configurable real text  
> search engine. Here’s a [railscasts.com](http://railscasts.com) screencast with links:
> 
> [#120 Thinking Sphinx - RailsCasts](http://railscasts.com/episodes/120-thinking-sphinx)

I liked Sphinx, and wrote it up, but it has turned out to be a real itch  
to  
maintain.

Sphinx requires its own daemon running in another process. That makes  
unit tests  
extremely difficult to keep clean. They must configure data, start the  
daemon,  
run it reliably, and stop it on command.

This is silly in modern Web architecture, because Mongrel (or mod-rails,  
or  
Passenger) already are daemons, so a search system could simply ride  
around  
inside your Ruby vm as a @@class\_instance of some controller. Its index  
would  
persist in memory long enough to be efficient at search time - that is  
the point  
of a persistent daemon process.

I intend to look at SearchLogic as soon as possible - formerly  
“Searchgasm” - to  
see if it’s lighter than Sphinx. Over time, all of our Sphinx unit tests  
have  
“decayed”. They would fail for no reason, out of the blue, on the test  
server,  
when we were busy working on something else, and we would comment them  
out.  
Almost none are still online, and that is a very bad omen.

Sphinx’s authors could simply provide an in-memory version…

–  
Phlip
