Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search through sentences

I have a rails app and have decided to have a search. I have a search textfield and the controller takes care of everything. In my search method

def self.search(search)
    if search
      str = []
      search.split.each do |s|
        a = find(:all, :conditions => ['title or content LIKE ?', "%#{s}%" ])
        str = (str + a).uniq
      end

    else
      find(:all)
    end
  end

I want to be able to handle multiple word searches. If you remove the each...loop it works fine with 1 word searches. Anyways, I would like to find the related posts for each word that is searched and return a combination of that.

Ex. If someone searches "Greatest Player" it will return all instances of posts that have the title or content "Greatest" and any that have the title or content "Player"

like image 412
Vasseurth Avatar asked Feb 27 '26 23:02

Vasseurth


1 Answers

You most likely should be looking at full text searching:

  • Full Text Searching with Rails
  • http://en.wikipedia.org/wiki/Full_text_search
like image 89
Jeff Perrin Avatar answered Mar 01 '26 13:03

Jeff Perrin