Changeset 258
- Timestamp:
- 04/25/08 02:57:46 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/picolena/templates/app/models/indexer.rb
r247 r258 16 16 } 17 17 log :debug => "Now optimizing index" 18 writer.optimize18 index.optimize 19 19 log :debug => "Indexing done in #{Time.now-start} s." 20 20 end … … 30 30 indexing_list_chunks=indexing_list.in_transposed_slices(threads_number) 31 31 32 # It initializes an IndexWriterbefore launching multithreaded32 # It initializes the Index before launching multithreaded 33 33 # indexing. Otherwise, two threads could try to instantiate 34 34 # an IndexWriter at the same time, and get a 35 35 # Ferret::Store::Lock::LockError 36 writer36 index 37 37 38 38 indexing_list_chunks.each_with_thread{|chunk| … … 54 54 document = default_fields 55 55 end 56 writer<< document56 index << document 57 57 end 58 58 59 # Ensures writeris closed, and removes every index file for RAILS_ENV.59 # Ensures index is closed, and removes every index file for RAILS_ENV. 60 60 def clear!(all=false) 61 61 close … … 64 64 end 65 65 66 # Closes the writerand67 # ensures that a new Index Writer is instantiated next time writeris called.66 # Closes the index and 67 # ensures that a new Index is instantiated next time index is called. 68 68 def close 69 @@ writer.close rescue nil69 @@index.close rescue nil 70 70 # Ferret will SEGFAULT otherwise. 71 @@ writer= nil71 @@index = nil 72 72 end 73 73 74 74 # Only one IndexWriter should be instantiated. 75 # If one already exists, returns it.75 # If one index already exists, returns it. 76 76 # Creates it otherwise. 77 def writer78 @@writer ||= Ferret::Index::IndexWriter.new(default_index_params)79 end80 81 77 def index 82 Ferret::Index::Index.new(default_index_params)78 @@index ||= Ferret::Index::Index.new(default_index_params) 83 79 end 84 80 85 81 def ensure_index_existence 86 82 index_every_directory(:remove_first) unless index_exists? or RAILS_ENV=="production" 83 end 84 85 def doc_count 86 index.writer.doc_count 87 87 end 88 88 … … 104 104 105 105 def default_index_params 106 {:path => Picolena::IndexSavePath, :analyzer => Picolena::Analyzer, :field_infos => default_field_infos} 106 { 107 :path => Picolena::IndexSavePath, 108 :analyzer => Picolena::Analyzer, 109 :field_infos => default_field_infos, 110 # Great way to ensure that no file is indexed twice! 111 :key => :complete_path 112 } 107 113 end 108 114
