Module: ActsAsFerret::RdigAdapter::ClassMethods

Defined in:
lib/acts_as_ferret/rdig_adapter.rb

Instance Method Summary collapse

Instance Method Details

#configure_rdigObject

unfortunately need to modify global RDig.configuration because it’s used everywhere in RDig



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/acts_as_ferret/rdig_adapter.rb', line 83

def configure_rdig
  # back up original config
  old_logger = RDig.logger
  old_cfg = RDig.configuration.dup
  RDig.logger = ActsAsFerret.logger
  rdig_configuration[:crawler].each { |k,v| RDig.configuration.crawler.send :"#{k}=", v } if rdig_configuration[:crawler]
  if ce_config = rdig_configuration[:content_extraction]
    RDig.configuration.content_extraction = OpenStruct.new( :hpricot => OpenStruct.new( ce_config ) )
  end
  yield
ensure
  # restore original config
  RDig.configuration.crawler = old_cfg.crawler
  RDig.configuration.content_extraction = old_cfg.content_extraction
  RDig.logger = old_logger
end

#find_for_id(id) ⇒ Object



107
108
109
# File 'lib/acts_as_ferret/rdig_adapter.rb', line 107

def find_for_id(id)
  new id
end

#find_with_ferret(q, options = {}, find_options = {}) ⇒ Object

overriding aaf to enforce loading page title and content from the ferret index



102
103
104
105
# File 'lib/acts_as_ferret/rdig_adapter.rb', line 102

def find_with_ferret(q, options = {}, find_options = {})
  options[:lazy] = true
  super
end

#records_for_rebuild(batch_size = 1000, &block) ⇒ Object

overriding aaf to return the documents fetched via RDig



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/acts_as_ferret/rdig_adapter.rb', line 60

def records_for_rebuild(batch_size = 1000, &block)
  indexer = Indexer.new(batch_size, self, &block)
  configure_rdig do
    crawler = RDig::Crawler.new RDig.configuration, ActsAsFerret::logger
    crawler.instance_variable_set '@indexer', indexer
    ActsAsFerret::logger.debug "now crawling..."
    crawler.crawl
  end
rescue => e
  ActsAsFerret::logger.error e
  ActsAsFerret::logger.debug e.backtrace.join("\n")
ensure
  indexer.close if indexer
end

#records_modified_since(time) ⇒ Object

overriding aaf to skip reindexing records changed during the rebuild when rebuilding with the rake task



77
78
79
# File 'lib/acts_as_ferret/rdig_adapter.rb', line 77

def records_modified_since(time)
  []
end