Changeset 111
- Timestamp:
- 11/15/06 19:10:26 (2 years ago)
- Files:
-
- trunk/demo/app/models/comment.rb (modified) (2 diffs)
- trunk/demo/test/unit/comment_test.rb (modified) (3 diffs)
- trunk/demo/test/unit/content_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/comment.rb
r78 r111 19 19 20 20 # only index the named fields: 21 #acts_as_ferret :fields => [ 'author', 'content']21 #acts_as_ferret :fields => [:author, :content ] 22 22 23 23 # you can override the default to_doc method … … 28 28 doc = super 29 29 # add a field containing the current time 30 doc['added'] = Time.now.to_i.to_s 31 # Ferret::Document::Field::Store::YES, 32 # Ferret::Document::Field::Index::UNTOKENIZED) 30 doc[:added] = Time.now.to_i.to_s 33 31 return doc 34 32 end trunk/demo/test/unit/comment_test.rb
r102 r111 46 46 assert_equal 1, comments_from_ferret.size 47 47 assert_equal 2, comments_from_ferret.total_hits 48 end 49 50 def test_score 51 comments_from_ferret = Comment.find_by_contents('comment AND fixture', :num_docs => 1) 52 assert comments_from_ferret.first.ferret_score > 0 48 53 end 49 54 … … 148 153 hits = i.search 'move OR shake' 149 154 assert_equal 1, hits.total_hits 155 hits = i.search '+move +the +shake' 156 assert_equal 1, hits.total_hits 150 157 151 158 hits = i.search 'move nothere' … … 153 160 end 154 161 162 # fails due to Ferret bug in 0.10.13, http://pastie.caboo.se/22886 155 163 def test_stopwords 156 164 comment = Comment.create( :author => 'john doe', :content => 'Move or shake' ) 157 ['move shake', 'Move shake', 'move Shake' ].each do |q|165 ['move shake', 'Move shake', 'move Shake', 'move or shake', 'move the shake'].each do |q| 158 166 comments_from_ferret = Comment.find_by_contents(q) 159 167 assert_equal comment, comments_from_ferret.first, "query #{q} failed" 160 168 end 161 162 comments_from_ferret = Comment.find_by_contents('Move or shake')163 assert_equal 1, comments_from_ferret.size164 assert_equal comment, comments_from_ferret.first165 169 comment.destroy 166 170 end trunk/demo/test/unit/content_test.rb
r109 r111 274 274 contents_from_ferret = Content.multi_search('title:title OR content:comment OR description:title', [Comment]) 275 275 assert_equal 5, contents_from_ferret.size 276 contents_from_ferret = Content.multi_search('title:title OR content:comment OR description:title', [Comment], :limit => 2) 277 assert_equal 2, contents_from_ferret.size 278 276 279 contents_from_ferret = Content.multi_search('*:title OR *:comment', Comment) 277 280 assert_equal 5, contents_from_ferret.size
