Search in Specific Fields of a Table

Hi, I’m new to Ferret and ROR, and was wondering how one would implement
an ‘advanced search’ page with a series of search fields, where each
field only searches the corresponding field in the table (not one search
field searching an entire table). Are there any options/conditions that
can be passed to find_by_contents?

Thank you,
John

John Mccarthy wrote:

Hi, I’m new to Ferret and ROR, and was wondering how one would implement
an ‘advanced search’ page with a series of search fields, where each
field only searches the corresponding field in the table (not one search
field searching an entire table). Are there any options/conditions that
can be passed to find_by_contents?

Thank you,
John

Hi, I found the answer to the question I asked above, if anyone else is
trying to implement an advanced search with search fields targeted to a
specific table field, here is one way that works:

Example table has two ‘Business’ table fields: ‘about_business’,
‘services’

q = []

unless params[:about_business].blank?
query_about_business =
Business.find_by_contents(“about_business:#{params[:about_business]}”,
:limit => :all)
q << query_about_business
end

unless params[:services].blank?
query_services =
Business.find_by_contents(“services:#{params[:services]}”, :limit =>
:all)
q << query_services
end

if q.empty?
[]
else
queries = q.inject{|array1, array2| array1 & array2}
@pages, @users = paginate(queries.collect { |spec| spec.user })
end