Changeset 243

Show
Ignore:
Timestamp:
04/24/08 08:01:47 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

Specs pass.
149 examples, 0 failures, 6 pending

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/yet_another_index_structure/lib/picolena/templates/app/models/finder.rb

    r241 r243  
    1212    @per_page=results_per_page 
    1313    @offset=(page.to_i-1)*results_per_page 
     14    index_should_have_documents 
    1415  end 
    1516   
     
    6970  end 
    7071   
    71   class<<self 
     72  class<<self   
    7273    def searcher 
    73       Ferret::Search::Searcher.new(Picolena::IndexSavePath) 
     74      @@searcher ||= Ferret::Search::Searcher.new(Picolena::IndexSavePath) 
    7475    end 
    7576     
     
    7879      searcher.search(query).hits.first 
    7980    end 
     81 
     82    def reload! 
     83      @@searcher = nil 
     84      @@index    = nil 
     85    end 
     86  end 
     87   
     88  private 
     89   
     90  def index_should_have_documents 
     91    raise IndexError, "no document found" unless index.size > 0 
    8092  end 
    8193end 
  • branches/yet_another_index_structure/lib/picolena/templates/app/models/indexer.rb

    r242 r243  
    55  @@max_threads_number = 8 
    66   
    7   class << self     
     7  class << self 
    88    def index_every_directory(remove_first=false) 
    99      clear! if remove_first 
     10      # Forces Finder.searcher and Finder.index to be reloaded, by removing them from the cache. 
     11      Finder.reload! 
    1012      log :debug => "Indexing every directory" 
    1113      start=Time.now 
     
    7274     
    7375    def index 
    74       Ferret::I.new(default_index_params)   
     76      Ferret::Index::Index.new(default_index_params)   
    7577    end 
    7678