You should use something like a textual search. You can search for postgres textual search, elasticsearch, solr. Or even if you want use a individual query that hits the database you should try something like:
SELECT * FROM TABLE_NAME LIKE %“STRING_HERE”%
Sorry about the caps my intention was just get more highlight.
I think you can frame your WHERE clause by splitting the search field
value on a particular database field. e.g.
Assume your query is passed in search parameter. So params[:search] will
access the string passed by the search form. Lets take the example of
Airport and name.
#get the parameter search and split it on blank spaces.
search_str = params[:search]
search_arr = search_str.split(' ')
#Loop through the search_arr and form a where_clause
where_clause = ''
search_arr.each_with_index do |s, i|
where_clause += ' AND ' unless i == 0
where_clause += "name LIKE '%" + s + "%'"
end
#Now use where method of ActiveRecord to fetch the records matching the
criteria.
airports = Airport.where(where_clause)
airport will have all the records matching thew criteria of name from
search form. Hope this will help.