# Acts\_as\_ferret MultiIndex

**URL:** <https://www.ruby-forum.com/t/acts-as-ferret-multiindex/113959>\
**Category:** Rails\
**Created:** [September 6, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-multiindex/113959 "2007-09-06T18:11:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindtonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f19dbf/32.png) [@mindtonic](https://www.ruby-forum.com/u/mindtonic)\
**Post date:** [September 6, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-multiindex/113959/1 "2007-09-06T18:11:32Z")

</div>

Hello,

I am working with Ferret and acts\_as\_ferret.

I have 9 different models that I am using for my search capability.  
acts\_as\_ferret is working beautifully when I do searches on a specific  
model.

The problems come when I try to do a `search all` function.

===================

I can easily get a proper collection using the following method:

def search\_all  
@results = []

[Announcement, Event, Group, Job, Need, Offering, Organization,  
Pedia, User].each do |model|  
finds = model.find\_by\_contents(@query)  
finds.each {|find| @results \<\< find } unless finds.blank?  
end

@results = @results.sort\_by { |result| result.ferret\_rank }  
@results.reverse!  
@total = @results.length  
end

===================

The problems come in that I have no way to implement pagination, or  
specify any further details.

I have been reading about Ferret::Index::MultiIndex does anyone know  
how to use it? It would be of great help as it does what I wish.

–OR–

Does anyone have any suggestions for a better way to implement an  
effective search across many different indexes?

Thanks!!

---

<div class="post-metadata">

**Author:** ![mindtonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f19dbf/32.png) [@mindtonic](https://www.ruby-forum.com/u/mindtonic)\
**Post date:** [September 7, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-multiindex/113959/2 "2007-09-07T12:27:34Z")

</div>

Check these posts,  
[http://www.igvita.com/blog/2007/02/20/ferret-pagination-in-rails/](http://www.igvita.com/blog/2007/02/20/ferret-pagination-in-rails/)

[http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial](http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial)

[http://www.frederico-araujo.com/2007/9/6/multi-search-with-ferret](http://www.frederico-araujo.com/2007/9/6/multi-search-with-ferret)

i think it would be easier to modify their versions to match yours. 🙂

good luck

in one of my apps I did this:

```
def search
    if params[:search_article] && params[:search_article][:q] != ""
      limit = 20
      order_by = "title ASC"
      @articles = Article.full_text_search(params[:search_article]
[:q], limit, order_by)
      order_by = "first_name ASC, last_name ASC"
      @users = User.full_text_search(params[:search_article][:q],
limit, order_by)
      order_by = "first_name ASC, last_name ASC"
      @birthdays = Birthday.full_text_search(params[:search_article]
[:q], limit, order_by)
    else
      @birthdays = []
      @users = []
      @articles = []
      flash[:notice] = 'No fue encrontrado nada con esta criteria.'
    end
  end
```

model code:

```
def self.full_text_search(q, limit, order_by)
     return nil if q.nil? or q==""
     results = self.find_by_contents(q,
      :order => order_by,
      :limit => limit
     )
     return results
  end
```
