Searching a database

I realize this is an SQL problem but figured a lot of people using ROR
have came across this before. I pulled apart the string that was
entered into the search form and stored it in textArray. The problem I
am having is when I include commmon words such as the, near, view and so
on into the search field I end up with zero results. when I only search
for less common words such as rocky and argentina for example the search
works fine. at first I thought that maybe it was generating too many
results and was screwing up but when i search for rocky it works and
when i search for near rocky it doesnt.

I realize the code might not be the most efficient but here it is…

@searches_pages, @searches = paginate(:searches, :per_page => 10,
:conditions => getSearch(textArray,params[:country]))

def getSearch(textArray,selectedCountry )
result = []
string = “”
if selectedCountry != “Optional Field”
string << "country = (?) and "
end
textArray.each do |x|
if textArray[textArray.length - 1] == x
string << "match(country,caption, keywords, notes) against
(?) "
else
string << "match(country, caption, keywords, notes) against
(?) and "
end
end
result << string
if selectedCountry != “Optional Field”
result << selectedCountry
end
textArray.each do |x|
result << x
end
result
end

Im not sure if i supplied enough information but I am trying to finish
this project soon so any type of responses would help. Also, if there
is an easier way to do an sql search based off of what is entered into
the search field please let me know. The reason I did this is because I
wasn’t sure how many words the user would be entering into the field.
And without knowing this I could not hard code the conditions => so I
wrote a helper method.

Chris H. wrote:

I realize this is an SQL problem but figured a lot of people using ROR
have came across this before. I pulled apart the string that was
entered into the search form and stored it in textArray. The problem I
am having is when I include commmon words such as the, near, view and so
on into the search field I end up with zero results. when I only search
for less common words such as rocky and argentina for example the search
works fine. at first I thought that maybe it was generating too many
results and was screwing up but when i search for rocky it works and
when i search for near rocky it doesnt.

You might want to look into using Ferret.

http://projects.jkraemer.net/acts_as_ferret/


Michael W.