Module: Sunspot::Rails::Searchable::InstanceMethods

Defined in:
sunspot_rails/lib/sunspot/rails/searchable.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(base)

:nodoc:



353
354
355
356
357
358
359
360
361
362
# File 'sunspot_rails/lib/sunspot/rails/searchable.rb', line 353

def self.included(base) #:nodoc:
  base.module_eval do
    alias_method :index, :solr_index unless method_defined? :index
    alias_method :index!, :solr_index! unless method_defined? :index!
    alias_method :remove_from_index, :solr_remove_from_index unless method_defined? :remove_from_index
    alias_method :remove_from_index!, :solr_remove_from_index! unless method_defined? :remove_from_index!
    alias_method :more_like_this, :solr_more_like_this unless method_defined? :more_like_this
    alias_method :more_like_this_ids, :solr_more_like_this_ids unless method_defined? :more_like_this_ids
  end
end

Instance Method Details

- (Boolean) indexable?

Returns:

  • (Boolean)


414
415
416
417
418
419
420
421
422
423
424
# File 'sunspot_rails/lib/sunspot/rails/searchable.rb', line 414

def indexable?
  # options[:if] is not specified or they successfully pass
  if_passes = self.class.sunspot_options[:if].nil? ||
              constraint_passes?(self.class.sunspot_options[:if])

  # options[:unless] is not specified or they successfully pass
  unless_passes = self.class.sunspot_options[:unless].nil? ||
                  !constraint_passes?(self.class.sunspot_options[:unless])

  if_passes and unless_passes
end

- (Object) solr_index

Index the model in Solr. If the model is already indexed, it will be updated. Using the defaults, you will usually not need to call this method, as models are indexed automatically when they are created or updated. If you have disabled automatic indexing (see ClassMethods#searchable), this method allows you to manage indexing manually.



371
372
373
# File 'sunspot_rails/lib/sunspot/rails/searchable.rb', line 371

def solr_index
  Sunspot.index(self)
end

- (Object) solr_index!

Index the model in Solr and immediately commit. See #index



378
379
380
# File 'sunspot_rails/lib/sunspot/rails/searchable.rb', line 378

def solr_index!
  Sunspot.index!(self)
end

- (Object) solr_more_like_this(*args, &block)



401
402
403
404
405
406
# File 'sunspot_rails/lib/sunspot/rails/searchable.rb', line 401

def solr_more_like_this(*args, &block)
  options = args.extract_options!
  self.class.solr_execute_search(options) do
    Sunspot.new_more_like_this(self, *args, &block)
  end
end

- (Object) solr_more_like_this_ids(&block)



408
409
410
411
412
# File 'sunspot_rails/lib/sunspot/rails/searchable.rb', line 408

def solr_more_like_this_ids(&block)
  self.class.solr_execute_search_ids do
    solr_more_like_this(&block)
  end
end

- (Object) solr_remove_from_index

Remove the model from the Solr index. Using the defaults, this should not be necessary, as models will automatically be removed from the index when they are destroyed. If you disable automatic removal (which is not recommended!), you can use this method to manage removal manually.



389
390
391
# File 'sunspot_rails/lib/sunspot/rails/searchable.rb', line 389

def solr_remove_from_index
  Sunspot.remove(self)
end

- (Object) solr_remove_from_index!

Remove the model from the Solr index and commit immediately. See #remove_from_index



397
398
399
# File 'sunspot_rails/lib/sunspot/rails/searchable.rb', line 397

def solr_remove_from_index!
  Sunspot.remove!(self)
end