# Find multiple strings collected in an array

**URL:** <https://www.ruby-forum.com/t/find-multiple-strings-collected-in-an-array/191191>\
**Category:** Rails\
**Created:** [July 7, 2010, 11:13am UTC](https://www.ruby-forum.com/t/find-multiple-strings-collected-in-an-array/191191 "2010-07-07T11:13:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c77e96/32.png) [@sachin](https://www.ruby-forum.com/u/sachin)\
**Post date:** [July 7, 2010, 11:13am UTC](https://www.ruby-forum.com/t/find-multiple-strings-collected-in-an-array/191191/1 "2010-07-07T11:13:13Z")

</div>

Hello Everybody,  
I am have an advance search form in which i have a field called :name  
in which user can enter 1 or multiple words.  
When there is more than 1 word, i am splitting that string and  
collecting it in to an array.

@collect = Array.new  
@collect \<\< name.split( )

this gives me an array [“John”, “whatever”, “anyother”]  
how can i find each item in the array in my rails app?

help appreciated.

Thanks in Advance

- S

---

<div class="post-metadata">

**Author:** ![sachin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c77e96/32.png) [@sachin](https://www.ruby-forum.com/u/sachin)\
**Post date:** [July 7, 2010, 7:19pm UTC](https://www.ruby-forum.com/t/find-multiple-strings-collected-in-an-array/191191/2 "2010-07-07T19:19:19Z")

</div>

> how can i find each item in the array in my rails app?  
> This isn’t specific enough to know for sure what you want, but I’m going  
> to assume that you want to search a specific model on a specific field  
> for each of those terms… if it was me, I would do it like this.  
> Assume a model of Widget that has a ‘title’ string field…

# in my controller action…

# with params[:name] being passed in via the form…

def search  
@widgets = Widget.all(:conditions =\> [“title IN (?)”,  
params[:name].split(/[,]/)])  
end

That would let you type in “John, whatever anyother” and have it work  
both on spaces and commas. It’s not very efficient though as it’s an  
_exact_ match so If you have a widget named ‘Jon’ it won’t find it.

You may want to look into sphinx or whatever full text search options  
your database provides…

-philip
