Skip to content

Commit

Permalink
Added support for multiple cores and additional standard activerecord…
Browse files Browse the repository at this point in the history
… query options
  • Loading branch information
oxtralite committed Jun 15, 2009
1 parent 9c7c8b0 commit 2c7d113
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/acts_as_solr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
module ActsAsSolr

class Post
def self.execute(request)
def self.execute(request, core = nil)
begin
if File.exists?(RAILS_ROOT+'/config/solr.yml')
config = YAML::load_file(RAILS_ROOT+'/config/solr.yml')
Expand All @@ -49,6 +49,7 @@ def self.execute(request)
else
url = 'http://localhost:8982/solr'
end
url += "/" + core if !core.nil?
connection = Solr::Connection.new(url)
return connection.send(request)
rescue
Expand Down
6 changes: 4 additions & 2 deletions lib/acts_as_solr/parser_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ParserMethods

# Method used by mostly all the ClassMethods when doing a search
def parse_query(query=nil, options={}, models=nil)
valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator, :include, :lazy]
valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator, :include, :lazy, :joins, :select, :core]
query_options = {}

return nil if (query.nil? || query.strip == '')
Expand Down Expand Up @@ -79,7 +79,7 @@ def parse_query(query=nil, options={}, models=nil)
query_options[:query] << ';' << replace_types([order], false)[0]
end

ActsAsSolr::Post.execute(Solr::Request::Standard.new(query_options))
ActsAsSolr::Post.execute(Solr::Request::Standard.new(query_options), options[:core])
rescue
raise "There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}"
end
Expand Down Expand Up @@ -125,6 +125,8 @@ def find_objects(ids, options, configuration)
conditions = [ "#{self.table_name}.#{primary_key} in (?)", ids ]
find_options = {:conditions => conditions}
find_options[:include] = options[:include] if options[:include]
find_options[:select] = options[:select] if options[:select]
find_options[:joins] = options[:joins] if options[:joins]
result = reorder(self.find(:all, find_options), ids)
else
ids
Expand Down

0 comments on commit 2c7d113

Please sign in to comment.