naive-search 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ # This model initially had no columns defined. If you add columns to the
4
+ # model remove the '{}' from the fixture names and add the columns immediately
5
+ # below each fixture, per the syntax in the comments below
6
+ #
7
+ one: {}
8
+ # column: value
9
+ #
10
+ two: {}
11
+ # column: value
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class CityTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -1,3 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
1
4
  require 'test_helper'
2
5
 
3
6
  class NaiveSearchTest < ActiveSupport::TestCase
@@ -23,6 +26,17 @@ class NaiveSearchTest < ActiveSupport::TestCase
23
26
  ].each do |attrs|
24
27
  Hotel.create(attrs)
25
28
  end
29
+
30
+ [
31
+ { :name => "Örnsköldsvik" },
32
+ { :name => "Örebro" },
33
+ { :name => "Östersund" },
34
+ { :name => "Öresund" },
35
+ { :name => "Österfärnebo" },
36
+ { :name => "Malmö" }
37
+ ].each do |attrs|
38
+ City.create(attrs)
39
+ end
26
40
  end
27
41
 
28
42
  test "result order" do
@@ -33,6 +47,13 @@ class NaiveSearchTest < ActiveSupport::TestCase
33
47
  assert_equal "Holiday Lodge", hotels.first, "should order matches by relevance #2"
34
48
  end
35
49
 
50
+ test "non-ascii character search" do
51
+ cities_small_oe = City.search_for("öster sund").map(&:name)
52
+ cities_capital_oe = City.search_for("Öre sund").map(&:name)
53
+ assert_equal ["Östersund", "Öresund", "Österfärnebo"], cities_small_oe, "should find matches with small umlaut queries"
54
+ assert_equal ["Öresund", "Östersund", "Örebro"], cities_capital_oe, "should find matches with capital umlaut queries"
55
+ end
56
+
36
57
  test "relevance" do
37
58
  relevance_arnold_bentley = Person.order("id asc").map{|p| p.relevance_for "arnold bentley" }
38
59
  assert_equal [6, 4, 4, 0, 0, 0, 4, 4], relevance_arnold_bentley, "should calculate correct relevance for 'arnold bentley'"
@@ -45,17 +66,21 @@ class NaiveSearchTest < ActiveSupport::TestCase
45
66
 
46
67
  relevance_nice_breakfast = Hotel.order("id asc").map{|h| h.relevance_for "nice breakfast" }
47
68
  assert_equal [1, 1, 2, 4], relevance_nice_breakfast, "should calculate correct relevance for 'nice breakfast'"
69
+
70
+ donald = Person.create(:name => "Donald", :surname => "Trump", :description => "rich, comb over")
71
+ assert_equal 0, donald.relevance_for("")
72
+ assert_equal 0, donald.relevance_for(100)
48
73
  end
49
74
 
50
75
  test "updating" do
51
76
  new_person = Person.create(:name => "Abraham", :surname => "Lincoln", :description => "nice hat!", :age => 56)
52
- assert_equal "Abraham\nLincoln\nnice hat!", new_person.naive_search_index, "should store value of the indexed fields in the search index"
77
+ assert_equal "abraham\nlincoln\nnice hat!", new_person.naive_search_index, "should store value of the indexed fields in the search index"
53
78
 
54
79
  new_person.age = 57
55
80
  new_person.send :update_naive_search_index
56
81
 
57
82
  assert_equal ["age"], new_person.changed, "should not change the search index #1"
58
- assert_equal "Abraham\nLincoln\nnice hat!", new_person.naive_search_index, "should not change the search index #2"
83
+ assert_equal "abraham\nlincoln\nnice hat!", new_person.naive_search_index, "should not change the search index #2"
59
84
  end
60
85
 
61
86
  test "pagination" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naive-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-09 00:00:00.000000000Z
