Changeset 181

Show
Ignore:
Timestamp:
04/20/08 04:36:50 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

Specs for Query.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/oo_indexer/lib/picolena/templates/spec/models/finder_spec.rb

    r153 r181  
    123123    @finder.matching_documents.should_not be_empty 
    124124  end 
    125  
    126   it "should not be case sensitive" do 
    127     a=Finder.new("test").total_hits 
    128     b=Finder.new("TEst").total_hits 
    129     c=Finder.new("tesT").total_hits 
    130     a.should == b 
    131     b.should == c 
    132   end 
    133    
    134   it "should accept field terms in different languages" 
    135   it "should accept LIKE and NOT boolean ops in different languages" do 
    136     fuzzy_query=Finder.new("test~").total_hits 
    137     test_query=Finder.new("test").total_hits 
    138      
    139     language_and_keywords={ 
    140       :en=>["LIKE", "NOT"], 
    141       :de=>["WIE", "NICHT"], 
    142       :es=>["COMO", "NO"], 
    143       :fr=>["COMME","NON"] 
    144     } 
    145      
    146     language_and_keywords.each_pair{|ln,keywords| 
    147       Globalite.language = ln 
    148       like_bool, not_bool = keywords 
    149       minus_query=Finder.new("#{like_bool} test #{not_bool} test").total_hits 
    150       (fuzzy_query-test_query).should == minus_query 
    151     } 
    152   end 
    153    
    154   it "should accept AND and OR boolean ops in different languages" do 
    155     language_and_keywords={ 
    156       :en=>["OR", "AND"], 
    157       :de=>["ODER", "UND"], 
    158       :es=>["O", "Y"], 
    159       :fr=>["OU","ET"] 
    160     } 
    161      
    162     language_and_keywords.each_pair{|ln,keywords| 
    163       Globalite.language = ln 
    164       or_bool, and_bool = keywords 
    165       or_query=Finder.new("test #{or_bool} another").total_hits 
    166       and_query=Finder.new("test #{and_bool} another").total_hits 
    167       test_query=Finder.new("test").total_hits 
    168       another_query=Finder.new("another").total_hits 
    169       (test_query+another_query-and_query).should == or_query 
    170     } 
    171   end 
    172    
    173   it "should use AND as default boolean ops" do 
    174     or_query=Finder.new("test OR another").total_hits 
    175     and_query=Finder.new("test another").total_hits 
    176     test_query=Finder.new("test").total_hits 
    177     another_query=Finder.new("another").total_hits 
    178      
    179     (test_query+another_query-and_query).should == or_query 
    180     and_query.should <= or_query 
    181     and_query.should <= test_query 
    182     and_query.should <= another_query 
    183   end 
    184    
    185   it "should convert foreign keywords to boolean operators only as whole-word" do 
    186     Globalite.language = :de 
    187       Finder.new("STRALSUND UND BRODERBUND").matching_documents.should_not be_empty 
    188     Globalite.language = :fr 
    189       Finder.new("CETTE ET MIETTE").matching_documents.should_not be_empty 
    190   end 
    191125   
    192126  it "should use ? as placeholder" do 
  • branches/oo_indexer/lib/picolena/templates/spec/models/query_spec.rb

    r152 r181  
    22 
    33describe Query do 
    4   before(:each) do 
    5     @query = Query.new 
     4  it "should return a BooleanQuery" do 
     5    Query.extract_from("whatever").class.should == Ferret::Search::BooleanQuery 
     6  end 
     7 
     8  it "should translate LIKE, NOT, OR and AND boolean ops to English" do 
     9    language_and_keywords={ 
     10      :de=>["WIE", "NICHT", "ODER", "UND"], 
     11      :es=>["COMO", "NO", "O", "Y"], 
     12      :fr=>["COMME","NON","OU","ET"] 
     13    } 
     14     
     15    english_query_with_like_and_not=Query.extract_from("LIKE something NOT something") 
     16    english_query_with_or=Query.extract_from("test OR another") 
     17    english_query_with_and=Query.extract_from("test AND another") 
     18     
     19    language_and_keywords.each_pair{|ln,keywords| 
     20      Globalite.language = ln 
     21      like_bool, not_bool, or_bool, and_bool = keywords 
     22      raw_query_in_some_language_with_like_and_not="#{like_bool} something #{not_bool} something" 
     23      raw_query_in_some_language_with_or="#test #{or_bool} another" 
     24      raw_query_in_some_language_with_and="#test #{and_bool} another" 
     25      Query.extract_from(raw_query_in_some_language_with_like_and_not).should == english_query_with_like_and_not 
     26      Query.extract_from(raw_query_in_some_language_with_or).should == english_query_with_or 
     27      Query.extract_from(raw_query_in_some_language_with_and).should == english_query_with_and 
     28    } 
     29  end 
     30   
     31  it "should accept field terms in different languages" 
     32   
     33  it "should use AND as default boolean ops" do 
     34    query_without_and = Query.extract_from("one AND two") 
     35    query_with_and    = Query.extract_from("one two") 
     36    query_with_and.should == query_without_and 
     37  end 
     38   
     39  it "should convert foreign keywords to boolean operators only as whole-word" do 
     40    Globalite.language = :en 
     41      english_query_with_french_words = Query.extract_from("CETTE AND MIETTE") 
     42      english_query_with_german_words = Query.extract_from("STRALSUND AND BRODERBUND") 
     43    Globalite.language = :de 
     44      Query.extract_from("STRALSUND UND BRODERBUND").should == english_query_with_german_words 
     45      Query.extract_from("CETTE ET MIETTE").should_not == english_query_with_french_words 
     46    Globalite.language = :fr 
     47      Query.extract_from("CETTE ET MIETTE").should == english_query_with_french_words 
     48      Query.extract_from("STRALSUND UND BRODERBUND").should_not == english_query_with_german_words 
     49  end 
     50   
     51  it "should not be case sensitive" do 
     52    Query.extract_from("test").should == Query.extract_from("TEst") 
     53    Query.extract_from("test").should == Query.extract_from("tesT") 
     54    Query.extract_from("test").should_not == Query.extract_from("tesTe")     
    655  end 
    756end