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

Changeset 78

Show
Ignore:
Timestamp:
08/23/06 16:45:28 (2 years ago)
Author:
jk
Message:

first Ferret 0.10 compatible version, some tests still failing (queries not ANDed by default, no more_like_this

Files:

Legend:

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

    r60 r78  
    88  # the multi_search method to run queries across multiple 
    99  # models (where each model has it's own index directory) 
    10   acts_as_ferret :store_class_name => true 
     10  # 
     11  # use the :additional_fields property to specify fields you intend  
     12  # to add in addition to those fields from your database table (which will be 
     13  # autodiscovered by acts_as_ferret) 
     14  # the :ignore flag tells aaf to not try to set this field's value itself (we 
     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  } 
    1119 
    1220  # only index the named fields: 
     
    2028    doc = super 
    2129    # add a field containing the current time 
    22     doc <<  Ferret::Document::Field.new( 
    23               'added', Time.now.to_i.to_s,  
    24               Ferret::Document::Field::Store::YES,  
    25               Ferret::Document::Field::Index::UNTOKENIZED) 
     30    doc['added'] = Time.now.to_i.to_s 
     31#              Ferret::Document::Field::Store::YES,  
     32#              Ferret::Document::Field::Index::UNTOKENIZED) 
    2633    return doc 
    2734  end 
  • trunk/demo/app/models/content.rb

    r51 r78  
    1111  # 'more like this' queries to find other content instances with similar 
    1212  # descriptions 
    13   acts_as_ferret :fields => { :comment_count => {}, 'title' => { :boost => 2 }, 'description' => { :boost => 1, :store => Ferret::Document::Field::Store::YES }, :special => {} }, :store_class_name => true 
     13  acts_as_ferret( :fields => {  
     14    :comment_count => {}, 
     15    :title         => { :boost => 2 },  
     16    :description   => { :boost => 1, :store => :yes }, 
     17    :special       => {}  
     18  }, :store_class_name => true) 
    1419 
    1520  # use this instead to not assign special boost values: 
  • trunk/demo/test/unit/comment_test.rb

    r76 r78  
    2323    # maybe different analyzers at index creation and searching time ? 
    2424    #comments_from_ferret = Comment.find_by_contents('"comment from fixture"') 
    25     comments_from_ferret = Comment.find_by_contents('comment AND fixture') 
     25    comments_from_ferret = Comment.find_by_contents('comment fixture') 
    2626    assert_equal 2, comments_from_ferret.size 
    2727    assert comments_from_ferret.include?(comments(:first)) 
     
    5050    assert_equal 10, (res = Comment.find_by_contents('multicomment')).size 
    5151    assert_equal 20, res.total_hits 
    52     assert_equal 15, (res = Comment.find_by_contents('multicomment', :num_docs => 15)).size 
     52    assert_equal 15, (res = Comment.find_by_contents('multicomment', :limit => 15)).size 
    5353    assert_equal 20, res.total_hits 
    5454    assert_equal 20, (res = Comment.find_by_contents('multicomment', :num_docs => :all)).size 
     
    6464    top_docs = Comment.ferret_index.search('"from fixture"') 
    6565    #top_docs = Comment.ferret_index.search('"comment from fixture"') 
    66     assert_equal 2, top_docs.score_docs.size 
    67     doc = Comment.ferret_index.doc(top_docs.score_docs[0].doc) 
     66    assert_equal 2, top_docs.total_hits 
     67    doc = Comment.ferret_index.doc(top_docs.hits[0].doc) 
    6868    # check for the special field added by the custom to_doc method 
    6969    assert_not_nil doc[:added] 
     
    136136  def test_stopwords_ferret_bug  
    137137    i = Ferret::Index::Index.new( 
    138             :occur_default => Ferret::Search::BooleanClause::Occur::MUST
    139             :default_search_field => '*' 
     138            :or_default => false
     139            :default_field => '*' 
    140140            ) 
    141141    d = Ferret::Document::Document.new 
    142     d << Ferret::Document::Field.new('id', '1',  
    143                                      Ferret::Document::Field::Store::YES, 
    144                                      Ferret::Document::Field::Index::UNTOKENIZED, 
    145                                      Ferret::Document::Field::TermVector::NO, 
    146                                      false, 1.0) 
    147     d << Ferret::Document::Field.new('content', 'Move or shake',  
    148                                      Ferret::Document::Field::Store::NO, 
    149                                      Ferret::Document::Field::Index::TOKENIZED, 
    150                                      Ferret::Document::Field::TermVector::NO, 
    151                                      false, 1.0) 
     142    d[:id] = '1' 
     143    d[:content] = 'Move or shake' 
    152144    i << d 
    153145    hits = i.search 'move nothere shake' 
  • trunk/demo/test/unit/content_test.rb

    r60 r78  
    9494  def test_multi_index 
    9595    i =  FerretMixin::Acts::ARFerret::MultiIndex.new([Content, Comment]) 
    96     hits = i.search(TermQuery.new(Term.new("title","title"))) 
    97     assert_equal 1, hits.score_docs.size 
    98  
    99     qp = Ferret::QueryParser.new("title",  
    100                       :analyzer => Ferret::Analysis::WhiteSpaceAnalyzer.new) 
     96    hits = i.search(TermQuery.new(:title,"title")) 
     97    assert_equal 1, hits.total_hits 
     98 
     99    qp = Ferret::QueryParser.new(:default_field => "title",  
     100                                :analyzer => Ferret::Analysis::WhiteSpaceAnalyzer.new) 
    101101    hits = i.search(qp.parse("title")) 
    102     assert_equal 1, hits.score_docs.size 
    103      
    104     qp = Ferret::QueryParser.new("*", :fields => ['title', 'content', 'description'], 
     102    assert_equal 1, hits.total_hits 
     103     
     104    qp = Ferret::QueryParser.new(:fields => ['title', 'content', 'description'], 
    105105                      :analyzer => Ferret::Analysis::WhiteSpaceAnalyzer.new) 
    106106    # TODO '*' doesn't seem to work in 0.9 anymore - there's no .fields method 
     
    109109    #qp.fields = ['title','content'] 
    110110    hits = i.search(qp.parse("title")) 
    111     assert_equal 2, hits.score_docs.size 
     111    assert_equal 2, hits.total_hits 
    112112    hits = i.search(qp.parse("title:title OR description:title")) 
    113     assert_equal 2, hits.score_docs.size 
     113    assert_equal 2, hits.total_hits 
    114114 
    115115    hits = i.search("title:title OR description:title OR title:comment OR description:comment OR content:comment") 
    116     assert_equal 5, hits.score_docs.size 
     116    assert_equal 5, hits.total_hits 
    117117 
    118118    hits = i.search("title OR comment") 
    119     assert_equal 5, hits.score_docs.size 
     119    assert_equal 5, hits.total_hits 
    120120  end 
    121121 
    122122  def test_multi_searcher 
    123     s = MultiSearcher.new([IndexSearcher.new(Content.class_index_dir), IndexSearcher.new(Comment.class_index_dir)]) 
    124     hits = s.search(TermQuery.new(Term.new("title","title"))) 
    125     assert_equal 1, hits.score_docs.size 
     123    s = MultiSearcher.new([Searcher.new(Content.class_index_dir), Searcher.new(Comment.class_index_dir)]) 
     124    hits = s.search(TermQuery.new(:title,"title")) 
     125    assert_equal 1, hits.total_hits 
    126126  end 
    127127   
     
    189189   
    190190  def test_find_by_contents_boost 
    191  
    192191    # give description field higher boost: 
    193192    contents_from_ferret = Content.find_by_contents('title:title OR description:title^10') 
     
    216215    contents_from_ferret = Content.find_by_contents('title', :num_docs => 1) 
    217216    assert_equal 1, contents_from_ferret.size 
    218     assert_equal contents(:first).id, contents_from_ferret.first.id  
     217    assert_equal contents(:first), contents_from_ferret.first  
    219218     
    220219    # limit result set size to 1, starting with the second result 

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