Here’s a summary of what I have:
===
class Person < ActiveRecord::Base
acts_as_ferret :additional_fields => [:organisation_names,
:preferred_address_address, :primary_organisation_name]
has_many :person_organisations, :dependent => true
has_many :organisations, :through => :person_organisations
belongs_to :preferred_address, :foreign_key => ‘preferred_address_id’,
:class_name => ‘Address’
belongs_to :primary_organisation, :foreign_key =>
‘primary_organisation_id’, :class_name => ‘Organisation’
def primary_organisation_name
return primary_organisation.name
end
def preferred_address_address
return preferred_address.address
end
def organisation_names
organisations.collect { |organisation| organisation.name }.join ’ ’
end
def self.full_text_search(q, options = {})
return nil if q.nil? or q == “”
default_options = {:limit => 10, :page => 1}
options = default_options.merge options
options[:offset] = options[:limit] * (options.delete(:page).to_i-1)
results = Person.find_by_contents(q, options)
return [results.total_hits, results]
end
end
class Organisation < ActiveRecord::Base
acts_as_ferret :additional_fields => [:address_address]
belongs_to :address
has_many :documents
has_many :person_organisations, :dependent => true
has_many :persons, :through => :person_organisations
def address_address
return address.address
end
def self.full_text_search(q, options = {})
return nil if q.nil? or q==""
default_options = {:limit => 10, :page => 1}
options = default_options.merge options
options[:offset] = options[:limit] * (options.delete(:page).to_i-1)
results = Organisation.find_by_contents(q, options)
return [results.total_hits, results]
end
end
class Document < ActiveRecord::Base
acts_as_ferret :additional_fields => [:organisation_name,
:topic_titles]
has_many :document_topics, :dependent => true
has_many :topics, :through => :document_topics
belongs_to :organisation
def topic_titles
topics.collect { |topic| topic.title }.join ’ ’
end
def organisation_name
return organisation.name
end
def self.full_text_search(q, options = {})
return nil if q.nil? or q == “”
default_options = {:limit => 10, :page => 1}
options = default_options.merge options
options[:offset] = options[:limit] * (options.delete(:page).to_i-1)
results = Document.find_by_contents(q, options)
return [results.total_hits, results]
end
end