Changeset 307
- Timestamp:
- 02/02/08 12:53:01 (8 months ago)
- Files:
-
- trunk/demo/app/models/comment.rb (modified) (1 diff)
- trunk/demo/test/unit/comment_test.rb (modified) (1 diff)
- trunk/plugin/acts_as_ferret/lib/act_methods.rb (modified) (1 diff)
- trunk/plugin/acts_as_ferret/lib/acts_as_ferret.rb (modified) (1 diff)
- trunk/plugin/acts_as_ferret/lib/instance_methods.rb (modified) (1 diff)
- trunk/plugin/acts_as_ferret/lib/local_index.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/comment.rb
r265 r307 32 32 :content => { :store => :yes }, 33 33 :author => { }, 34 :added => { :index => :untokenized, :store => :yes, :ignore => true } 34 :added => { :index => :untokenized, :store => :yes, :ignore => true }, 35 :aliased => { :via => :content } 35 36 }, :ferret => { :analyzer => Ferret::Analysis::StandardAnalyzer.new(['fax', 'gsm', 'the', 'or']) } ) 36 37 #}, :ferret => { :analyzer => PlainAsciiAnalyzer.new(['fax', 'gsm', 'the', 'or']) } ) trunk/demo/test/unit/comment_test.rb
r263 r307 21 21 def test_class_index_dir 22 22 assert Comment.aaf_configuration[:index_dir] =~ %r{^#{RAILS_ROOT}/index/test/comment} 23 end 24 25 def test_aliased_field 26 res = Comment.find_with_ferret 'aliased:regarding' 27 assert_equal 1, res.total_hits 28 assert_equal comments(:comment_for_c2), res.first 23 29 end 24 30 trunk/plugin/acts_as_ferret/lib/act_methods.rb
r300 r307 223 223 :index => :yes, 224 224 :term_vector => :with_positions_offsets, 225 :via => field, 225 226 :boost => 1.0 ) 226 227 options[:term_vector] = :no if options[:index] == :no trunk/plugin/acts_as_ferret/lib/acts_as_ferret.rb
r244 r307 125 125 options = options.dup 126 126 options.delete(:boost) if options[:boost].is_a?(Symbol) 127 options.delete(:via) 127 128 fi.add_field(field, { :store => :no, 128 129 :index => :yes }.update(options)) trunk/plugin/acts_as_ferret/lib/instance_methods.rb
r306 r307 153 153 154 154 def content_for_field_name(field, dynamic_boost = nil) 155 field_data = self[field] || self.instance_variable_get("@#{field.to_s}".to_sym) || self.send(field.to_sym) 155 ar_field = aaf_configuration[:ferret_fields][field][:via] 156 field_data = self.send(ar_field) || self.instance_variable_get("@#{ar_field}") 156 157 if (dynamic_boost && boost_value = self.send(dynamic_boost)) 157 158 field_data = Ferret::Field.new(field_data) trunk/plugin/acts_as_ferret/lib/local_index.rb
r306 r307 53 53 models = models.flatten.uniq.map(&:constantize) 54 54 logger.debug "rebuild index: #{models.inspect}" 55 index = Ferret::Index::Index.new(aaf_configuration[:ferret].dup.update(:auto_flush => false,55 index = Ferret::Index::Index.new(aaf_configuration[:ferret].dup.update(:auto_flush => false, 56 56 :field_infos => ActsAsFerret::field_infos(models), 57 :create => true))57 :create => true)) 58 58 index.batch_size = aaf_configuration[:reindex_batch_size] 59 59 index.logger = logger … … 90 90 logger.debug "stored_fields: #{stored_fields}" 91 91 return stored_fields 92 end 93 94 # loads data for fields declared as :lazy from the Ferret document 95 def extract_lazy_fields(doc, lazy_fields) 96 fields = aaf_configuration[:ferret_fields] 97 data = {} 98 lazy_fields.each { |field| data[fields[field][:via]] = doc[field] } if lazy_fields 99 data 92 100 end 93 101 … … 106 114 model = aaf_configuration[:store_class_name] ? doc[:class_name] : aaf_configuration[:class_name] 107 115 # fetch stored fields if lazy loading 108 data = {} 109 lazy_fields.each { |field| data[field] = doc[field] } if lazy_fields 116 data = extract_lazy_fields(doc, lazy_fields) 110 117 if block_given? 111 118 yield model, doc[:id], score, data … … 129 136 doc = index[hit] 130 137 # fetch stored fields if lazy loading 131 data = {} 132 lazy_fields.each { |field| data[field] = doc[field] } if lazy_fields 138 data = extract_lazy_fields(doc, lazy_fields) 133 139 raise "':store_class_name => true' required for multi_search to work" if doc[:class_name].blank? 134 140 if block_given?
