Changeset 142
- Timestamp:
- 02/03/07 21:18:55 (2 years ago)
- Files:
-
- trunk/demo/app/models/comment.rb (modified) (1 diff)
- trunk/demo/app/models/content.rb (modified) (1 diff)
- trunk/demo/app/models/content_base.rb (added)
- trunk/demo/app/models/remote_content.rb (deleted)
- trunk/demo/app/models/shared_index1.rb (modified) (1 diff)
- trunk/demo/app/models/shared_index2.rb (modified) (1 diff)
- trunk/demo/db/migrate/006_create_remote_contents.rb (deleted)
- trunk/demo/test/unit/content_test.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/comment.rb
r135 r142 14 14 # the :ignore flag tells aaf to not try to set this field's value itself (we 15 15 # do this in our custom to_doc method) 16 acts_as_ferret :store_class_name => true, :additional_fields => { 17 :added => { :index => :untokenized, :store => :yes, :ignore => true }, 18 } 16 acts_as_ferret( :store_class_name => true, 17 :remote => ENV['AAF_REMOTE'], # for testing drb remote indexing 18 :additional_fields => { 19 :added => { :index => :untokenized, :store => :yes, :ignore => true } 20 } ) 19 21 20 22 # only index the named fields: trunk/demo/app/models/content.rb
r102 r142 1 # common base class for Content and SpecialContent2 class ContentBase < ActiveRecord::Base3 set_table_name 'contents'4 5 # a higher boost means more importance for the field --> documents having a6 # match in a field with a higher boost value will be ranked higher7 #8 # we use the store_class_name flag to be able to retrieve model instances when9 # searching multiple indexes at once.10 # the contents of the description field are stored in the index for running11 # 'more like this' queries to find other content instances with similar12 # descriptions13 acts_as_ferret( :fields => {14 :comment_count => {},15 :title => { :boost => 2 },16 :description => { :boost => 1, :store => :yes },17 :special => {}18 }, :store_class_name => true)19 20 21 def comment_count; 0 end22 23 end24 25 1 class Content < ContentBase #ActiveRecord::Base 26 2 trunk/demo/app/models/shared_index1.rb
r60 r142 1 1 class SharedIndex1 < ActiveRecord::Base 2 acts_as_ferret :single_index => true 2 acts_as_ferret :single_index => true, :remote => ENV['AAF_REMOTE'] 3 3 end trunk/demo/app/models/shared_index2.rb
r60 r142 1 1 class SharedIndex2 < ActiveRecord::Base 2 acts_as_ferret :single_index => true 2 acts_as_ferret :single_index => true, :remote => ENV['AAF_REMOTE'] 3 3 end trunk/demo/test/unit/content_test.rb
r140 r142 13 13 Comment.rebuild_index 14 14 ContentBase.rebuild_index 15 raise "missing fixtures" unless ContentBase.count > 2 15 16 16 17 @another_content = Content.new( :title => 'Another Content item', … … 274 275 275 276 [ 'title:title OR description:title OR content:title', 'title', '*:title'].each do |query| 276 contents_from_ferret = Content.id_multi_search(query)277 total_hits, contents_from_ferret = Content.id_multi_search(query) 277 278 assert_equal 2, contents_from_ferret.size, query 279 assert_equal 2, total_hits, query 278 280 assert_equal contents(:first).id, contents_from_ferret.first[:id].to_i 279 281 assert_equal @another_content.id, contents_from_ferret.last[:id].to_i … … 283 285 Comment.rebuild_index 284 286 ['title OR comment', 'title:(title OR comment) OR description:(title OR comment) OR content:(title OR comment)'].each do |query| 285 contents_from_ferret = Content.id_multi_search(query, [Comment])287 total_hits, contents_from_ferret = Content.id_multi_search(query, [Comment]) 286 288 assert_equal 5, contents_from_ferret.size, query 289 assert_equal 5, total_hits 287 290 end 288 291 end … … 294 297 295 298 def test_find_id_by_contents 296 contents_from_ferret = Content.find_id_by_contents('title:title OR description:title') 297 assert_equal 2, contents_from_ferret.size 299 total_hits, contents_from_ferret = Content.find_id_by_contents('title:title OR description:title') 300 assert_equal 2, contents_from_ferret.size 301 assert_equal 2, total_hits 298 302 #puts "first (id=#{contents_from_ferret.first[:id]}): #{contents_from_ferret.first[:score]}" 299 303 #puts "last (id=#{contents_from_ferret.last[:id]}): #{contents_from_ferret.last[:score]}" … … 303 307 304 308 # give description field higher boost: 305 contents_from_ferret = Content.find_id_by_contents('title:title OR description:title^10') 306 assert_equal 2, contents_from_ferret.size 309 total_hits, contents_from_ferret = Content.find_id_by_contents('title:title OR description:title^10') 310 assert_equal 2, contents_from_ferret.size 311 assert_equal 2, total_hits 307 312 #puts "first (id=#{contents_from_ferret.first[:id]}): #{contents_from_ferret.first[:score]}" 308 313 #puts "last (id=#{contents_from_ferret.last[:id]}): #{contents_from_ferret.last[:score]}"