12
+ date: 2011-11-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2152290460 !ruby/object:Gem::Requirement
16
+ requirement: &2152680280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152290460
24
+ version_requirements: *2152680280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &2152283200 !ruby/object:Gem::Requirement
27
+ requirement: &2152679700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152283200
35
+ version_requirements: *2152679700
36
36
  description: Provides very simple full text searching for ActiveRecord, without depending
37
37
  on any particular SQL-feature, search server or anything like that.
38
38
  email:
@@ -54,6 +54,7 @@ files:
54
54
  - test/dummy/app/assets/stylesheets/application.css
55
55
  - test/dummy/app/controllers/application_controller.rb
56
56
  - test/dummy/app/helpers/application_helper.rb
57
+ - test/dummy/app/models/city.rb
57
58
  - test/dummy/app/models/hotel.rb
58
59
  - test/dummy/app/models/person.rb
59
60
  - test/dummy/app/views/layouts/application.html.erb
@@ -79,6 +80,8 @@ files:
79
80
  - test/dummy/db/migrate/20111108071246_create_hotels.rb
80
81
  - test/dummy/db/migrate/20111108082054_add_naive_search_index_to_hotel.rb
81
82
  - test/dummy/db/migrate/20111108142454_add_age_to_person.rb
83
+ - test/dummy/db/migrate/20111117144937_create_cities.rb
84
+ - test/dummy/db/migrate/20111117155928_add_naive_search_index_to_city.rb
82
85
  - test/dummy/db/schema.rb
83
86
  - test/dummy/db/seeds.rb
84
87
  - test/dummy/db/test.sqlite3
@@ -90,8 +93,10 @@ files:
90
93
  - test/dummy/public/favicon.ico
91
94
  - test/dummy/Rakefile
92
95
  - test/dummy/script/rails
96
+ - test/dummy/test/fixtures/cities.yml
93
97
  - test/dummy/test/fixtures/hotels.yml
94
98
  - test/dummy/test/fixtures/people.yml
99
+ - test/dummy/test/unit/city_test.rb
95
100
  - test/dummy/test/unit/hotel_test.rb
96
101
  - test/dummy/test/unit/person_test.rb
97
102
  - test/naive_search_test.rb
@@ -125,6 +130,7 @@ test_files:
125
130
  - test/dummy/app/assets/stylesheets/application.css
126
131
  - test/dummy/app/controllers/application_controller.rb
127
132
  - test/dummy/app/helpers/application_helper.rb
133
+ - test/dummy/app/models/city.rb
128
134
  - test/dummy/app/models/hotel.rb
129
135
  - test/dummy/app/models/person.rb
130
136
  - test/dummy/app/views/layouts/application.html.erb
@@ -150,6 +156,8 @@ test_files:
150
156
  - test/dummy/db/migrate/20111108071246_create_hotels.rb
151
157
  - test/dummy/db/migrate/20111108082054_add_naive_search_index_to_hotel.rb
152
158
  - test/dummy/db/migrate/20111108142454_add_age_to_person.rb
159
+ - test/dummy/db/migrate/20111117144937_create_cities.rb
160
+ - test/dummy/db/migrate/20111117155928_add_naive_search_index_to_city.rb
153
161
  - test/dummy/db/schema.rb
154
162
  - test/dummy/db/seeds.rb
155
163
  - test/dummy/db/test.sqlite3
@@ -161,8 +169,10 @@ test_files:
161
169
  - test/dummy/public/favicon.ico
162
170
  - test/dummy/Rakefile
163
171
  - test/dummy/script/rails
172
+ - test/dummy/test/fixtures/cities.yml
164
173
  - test/dummy/test/fixtures/hotels.yml
165
174
  - test/dummy/test/fixtures/people.yml
175
+ - test/dummy/test/unit/city_test.rb
166
176
  - test/dummy/test/unit/hotel_test.rb
167
177
  - test/dummy/test/unit/person_test.rb
168
178
  - test/naive_search_test.rb