Xapian search – acts_as_xapian tip (II)
Further to my first post on using acts_as_xapian, I have been trying to make xapian work with pagination and association proxies properly
class Lesson < ActiveRecord::Base # Index user_id as a term in xapian belongs_to :user def self.find_with_xapian(search_term, options={}) ActsAsXapian::Search.new([self], search_term, options).results.collect{|x| x[:model]} end end class User < ActiveRecord::Base has_many :lessons do #Extend this association # Override the method in lessons def self.find_with_xapian(search_term, options={}) ActsAsXapian::Search.new([proxy_reflection.klass], "{proxy_reflection.primary_key_name}:#{proxy_owner.id} #{search_term}", options) .results.collect{|x| x[:model]} end end end
This will ensure that current_user.locations.find_with_xapian will find the correct number of locations, enabling us to work with pagination, etc. What’s left to do is to get the Search object out so that we can get matches_estimated out. I’ll leave out for next time.
This post was brought to you from Software Freedom Day, New Zealand.
October 15th, 2008 at 3:19 am
I’ve implement your proposal.
See: http://groups.google.com/group/acts_as_xapian/t/876e6b02389fbca8 for more information.
Cheers, Lukas
October 19th, 2008 at 1:15 am
Cool! Nice work. Please see my comments on that thread.