title: Multiple keywords database search
body: <p>I am currently using scopes in my model to perform searches within a database.  I can stack these scopes and it will output results matching all parameters.  </p>
  
  <pre><code>scope :search_between, lambda{|begin_date, end_date|
    where "sub.date BETWEEN ? AND ?", begin_date, end_date
  }
  </code></pre>
  
  <p>What I am having trouble with is integrating a keywords search that will search the entire database and output the results that contain the sum of the keywords.  I would like to do something like this (displayed for simplicity):</p>
  
  <pre><code>scope :keywords, lambda{|search|
    search.chomp.split(/,\s*/) do |item|
      where "date like ? or city like ? or state like ?", "%#{item}%" and
      where "date like ? or city like ? or state like ?", "%#{item}%" and
      where "date like ? or city like ? or state like ?", "%#{item}%"
    end
  }
  </code></pre>
  
  <p>I am currently using something like this to take care of searching multiple columns:</p>
  
  <pre><code>scope :keywords, lambda{|search|
    search.chomp.split(/,\s*/) do |item|
      where(Sub.column_names.map {|cn| "#{cn} like ?" }.join("or "), "%#{item}%"]  Sub.column_names.size)).join(' AND ')
    end
  } 
  </code></pre>
  
  <p>My problem is that I want to do multiple "where()'s" in the scope. Is it possible and if so, how?</p>