# Rails association and multiple indexes

**URL:** <https://www.ruby-forum.com/t/rails-association-and-multiple-indexes/73155>\
**Category:** Ferret\
**Created:** [October 22, 2006, 2:32am UTC](https://www.ruby-forum.com/t/rails-association-and-multiple-indexes/73155 "2006-10-22T02:32:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![papipo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@papipo](https://www.ruby-forum.com/u/papipo)\
**Post date:** [October 22, 2006, 2:32am UTC](https://www.ruby-forum.com/t/rails-association-and-multiple-indexes/73155/1 "2006-10-22T02:32:12Z")

</div>

Hi!

If I have two models, Product and Manufacturer, of course Product  
belongs\_to :manufacturer.

A search engine would allow a user to look for a product by its name or  
manufacturer. Is it better to define a method like:

def searchable\_field  
“#{name} #{manufacturer.name}”  
end

and add it as indexable field (acts\_as\_ferret :fields =\>  
[‘searchable\_field’])…

Or maybe that it is more advisable to index different fields:

Product \< ActiveRecord::Base  
acts\_as\_ferret :fields =\> [‘name’, ‘manufacturer\_name’]

```
def manufacturer_name
  "#{manufacturer.name}"
end

```

end

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![papipo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@papipo](https://www.ruby-forum.com/u/papipo)\
**Post date:** [October 22, 2006, 12:44pm UTC](https://www.ruby-forum.com/t/rails-association-and-multiple-indexes/73155/2 "2006-10-22T12:44:27Z")

</div>

On 10/22/06, Rodrigo A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> “#{manufacturer.name}”  
> end  
> end
> 
> Thanks in advance.

Hi Rodrigo,

It’s better to index individual fields. You can easily search both  
fields like this:

```
"name|manufacturer_name:(#{query})"

```

I can’t really think of any advantages to putting buth fields into the  
one search field.
