Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 600ffe3417
Fetching contributors…

Cannot retrieve contributors at this time

45 lines (38 sloc) 1.226 kb
module RDig
module Index
# used by the crawler to build the ferret index
class Indexer
include MonitorMixin
attr_reader :indexed_documents
def initialize(settings)
@indexed_documents = 0
@config = settings
@index_writer = Ferret::Index::IndexWriter.new(
:path => settings.path,
:create => settings.create,
:analyzer => settings.analyzer)
super() # scary, MonitorMixin won't initialize if we don't call super() here (parens matter)
end
def add_to_index(document)
RDig.logger.debug "add to index: #{document.uri.to_s}"
@config.rewrite_uri.call(document.uri) if @config.rewrite_uri
# all stored and tokenized, should be ferret defaults
doc = {
:url => document.uri.to_s,
:title => document.title,
:data => document.body
}
synchronize do
@index_writer << doc
@indexed_documents += 1
end
end
alias :<< :add_to_index
def close
@index_writer.optimize
@index_writer.close
@index_writer = nil
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.