lib/flare/session.rb in flare-1.4.4 vs lib/flare/session.rb in flare-1.6.1

- old
+ new

@@ -1,34 +1,41 @@ module Flare class Session RESULT_LIMIT = 1000 PER_PAGE = 16 - def connection - @connection ||= RSolr.connect(:url => Flare::Configuration.client.url) + def initialize(url) + @connection = RSolr.connect(:url => url) end - + + attr_reader :connection + delegate :commit, :optimize, :to => :connection def search_for_ids(*args) + options = args.extract_options! + ar_options = { :include => options.delete(:include) } response = execute(*args) Flare::Collection.ids_from_response(response, response[:request][:page], response[:request][:per_page], response[:request]) end def search(*args) - response = execute(*args) - Flare::Collection.create_from_response(response, response[:request][:page], response[:request][:per_page], response[:request]) + options = args.extract_options! + ar_options = { :include => options.delete(:include) } + response = execute(options) + Flare::Collection.create_from_response(response, response[:request][:page], response[:request][:per_page], ar_options) end def count(*args) execute(*args)[:response][:numFound] end def index(*objects) objects = ensure_searchable(objects) objects.collect(&:to_solr_doc).each do |doc| - connection.update(RSolr::Message::Generator.new.add(doc[:fields], doc[:attributes])) + # connection.update(RSolr::Message::Generator.new.add(doc[:fields], doc[:attributes])) + connection.update(RSolr::Message::Builder.new.add(doc[:fields], doc[:attributes])) # connection.add(doc[:fields], doc[:attributes]) end end def index!(*objects) @@ -59,11 +66,11 @@ private def execute(*args) options = args.extract_options! - options.assert_valid_keys(:q, :fq, :types, :page, :per_page, :limit, :fl, :sort, :facet, :mlt) + options.assert_valid_keys(:q, :fq, :types, :page, :per_page, :limit, :fl, :sort, :facet, :mlt, :mm) options.reverse_merge!({ :page => 1, :per_page => PER_PAGE, :limit => RESULT_LIMIT, @@ -94,9 +101,14 @@ end if options[:mlt] query['mlt'] = true query['mlt.fl'] = Array(options[:mlt][:fields]).flatten.join(',') + query['mlt.count'] = options[:mlt][:count] if options[:mlt][:count] + end + + if options[:mm] + query['mm'] = options[:mm] end if options[:types] query[:fq] << Array(options[:types]).map {|type| "type:#{type}"}.join(" OR ") end