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

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/sunspot/rails/searchable.rb', line 421

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
    alias_method :atomic_update, :solr_atomic_update unless method_defined? :atomic_update
    alias_method :atomic_update!, :solr_atomic_update! unless method_defined? :atomic_update!
  end
end

Instance Method Details

#indexable?Boolean

Returns:

  • (Boolean)


501
502
503
504
505
506
507
508
509
510
511
# File 'lib/sunspot/rails/searchable.rb', line 501

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

#solr_atomic_update(updates = {}) ⇒ Object

Updates specified model properties in Solr. Unlike ClassMethods#solr_atomic_update you dont need to pass object id, you only need to pass hash with property changes



457
458
459
# File 'lib/sunspot/rails/searchable.rb', line 457

def solr_atomic_update(updates = {})
  Sunspot.atomic_update(self.class, self => updates)
end

#solr_atomic_update!(updates = {}) ⇒ Object

Updates specified model properties in Solr and immediately commit. See #solr_atomic_update



465
466
467
# File 'lib/sunspot/rails/searchable.rb', line 465

def solr_atomic_update!(updates = {})
  Sunspot.atomic_update!(self.class, self => updates)
end

#solr_indexObject

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.



441
442
443
# File 'lib/sunspot/rails/searchable.rb', line 441

def solr_index
  Sunspot.index(self)
end

#solr_index!Object

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



448
449
450
# File 'lib/sunspot/rails/searchable.rb', line 448

def solr_index!
  Sunspot.index!(self)
end

#solr_more_like_this(*args, &block) ⇒ Object



488
489
490
491
492
493
# File 'lib/sunspot/rails/searchable.rb', line 488

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

#solr_more_like_this_ids(&block) ⇒ Object



495
496
497
498
499
# File 'lib/sunspot/rails/searchable.rb', line 495

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

#solr_remove_from_indexObject

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.



476
477
478
# File 'lib/sunspot/rails/searchable.rb', line 476

def solr_remove_from_index
  Sunspot.remove(self)
end

#solr_remove_from_index!Object

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



484
485
486
# File 'lib/sunspot/rails/searchable.rb', line 484

def solr_remove_from_index!
  Sunspot.remove!(self)
end