# Search

**URL:** <https://www.ruby-forum.com/t/search/120889>\
**Category:** Rails\
**Created:** [November 21, 2007, 2:02pm UTC](https://www.ruby-forum.com/t/search/120889 "2007-11-21T14:02:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [November 21, 2007, 2:02pm UTC](https://www.ruby-forum.com/t/search/120889/1 "2007-11-21T14:02:27Z")

</div>

what will be the code for ‘search’ option in page and after that  
search result will be shown in next page

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [November 21, 2007, 3:46pm UTC](https://www.ruby-forum.com/t/search/120889/2 "2007-11-21T15:46:26Z")

</div>

Hi Joe,

you are asking something very wide, i suggest you go ahead and read  
some tutorials and books (try [http://pdfetch.com](http://pdfetch.com)) to find some.  
there are MILLIONS of examples on how to implement a search mechanism.

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [November 22, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/search/120889/3 "2007-11-22T13:24:32Z")

</div>

If you are asking for full text search then you can use ferret.  
You can find a brief tutorial on how to use it here

> **[Full text search using Ferret (acts\_as\_ferret) with rails](https://nasir.wordpress.com/2007/10/25/full-text-search-using-ferret-acts_as_ferret-with-rails/)**
>
> I recently started working with acts\_as\_ferret so I thought to put together a little how to: Assuming you already have ruby on rails environment set up 1) To install it run gem install ferret this …

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [November 22, 2007, 2:30pm UTC](https://www.ruby-forum.com/t/search/120889/4 "2007-11-22T14:30:51Z")

</div>

On Nov 22, 4:23 am, nas [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If you are asking for full text search then you can use ferret.  
> You can find a brief tutorial on how to use it herehttp://nasir.wordpress.com/2007/10/25/full-text-search-using-ferret-a…
> 
> On Nov 21, 1:01 pm, joe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > what will be the code for ‘search’ option in page and after that  
> > search result will be shown in next page

most of my experience has been with ferret, but I’ve seen production  
sites are also using sol/acts\_as\_solr and Sphinx/sphincter:

[http://api.railsfreaks.com/projects/acts\_as\_solr/](http://api.railsfreaks.com/projects/acts_as_solr/)

> **[Sphinx | Open Source Search Engine](http://www.sphinxsearch.com/)**
>
> Sphinx is an open source full text search server, designed with performance, relevance (search quality),
> and integration simplicity in mind. Sphinx lets you either batch index and search data stored in files, an SQL database, NoSQL storage --
> or...

also tsearch/Postgres

gdluck!

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [November 25, 2007, 9:18am UTC](https://www.ruby-forum.com/t/search/120889/5 "2007-11-25T09:18:03Z")

</div>

joe,

The issue that I have found with the search requirement, is in  
actually identifying the type of search that you want to carry out.  
Start by narrowing down the specifics of what you want to achieve, and  
then if you need help on that, ask again for someone to point you in  
the right direction. If you just want to be able to select a single  
record from the database, then the CRUD type of approach is to list  
all records in the index action, giving each record a unique link  
based on its id. Clicking the link then sends that id to the show  
method. Rails routes and particularly the restful resource follows  
this approach so that it is easy to build the paths. I am just  
getting my head around this fully myself.

Regarding search in general, the types of things I consider when  
needing to implement search or look up are the following.

1. What sort of result am I looking for. A list, or a single  
match.
2. What fields/information are relevant to the search
3. If there are multiple fields, should they be searched  
simultaneously, or only one at a time.
4. If the reuslt is to be a list then you probably want a filter that  
will sift the data by some search criteria.
5. A single result will either need a unique key, or will need a  
means of choosing the actual required result from a list or drop down  
etc.
6. IS the search to be interactive using an ajax call, or will just  
return the results via a new page (your request suggest you are just  
looking for the latter.)

I have tried a number of types of lookups for my applications, I am  
tending to home in on two main types.

The first is a filter on an index page. The simplest of these is  
basic pagination, then adding to that the ability to filter by a  
specific field, eg supplier name, or location, or type etc. That  
field may be free text field or a drop down, and can offer partial  
field look up. Building the filter into a form, allows the fields to  
be passed to the server.

The second approach I use is to offer a display of a blank record,  
with auto-complete fields for the fields I wish to allow to be used as  
lookups. Then typing into any of those fields will dynamically return  
a list of possible matches for the user to select. Write your own  
selection method in the controller to update the whole object.

I havn’t tried using Ferret yet, since it seems to me that it builds a  
system wide search for indexing, which for my requirements is overkill  
and added complexity. If I am missing a point about Ferret then maybe  
someone might enlighten me.

Define your search requirement more tightly, and then if you are still  
looking for help in how to implement it, post a more specific request  
and I am sure you will get more help.

Tonypm
