Restricting Attributes for Ferret Searches Across Tables

Hi, suppose I am creating an ‘advanced search’ page that enables
field-specific searches for fields from two different tables.

The search fields for one of the tables is implemented as follows:

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

This works just fine. However, if a field from a second table is added,
the ‘inject’ method will kill all of the search results because the
attributes that the arrays contain are different, and the ‘set
intersection’ is blank.

Is there a way to chop off the attributes in the arrays and keep only
one specified attribute common to both tables (such as ‘business_id’),
so that the set intersection works?

Thank you for your help!

John