lib/picky/indexers/serial.rb in picky-2.6.0 vs lib/picky/indexers/serial.rb in picky-2.7.0

- old
+ new

@@ -6,47 +6,50 @@ # # Note: It is called serial since it indexes each category separately. # class Serial < Base - attr_reader :category - - delegate :source, :to => :category - - def initialize category - @category = category - end - - # The tokenizer used is a cached tokenizer from the category. - # - def tokenizer - @tokenizer ||= category.tokenizer - end - # Harvest the data from the source, tokenize, # and write to an intermediate "prepared index" file. # - def process + # Parameters: + # * categories: An enumerable of Category-s. + # + def process categories comma = ?, newline = ?\n - local_tokenizer = tokenizer - category.prepared_index_file do |file| - result = [] - source.harvest(category) do |indexed_id, text| - local_tokenizer.tokenize(text).each do |token_text| - next unless token_text - result << indexed_id << comma << token_text << newline + categories.each do |category| + + tokenizer = category.tokenizer + + category.prepared_index_file do |file| + result = [] + + source.harvest(category) do |indexed_id, text| + tokenizer.tokenize(text).each do |token_text| + next unless token_text + result << indexed_id << comma << token_text << newline + end + file.write(result.join) && result.clear if result.size > 100_000 end - file.write(result.join) && result.clear if result.size > 100_000 + + timed_exclaim %Q{"#{@index_or_category.identifier}": => #{file.path}.} + + file.write result.join end - file.write result.join + end + end + # # - def indexing_message # :nodoc: - timed_exclaim %Q{"#{@category.identifier}": Starting serial indexing.} + def start_indexing_message # :nodoc: + timed_exclaim %Q{"#{@index_or_category.identifier}": Starting serial data preparation.} + end + def finish_indexing_message # :nodoc: + timed_exclaim %Q{"#{@index_or_category.identifier}": Finished serial data preparation.} end end end \ No newline at end of file