# Help with Model find

**URL:** <https://www.ruby-forum.com/t/help-with-model-find/127763>\
**Category:** Rails\
**Created:** [February 1, 2008, 3:01am UTC](https://www.ruby-forum.com/t/help-with-model-find/127763 "2008-02-01T03:01:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skoppy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@skoppy](https://www.ruby-forum.com/u/skoppy)\
**Post date:** [February 1, 2008, 3:01am UTC](https://www.ruby-forum.com/t/help-with-model-find/127763/1 "2008-02-01T03:01:16Z")

</div>

I am trying to set up a simple search on my site. First I am grabbing  
the string that was entered into the text field and searching through  
my article titles.

Next I am splitting the string into an array so i can separate the  
search string into individual keywords. What I would like to do now  
is loop through that array of keywords and pull in any articles where  
the body text contains the keyword.

I have been testing this in the console for my app. So far it looks  
like the SQL query is correct but no articles are being added to my  
array of articles.

here is a copy of my search action code:

def search  
# Collect full query from params, then search article titles for a  
match on the full query string  
@query = params[:query]  
by\_title = Article.find(:all, :conditions =\> [ “active = ? AND  
title like ?”, true, “%#{params[:query]}%” ])  
# Split the query string into an array of keywords based on  
whitespace  
keywords = @query.split(/\s+/)  
by\_keyword = []  
keywords.each { |term| by\_keyword | Article.find(:all, :conditions  
=\> [“active = ? AND body LIKE ?”, true, “%#{term}%”]) }  
@articles = by\_title | by\_keyword  
end

Does anyone have any suggestions?

---

<div class="post-metadata">

**Author:** ![skoppy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@skoppy](https://www.ruby-forum.com/u/skoppy)\
**Post date:** [February 1, 2008, 5:17am UTC](https://www.ruby-forum.com/t/help-with-model-find/127763/2 "2008-02-01T05:17:53Z")

</div>

Have you thought about using Ferret and the acts\_as\_ferret plugin?

---

<div class="post-metadata">

**Author:** ![skoppy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@skoppy](https://www.ruby-forum.com/u/skoppy)\
**Post date:** [February 1, 2008, 7:17am UTC](https://www.ruby-forum.com/t/help-with-model-find/127763/3 "2008-02-01T07:17:00Z")

</div>

I have thought about that but I think that is going to be a little  
while down the road. We’re trying to launch by next week so for now  
we’re just trying to come up with a simple search.
