To edit pages or tickets please login with username/password: aaf/aaf

Changeset 10

Show
Ignore:
Timestamp:
03/08/06 23:22:11 (3 years ago)
Author:
jk
Message:

testing acts_as_ferret without parameters and some more complex
queries

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo/app/models/comment.rb

    r5 r10  
    11class Comment < ActiveRecord::Base 
    22  belongs_to :parent, :class_name => 'Content' 
    3   acts_as_ferret :fields => [ 'author', 'content' ] 
     3  # just index all fields: 
     4  acts_as_ferret  
     5  #acts_as_ferret :fields => ['author', 'content' ] 
    46end 
  • trunk/demo/test/unit/comment_test.rb

    r5 r10  
    1616    comment = Comment.new( :author => 'john doe', :content => 'This is a useless comment' ) 
    1717    comment.save 
     18    comment2 = Comment.new( :author => 'another', :content => 'content' ) 
     19    comment2.save 
    1820 
     21    comments_from_ferret = Comment.find_by_contents('anoth* OR jo*') 
     22    assert_equal 2, comments_from_ferret.size 
     23    assert comments_from_ferret.include?(comment) 
     24    assert comments_from_ferret.include?(comment2) 
     25     
     26    comments_from_ferret = Comment.find_by_contents('another') 
     27    assert_equal 1, comments_from_ferret.size 
     28    assert_equal comment2.id, comments_from_ferret.first.id 
     29     
    1930    comments_from_ferret = Comment.find_by_contents('doe') 
    2031    assert_equal 1, comments_from_ferret.size 
  • trunk/demo/test/unit/content_test.rb

    r5 r10  
    6565    assert_equal 1, contents_from_ferret.size 
    6666    assert_equal @content.id, contents_from_ferret.first.id 
     67 
     68    # wildcard query 
     69    contents_from_ferret = Content.find_by_contents('use*') 
     70    assert_equal 1, contents_from_ferret.size 
     71 
     72    # ferret-bug ? wildcard queries don't seem to get lowercased even when 
     73    # using StandardAnalyzer: 
     74    # contents_from_ferret = Content.find_by_contents('Ti*') 
     75    # we should find both 'Title' and 'title' 
     76    # assert_equal 2, contents_from_ferret.size  
     77    # theory: :wild_lower parser option isn't used 
     78 
     79    contents_from_ferret = Content.find_by_contents('ti*') 
     80    # this time we find both 'Title' and 'title' 
     81    assert_equal 2, contents_from_ferret.size 
     82     
    6783   end 
    6884 

To edit pages or tickets please login with username/password: aaf/aaf