lib/sunspot.rb in outoftime-sunspot-0.8.9 vs lib/sunspot.rb in outoftime-sunspot-0.9.0

- old
+ new

@@ -1,11 +1,20 @@ -gem 'solr-ruby' -require 'solr' +begin + require 'time' + require 'date' + require 'rsolr' +rescue LoadError + require 'rubygems' + require 'rsolr' +end + require File.join(File.dirname(__FILE__), 'light_config') -%w(adapters configuration setup field data_extractor indexer - query search facet facet_row session type util dsl).each do |filename| +%w(util adapters configuration setup composite_setup field field_factory + data_extractor indexer query search facet facet_row instantiated_facet + instantiated_facet_row date_facet date_facet_row query_facet query_facet_row + session type dsl).each do |filename| require File.join(File.dirname(__FILE__), 'sunspot', filename) end # # The Sunspot module provides class-method entry points to most of the @@ -280,12 +289,12 @@ # # Sunspot.search(Post) do |query| # query.with(:blog_id, @current_blog.id) # end # - # See Sunspot::DSL::Scope and Sunspot::DSL::Query for the full API presented - # inside the block. + # See Sunspot::DSL::Search, Sunspot::DSL::Scope, Sunspot::DSL::FieldQuery + # and Sunspot::DSL::Query for the full API presented inside the block. # def search(*types, &block) session.search(*types, &block) end @@ -317,10 +326,34 @@ # def remove! session.remove!(*objects) end + # + # Remove an object from the index using its class name and primary key. + # Useful if you know this information and want to remove an object without + # instantiating it from persistent storage + # + # ==== Parameters + # + # clazz<Class>:: Class of the object, or class name as a string or symbol + # id:: + # Primary key of the object. This should be the same id that would be + # returned by the class's instance adapter. + # + def remove_by_id(clazz, id) + session.remove_by_id(clazz, id) + end + + # + # Remove an object by class name and primary key, and immediately commit. + # See #remove_by_id and #commit + # + def remove_by_id!(clazz, id) + session.remove_by_id!(clazz, id) + end + # Remove all objects of the given classes from the index. There isn't much # use for this in general operations but it can be useful for maintenance, # testing, etc. If no arguments are passed, remove everything from the # index. # @@ -348,11 +381,32 @@ # classes for which to remove all instances from the index def remove_all!(*classes) session.remove_all!(*classes) end + # + # Process all adds in a batch. Any Sunspot adds initiated inside the block + # will be sent in bulk when the block finishes. Useful if your application + # initiates index adds from various places in code as part of a single + # operation; doing a batch add will give better performance. # + # ==== Example + # + # Sunspot.batch do + # post = Post.new + # Sunspot.add(post) + # comment = Comment.new + # Sunspot.add(comment) + # end + # + # Sunspot will send both the post and the comment in a single request. + # + def batch(&block) + session.batch(&block) + end + + # # True if documents have been added, updated, or removed since the last # commit. # # ==== Returns # @@ -382,11 +436,23 @@ # # Resets the singleton session. This is useful for clearing out all # static data between tests, but probably nowhere else. # - def reset! - @session = Session.new(session.config) + # ==== Parameters + # + # keep_config<Boolean>:: + # Whether to retain the configuration used by the current singleton + # session. Default false. + # + def reset!(keep_config = false) + config = + if keep_config + session.config + else + Configuration.build + end + @session = Session.new(config) end private #