Changeset 181
- Timestamp:
- 04/20/08 04:36:50 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/oo_indexer/lib/picolena/templates/spec/models/finder_spec.rb
r153 r181 123 123 @finder.matching_documents.should_not be_empty 124 124 end 125 126 it "should not be case sensitive" do127 a=Finder.new("test").total_hits128 b=Finder.new("TEst").total_hits129 c=Finder.new("tesT").total_hits130 a.should == b131 b.should == c132 end133 134 it "should accept field terms in different languages"135 it "should accept LIKE and NOT boolean ops in different languages" do136 fuzzy_query=Finder.new("test~").total_hits137 test_query=Finder.new("test").total_hits138 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 = ln148 like_bool, not_bool = keywords149 minus_query=Finder.new("#{like_bool} test #{not_bool} test").total_hits150 (fuzzy_query-test_query).should == minus_query151 }152 end153 154 it "should accept AND and OR boolean ops in different languages" do155 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 = ln164 or_bool, and_bool = keywords165 or_query=Finder.new("test #{or_bool} another").total_hits166 and_query=Finder.new("test #{and_bool} another").total_hits167 test_query=Finder.new("test").total_hits168 another_query=Finder.new("another").total_hits169 (test_query+another_query-and_query).should == or_query170 }171 end172 173 it "should use AND as default boolean ops" do174 or_query=Finder.new("test OR another").total_hits175 and_query=Finder.new("test another").total_hits176 test_query=Finder.new("test").total_hits177 another_query=Finder.new("another").total_hits178 179 (test_query+another_query-and_query).should == or_query180 and_query.should <= or_query181 and_query.should <= test_query182 and_query.should <= another_query183 end184 185 it "should convert foreign keywords to boolean operators only as whole-word" do186 Globalite.language = :de187 Finder.new("STRALSUND UND BRODERBUND").matching_documents.should_not be_empty188 Globalite.language = :fr189 Finder.new("CETTE ET MIETTE").matching_documents.should_not be_empty190 end191 125 192 126 it "should use ? as placeholder" do branches/oo_indexer/lib/picolena/templates/spec/models/query_spec.rb
r152 r181 2 2 3 3 describe 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") 6 55 end 7 56 end
