picky 2.7.0 → 3.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. data/lib/picky/adapters/rack/base.rb +20 -16
  2. data/lib/picky/adapters/rack/live_parameters.rb +28 -24
  3. data/lib/picky/adapters/rack/search.rb +67 -0
  4. data/lib/picky/adapters/rack.rb +27 -23
  5. data/lib/picky/application.rb +246 -236
  6. data/lib/picky/backend/base.rb +115 -119
  7. data/lib/picky/backend/file/basic.rb +102 -98
  8. data/lib/picky/backend/file/json.rb +27 -23
  9. data/lib/picky/backend/file/marshal.rb +32 -28
  10. data/lib/picky/backend/file/text.rb +45 -41
  11. data/lib/picky/backend/files.rb +19 -15
  12. data/lib/picky/backend/redis/basic.rb +76 -72
  13. data/lib/picky/backend/redis/list_hash.rb +40 -36
  14. data/lib/picky/backend/redis/string_hash.rb +30 -26
  15. data/lib/picky/backend/redis.rb +32 -28
  16. data/lib/picky/bundle.rb +82 -57
  17. data/lib/{bundling.rb → picky/bundling.rb} +0 -0
  18. data/lib/picky/calculations/location.rb +51 -47
  19. data/lib/picky/categories.rb +60 -56
  20. data/lib/picky/categories_indexed.rb +73 -82
  21. data/lib/picky/categories_indexing.rb +12 -8
  22. data/lib/picky/category.rb +109 -120
  23. data/lib/picky/category_indexed.rb +39 -41
  24. data/lib/picky/category_indexing.rb +123 -125
  25. data/lib/picky/character_substituters/west_european.rb +32 -26
  26. data/lib/{constants.rb → picky/constants.rb} +0 -0
  27. data/lib/picky/cores.rb +96 -92
  28. data/lib/{deployment.rb → picky/deployment.rb} +0 -0
  29. data/lib/picky/frontend_adapters/rack.rb +133 -118
  30. data/lib/picky/generators/aliases.rb +5 -3
  31. data/lib/picky/generators/base.rb +11 -7
  32. data/lib/picky/generators/partial/default.rb +7 -3
  33. data/lib/picky/generators/partial/none.rb +24 -20
  34. data/lib/picky/generators/partial/strategy.rb +20 -16
  35. data/lib/picky/generators/partial/substring.rb +94 -90
  36. data/lib/picky/generators/partial_generator.rb +11 -7
  37. data/lib/picky/generators/similarity/default.rb +9 -5
  38. data/lib/picky/generators/similarity/double_metaphone.rb +20 -16
  39. data/lib/picky/generators/similarity/metaphone.rb +20 -16
  40. data/lib/picky/generators/similarity/none.rb +23 -19
  41. data/lib/picky/generators/similarity/phonetic.rb +49 -45
  42. data/lib/picky/generators/similarity/soundex.rb +20 -16
  43. data/lib/picky/generators/similarity/strategy.rb +10 -6
  44. data/lib/picky/generators/similarity_generator.rb +11 -7
  45. data/lib/picky/generators/strategy.rb +14 -10
  46. data/lib/picky/generators/weights/default.rb +9 -5
  47. data/lib/picky/generators/weights/logarithmic.rb +30 -26
  48. data/lib/picky/generators/weights/strategy.rb +10 -6
  49. data/lib/picky/generators/weights_generator.rb +11 -7
  50. data/lib/picky/helpers/measuring.rb +20 -16
  51. data/lib/picky/indexed/bundle/base.rb +39 -37
  52. data/lib/picky/indexed/bundle/memory.rb +68 -64
  53. data/lib/picky/indexed/bundle/redis.rb +73 -69
  54. data/lib/picky/indexed/wrappers/bundle/calculation.rb +26 -22
  55. data/lib/picky/indexed/wrappers/bundle/location.rb +30 -26
  56. data/lib/picky/indexed/wrappers/bundle/wrapper.rb +36 -32
  57. data/lib/picky/indexed/wrappers/category/location.rb +17 -13
  58. data/lib/picky/indexed/wrappers/exact_first.rb +46 -42
  59. data/lib/picky/indexers/base.rb +26 -22
  60. data/lib/picky/indexers/parallel.rb +62 -58
  61. data/lib/picky/indexers/serial.rb +41 -37
  62. data/lib/picky/indexes/index.rb +400 -0
  63. data/lib/picky/indexes/index_indexed.rb +24 -0
  64. data/lib/picky/indexes/index_indexing.rb +138 -0
  65. data/lib/picky/indexes/memory.rb +20 -0
  66. data/lib/picky/indexes/redis.rb +20 -0
  67. data/lib/picky/indexes.rb +68 -61
  68. data/lib/picky/indexes_indexed.rb +16 -12
  69. data/lib/picky/indexes_indexing.rb +41 -37
  70. data/lib/picky/indexing/bundle/base.rb +216 -205
  71. data/lib/picky/indexing/bundle/memory.rb +16 -11
  72. data/lib/picky/indexing/bundle/redis.rb +14 -12
  73. data/lib/picky/indexing/wrappers/category/location.rb +17 -13
  74. data/lib/picky/interfaces/live_parameters.rb +159 -154
  75. data/lib/picky/loader.rb +267 -304
  76. data/lib/picky/loggers/search.rb +20 -13
  77. data/lib/picky/no_source_specified_exception.rb +7 -3
  78. data/lib/picky/performant.rb +6 -2
  79. data/lib/picky/query/allocation.rb +71 -67
  80. data/lib/picky/query/allocations.rb +99 -94
  81. data/lib/picky/query/combination.rb +70 -66
  82. data/lib/picky/query/combinations/base.rb +56 -52
  83. data/lib/picky/query/combinations/memory.rb +36 -32
  84. data/lib/picky/query/combinations/redis.rb +66 -62
  85. data/lib/picky/query/indexes.rb +175 -160
  86. data/lib/picky/query/qualifier_category_mapper.rb +43 -0
  87. data/lib/picky/query/token.rb +165 -172
  88. data/lib/picky/query/tokens.rb +86 -82
  89. data/lib/picky/query/weights.rb +44 -48
  90. data/lib/picky/query.rb +5 -1
  91. data/lib/picky/rack/harakiri.rb +51 -47
  92. data/lib/picky/results.rb +81 -77
  93. data/lib/picky/search.rb +169 -158
  94. data/lib/picky/sinatra.rb +34 -0
  95. data/lib/picky/sources/base.rb +73 -70
  96. data/lib/picky/sources/couch.rb +61 -57
  97. data/lib/picky/sources/csv.rb +68 -64
  98. data/lib/picky/sources/db.rb +139 -135
  99. data/lib/picky/sources/delicious.rb +52 -48
  100. data/lib/picky/sources/mongo.rb +68 -63
  101. data/lib/picky/sources/wrappers/base.rb +20 -16
  102. data/lib/picky/sources/wrappers/location.rb +37 -33
  103. data/lib/picky/statistics.rb +46 -43
  104. data/lib/picky/tasks.rb +3 -0
  105. data/lib/picky/tokenizers/base.rb +192 -187
  106. data/lib/picky/tokenizers/index.rb +25 -21
  107. data/lib/picky/tokenizers/location.rb +33 -29
  108. data/lib/picky/tokenizers/query.rb +49 -43
  109. data/lib/picky.rb +21 -13
  110. data/lib/tasks/application.rake +1 -1
  111. data/lib/tasks/index.rake +3 -3
  112. data/lib/tasks/routes.rake +1 -1
  113. data/lib/tasks/server.rake +1 -1
  114. data/spec/lib/adapters/rack/base_spec.rb +1 -1
  115. data/spec/lib/adapters/rack/live_parameters_spec.rb +1 -1
  116. data/spec/lib/adapters/rack/query_spec.rb +1 -1
  117. data/spec/lib/application_spec.rb +39 -32
  118. data/spec/lib/backend/file/basic_spec.rb +2 -2
  119. data/spec/lib/backend/file/json_spec.rb +2 -2
  120. data/spec/lib/backend/file/marshal_spec.rb +2 -2
  121. data/spec/lib/backend/file/text_spec.rb +1 -1
  122. data/spec/lib/backend/files_spec.rb +14 -24
  123. data/spec/lib/backend/redis/basic_spec.rb +2 -2
  124. data/spec/lib/backend/redis/list_hash_spec.rb +3 -3
  125. data/spec/lib/backend/redis/string_hash_spec.rb +3 -3
  126. data/spec/lib/backend/redis_spec.rb +20 -13
  127. data/spec/lib/calculations/location_spec.rb +1 -1
  128. data/spec/lib/categories_indexed_spec.rb +16 -34
  129. data/spec/lib/category_indexed_spec.rb +9 -27
  130. data/spec/lib/category_indexing_spec.rb +2 -3
  131. data/spec/lib/category_spec.rb +10 -10
  132. data/spec/lib/character_substituters/west_european_spec.rb +6 -5
  133. data/spec/lib/cores_spec.rb +17 -17
  134. data/spec/lib/extensions/symbol_spec.rb +15 -1
  135. data/spec/lib/frontend_adapters/rack_spec.rb +20 -20
  136. data/spec/lib/generators/aliases_spec.rb +3 -3
  137. data/spec/lib/generators/cacher_strategy_spec.rb +1 -1
  138. data/spec/lib/generators/partial/default_spec.rb +3 -3
  139. data/spec/lib/generators/partial/none_spec.rb +2 -2
  140. data/spec/lib/generators/partial/substring_spec.rb +1 -1
  141. data/spec/lib/generators/partial_generator_spec.rb +3 -3
  142. data/spec/lib/generators/similarity/double_metaphone_spec.rb +1 -1
  143. data/spec/lib/generators/similarity/metaphone_spec.rb +1 -1
  144. data/spec/lib/generators/similarity/none_spec.rb +1 -1
  145. data/spec/lib/generators/similarity/phonetic_spec.rb +1 -1
  146. data/spec/lib/generators/similarity/soundex_spec.rb +1 -1
  147. data/spec/lib/generators/similarity_generator_spec.rb +2 -2
  148. data/spec/lib/generators/weights/logarithmic_spec.rb +1 -1
  149. data/spec/lib/generators/weights_generator_spec.rb +1 -1
  150. data/spec/lib/helpers/measuring_spec.rb +2 -2
  151. data/spec/lib/indexed/bundle/memory_spec.rb +6 -6
  152. data/spec/lib/indexed/bundle/redis_spec.rb +4 -4
  153. data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +2 -3
  154. data/spec/lib/indexed/wrappers/bundle/wrapper_spec.rb +2 -2
  155. data/spec/lib/indexed/wrappers/exact_first_spec.rb +5 -5
  156. data/spec/lib/indexers/base_spec.rb +1 -1
  157. data/spec/lib/indexers/parallel_spec.rb +1 -1
  158. data/spec/lib/indexers/serial_spec.rb +1 -1
  159. data/spec/lib/{index/base_indexed_spec.rb → indexes/index_indexed_spec.rb} +3 -3
  160. data/spec/lib/{index/base_indexing_spec.rb → indexes/index_indexing_spec.rb} +19 -2
  161. data/spec/lib/{index/base_spec.rb → indexes/index_spec.rb} +6 -25
  162. data/spec/lib/{index → indexes}/redis_spec.rb +1 -1
  163. data/spec/lib/indexes_class_spec.rb +2 -2
  164. data/spec/lib/indexes_indexed_spec.rb +1 -1
  165. data/spec/lib/indexes_indexing_spec.rb +1 -1
  166. data/spec/lib/indexes_spec.rb +1 -1
  167. data/spec/lib/indexing/bundle/base_spec.rb +7 -5
  168. data/spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb +4 -4
  169. data/spec/lib/indexing/bundle/memory_spec.rb +15 -15
  170. data/spec/lib/indexing/bundle/redis_spec.rb +9 -9
  171. data/spec/lib/interfaces/live_parameters_spec.rb +5 -5
  172. data/spec/lib/loader_spec.rb +17 -19
  173. data/spec/lib/loggers/search_spec.rb +2 -2
  174. data/spec/lib/query/allocation_spec.rb +1 -1
  175. data/spec/lib/query/allocations_spec.rb +1 -1
  176. data/spec/lib/query/combination_spec.rb +4 -4
  177. data/spec/lib/query/combinations/base_spec.rb +1 -1
  178. data/spec/lib/query/combinations/memory_spec.rb +1 -1
  179. data/spec/lib/query/combinations/redis_spec.rb +1 -1
  180. data/spec/lib/query/indexes_spec.rb +7 -2
  181. data/spec/lib/query/qualifier_category_mapper_spec.rb +34 -0
  182. data/spec/lib/query/token_spec.rb +32 -53
  183. data/spec/lib/query/tokens_spec.rb +30 -35
  184. data/spec/lib/query/weights_spec.rb +16 -16
  185. data/spec/lib/rack/harakiri_spec.rb +5 -5
  186. data/spec/lib/results_spec.rb +1 -1
  187. data/spec/lib/search_spec.rb +24 -22
  188. data/spec/lib/sinatra_spec.rb +36 -0
  189. data/spec/lib/sources/base_spec.rb +1 -1
  190. data/spec/lib/sources/couch_spec.rb +9 -9
  191. data/spec/lib/sources/csv_spec.rb +7 -7
  192. data/spec/lib/sources/db_spec.rb +2 -2
  193. data/spec/lib/sources/delicious_spec.rb +5 -5
  194. data/spec/lib/sources/mongo_spec.rb +7 -7
  195. data/spec/lib/sources/wrappers/base_spec.rb +2 -2
  196. data/spec/lib/sources/wrappers/location_spec.rb +1 -1
  197. data/spec/lib/statistics_spec.rb +1 -1
  198. data/spec/lib/tokenizers/base_spec.rb +2 -2
  199. data/spec/lib/tokenizers/index_spec.rb +1 -1
  200. data/spec/lib/tokenizers/query_spec.rb +1 -1
  201. metadata +30 -30
  202. data/lib/picky/adapters/rack/query.rb +0 -65
  203. data/lib/picky/index/base.rb +0 -409
  204. data/lib/picky/index/base_indexed.rb +0 -29
  205. data/lib/picky/index/base_indexing.rb +0 -127
  206. data/lib/picky/index/memory.rb +0 -16
  207. data/lib/picky/index/redis.rb +0 -16
  208. data/lib/picky/query/qualifiers.rb +0 -76
  209. data/lib/picky/query/solr.rb +0 -60
  210. data/lib/picky/signals.rb +0 -8
  211. data/lib/picky-tasks.rb +0 -6
  212. data/lib/tasks/spec.rake +0 -11
  213. data/spec/lib/query/qualifiers_spec.rb +0 -31
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Backend::Redis::StringHash do
3
+ describe Picky::Backend::Redis::StringHash do
4
4
 
5
5
  let(:index) { described_class.new :some_namespace }
6
6
 
@@ -17,7 +17,7 @@ describe Backend::Redis::StringHash do
17
17
 
18
18
  describe 'collection' do
19
19
  it 'raises' do
20
- expect { index.collection :anything }.to raise_error("Can't retrieve collection for :anything from a StringHash. Use Index::Redis::ListHash.")
20
+ expect { index.collection :anything }.to raise_error("Can't retrieve collection for :anything from a StringHash. Use Indexes::Redis::ListHash.")
21
21
  end
22
22
  end
23
23
 
@@ -40,7 +40,7 @@ describe Backend::Redis::StringHash do
40
40
 
41
41
  describe 'to_s' do
42
42
  it 'returns the cache path with the default file extension' do
43
- index.to_s.should == 'Backend::Redis::StringHash(some_namespace:*)'
43
+ index.to_s.should == 'Picky::Backend::Redis::StringHash(some_namespace:*)'
44
44
  end
45
45
  end
46
46
 
@@ -1,16 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Backend::Redis do
3
+ describe Picky::Backend::Redis do
4
4
 
5
5
  context 'indexing' do
6
6
  let(:category) do
7
7
  index = stub :index,
8
8
  :name => :some_index,
9
- :indexing_bundle_class => Indexing::Bundle::Memory,
10
- :indexed_bundle_class => Indexed::Bundle::Memory
11
- category = Category.new :some_category, index
9
+ :indexing_bundle_class => Picky::Indexing::Bundle::Memory,
10
+ :indexed_bundle_class => Picky::Indexed::Bundle::Memory,
11
+ :identifier => :some_index_identifier
12
+ Picky::Category.new :some_category, index
12
13
  end
13
- let(:redis) { described_class.new :some_name, category }
14
+ let(:bundle) { Picky::Indexing::Bundle::Memory.new :some_bundle, category, nil, nil, nil }
15
+ let(:redis) { described_class.new bundle }
14
16
 
15
17
  describe 'setting' do
16
18
  it 'delegates to the configuration' do
@@ -78,13 +80,15 @@ describe Backend::Redis do
78
80
 
79
81
  context 'indexed' do
80
82
  let(:category) do
81
- index = stub :index,
82
- :name => :some_index,
83
- :indexing_bundle_class => Indexing::Bundle::Memory,
84
- :indexed_bundle_class => Indexed::Bundle::Memory
85
- category = Category.new :some_category, index
83
+ index = stub :index,
84
+ :name => :some_index,
85
+ :indexing_bundle_class => Picky::Indexing::Bundle::Memory,
86
+ :indexed_bundle_class => Picky::Indexed::Bundle::Memory,
87
+ :identifier => :some_index_identifier
88
+ Picky::Category.new :some_category, index
86
89
  end
87
- let(:redis) { described_class.new :some_name, category }
90
+ let(:bundle) { Picky::Indexing::Bundle::Memory.new :some_bundle, category, nil, nil, nil }
91
+ let(:redis) { described_class.new bundle }
88
92
 
89
93
  describe 'setting' do
90
94
  it 'delegates to the configuration' do
@@ -153,10 +157,13 @@ describe Backend::Redis do
153
157
  describe 'to_s' do
154
158
  it 'returns the right value' do
155
159
  category = stub :category,
160
+ :name => :some_category,
156
161
  :identifier => "category_identifier",
157
- :prepared_index_path => "prepared/index/path"
162
+ :prepared_index_path => "prepared/index/path",
163
+ :index_directory => 'some/index/directory'
164
+ bundle = Picky::Indexing::Bundle::Memory.new :some_bundle, category, nil, nil, nil
158
165
 
159
- described_class.new("some_bundle", category).to_s.should == "Backend::Redis(Backend::File::Text(prepared/index/path.txt), some_bundle, category_identifier)"
166
+ described_class.new(bundle).to_s.should == "Picky::Backend::Redis(category_identifier:some_bundle)"
160
167
  end
161
168
  end
162
169
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Calculations::Location do
3
+ describe Picky::Calculations::Location do
4
4
 
5
5
  context 'with precision 1' do
6
6
  before(:each) do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Categories do
3
+ describe Picky::Categories do
4
4
  context 'with option ignore_unassigned_tokens' do
5
5
  context 'ignore_unassigned_tokens true' do
6
6
  before(:each) do
@@ -22,16 +22,16 @@ describe Categories do
22
22
 
23
23
  context "with real categories" do
24
24
  before(:each) do
25
- @index1 = Index::Memory.new :name, source: []
25
+ @index1 = Picky::Indexes::Memory.new :name, source: []
26
26
 
27
27
  @categories = described_class.new
28
- @categories << Category.new(:category1, @index1)
29
- @categories << Category.new(:category2, @index1)
30
- @categories << Category.new(:category3, @index1)
28
+ @categories << Picky::Category.new(:category1, @index1)
29
+ @categories << Picky::Category.new(:category2, @index1)
30
+ @categories << Picky::Category.new(:category3, @index1)
31
31
  end
32
32
  describe "similar_possible_for" do
33
33
  before(:each) do
34
- @token = Query::Token.processed 'similar~'
34
+ @token = Picky::Query::Token.processed 'similar~'
35
35
  end
36
36
  it "returns possible categories" do
37
37
  @categories.similar_possible_for(@token).should == []
@@ -65,11 +65,11 @@ describe Categories do
65
65
 
66
66
  context 'without options' do
67
67
  before(:each) do
68
- @index1 = Index::Memory.new :some_index, source: []
68
+ @index1 = Picky::Indexes::Memory.new :some_index, source: []
69
69
 
70
- @category1 = Category.new :category1, @index1
71
- @category2 = Category.new :category2, @index1
72
- @category3 = Category.new :category3, @index1
70
+ @category1 = Picky::Category.new :category1, @index1
71
+ @category2 = Picky::Category.new :category2, @index1
72
+ @category3 = Picky::Category.new :category3, @index1
73
73
 
74
74
  @categories = described_class.new
75
75
  @categories << @category1
@@ -77,7 +77,7 @@ describe Categories do
77
77
  @categories << @category3
78
78
  end
79
79
 
80
- describe "possible_combinations_for" do
80
+ describe "possible_combinations" do
81
81
  before(:each) do
82
82
  @token = stub :token
83
83
  end
@@ -88,7 +88,7 @@ describe Categories do
88
88
  it "calls the right method" do
89
89
  @categories.should_receive(:similar_possible_for).once.with @token
90
90
 
91
- @categories.possible_combinations_for @token
91
+ @categories.possible_combinations @token
92
92
  end
93
93
  end
94
94
  context "with non-similar token" do
@@ -98,7 +98,7 @@ describe Categories do
98
98
  it "calls the right method" do
99
99
  @categories.should_receive(:possible_for).once.with @token
100
100
 
101
- @categories.possible_combinations_for @token
101
+ @categories.possible_combinations @token
102
102
  end
103
103
  end
104
104
  end
@@ -107,7 +107,7 @@ describe Categories do
107
107
  context 'without preselected categories' do
108
108
  context 'user defined exists' do
109
109
  before(:each) do
110
- @token = stub :token, :user_defined_category_names => [:category2]
110
+ @token = stub :token, :user_defined_categories => [@category2]
111
111
  end
112
112
  context 'combination exists' do
113
113
  before(:each) do
@@ -139,7 +139,7 @@ describe Categories do
139
139
  describe 'possible_categories' do
140
140
  context 'user defined exists' do
141
141
  before(:each) do
142
- @token = stub :token, :user_defined_category_names => [:category2]
142
+ @token = stub :token, :user_defined_categories => [@category2]
143
143
  end
144
144
  it 'should return the right categories' do
145
145
  @categories.possible_categories(@token).should == [@category2]
@@ -147,7 +147,7 @@ describe Categories do
147
147
  end
148
148
  context 'user defined does not exist' do
149
149
  before(:each) do
150
- @token = stub :token, :user_defined_category_names => nil
150
+ @token = stub :token, :user_defined_categories => nil
151
151
  end
152
152
  it 'should return all categories' do
153
153
  @categories.possible_categories(@token).should == [@category1, @category2, @category3]
@@ -155,24 +155,6 @@ describe Categories do
155
155
  end
156
156
  end
157
157
 
158
- describe 'user_defined_categories' do
159
- context 'category exists' do
160
- before(:each) do
161
- @token = stub :token, :user_defined_category_names => [:category2]
162
- end
163
- it 'should return the right categories' do
164
- @categories.user_defined_categories(@token).should == [@category2]
165
- end
166
- end
167
- context 'category does not exist' do
168
- before(:each) do
169
- @token = stub :token, :user_defined_category_names => [:gnoergel]
170
- end
171
- it 'should return nil' do
172
- @categories.user_defined_categories(@token).should == []
173
- end
174
- end
175
- end
176
158
  end
177
159
 
178
160
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Category do
3
+ describe Picky::Category do
4
4
 
5
5
  before(:each) do
6
- @index = Index::Base.new :some_index, source: []
6
+ @index = Picky::Indexes::Index.new :some_index, source: []
7
7
  @partial_strategy = stub :partial, :use_exact_for_partial? => false
8
8
  @weights_strategy = stub :weights
9
9
  @similarity_strategy = stub :similarity
@@ -29,53 +29,35 @@ describe Category do
29
29
  @partial_strategy.stub! :use_exact_for_partial? => true
30
30
  end
31
31
  it 'returns the partial index' do
32
- @category.indexed_partial.should be_kind_of(Indexed::Bundle::Memory)
32
+ @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle::Memory)
33
33
  end
34
34
  end
35
35
  context 'with a partial strategy that uses the partial index (default)' do
36
36
  it 'returns the partial index' do
37
- @category.indexed_partial.should be_kind_of(Indexed::Bundle::Memory)
37
+ @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle::Memory)
38
38
  end
39
39
  end
40
40
  end
41
41
  context 'indexed_bundle_class defined differently' do
42
42
  before(:each) do
43
- @category = described_class.new :some_name, Index::Redis.new(:some_index_name, source: [])
43
+ @category = described_class.new :some_name, Picky::Indexes::Redis.new(:some_index_name, source: [])
44
44
  end
45
45
  context 'with a partial strategy that uses the exact index' do
46
46
  before(:each) do
47
47
  @partial_strategy.stub! :use_exact_for_partial? => true
48
48
  end
49
49
  it 'returns the partial index' do
50
- @category.indexed_partial.should be_kind_of(Indexed::Bundle::Redis)
50
+ @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle::Redis)
51
51
  end
52
52
  end
53
53
  context 'with a partial strategy that uses the partial index (default)' do
54
54
  it 'returns the partial index' do
55
- @category.indexed_partial.should be_kind_of(Indexed::Bundle::Redis)
55
+ @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle::Redis)
56
56
  end
57
57
  end
58
58
  end
59
59
  end
60
60
 
61
- describe 'generate_qualifiers_from' do
62
- context 'with qualifiers' do
63
- it 'returns that' do
64
- @category.generate_qualifiers_from(:qualifiers => [:a, :b]).should == [:a, :b]
65
- end
66
- end
67
- context 'without anything' do
68
- it 'returns that' do
69
- @category.generate_qualifiers_from({}).should == nil
70
- end
71
- end
72
- context 'with qualifier' do
73
- it 'returns that' do
74
- @category.generate_qualifiers_from(:qualifier => :a).should == [:a]
75
- end
76
- end
77
- end
78
-
79
61
  describe 'weight' do
80
62
  before(:each) do
81
63
  @token = stub :token, :text => :some_text
@@ -143,10 +125,10 @@ describe Category do
143
125
  @category.stub! :weight => :some_weight, :bundle_for => :bundle
144
126
  end
145
127
  it 'should return a new combination' do
146
- @category.combination_for(@token).should be_kind_of(Query::Combination)
128
+ @category.combination_for(@token).should be_kind_of(Picky::Query::Combination)
147
129
  end
148
130
  it 'should create the combination correctly' do
149
- Query::Combination.should_receive(:new).once.with @token, @category
131
+ Picky::Query::Combination.should_receive(:new).once.with @token, @category
150
132
 
151
133
  @category.combination_for @token
152
134
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Category do
3
+ describe Picky::Category do
4
4
 
5
5
  before(:each) do
6
- @index = Index::Memory.new :some_index, source: []
6
+ @index = Picky::Indexes::Memory.new :some_index, source: []
7
7
  @source = stub :some_given_source, :key_format => nil
8
8
  end
9
9
  let(:category) { described_class.new(:some_category, @index, :source => @source).tap { |c| c.stub! :timed_exclaim } }
@@ -96,7 +96,6 @@ describe Category do
96
96
 
97
97
  describe 'cache' do
98
98
  it 'should call multiple methods in order' do
99
- category.should_receive(:configure).once.with().ordered
100
99
  category.should_receive(:generate_caches_from_source).once.with().ordered
101
100
  category.should_receive(:generate_partial).once.with().ordered
102
101
  category.should_receive(:generate_caches_from_memory).once.with().ordered
@@ -1,22 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Category do
3
+ describe Picky::Category do
4
4
 
5
- let(:index) { Index::Memory.new :some_index, source: [] }
5
+ let(:index) { Picky::Indexes::Memory.new :some_index, source: [] }
6
6
  let(:category) { described_class.new :some_category, index }
7
7
 
8
8
  it 'should set defaults correctly' do
9
- category.indexing_exact.weights_strategy.should == Generators::Weights::Default
10
- category.indexing_exact.partial_strategy.should be_kind_of(Generators::Partial::None)
11
- category.indexing_exact.similarity_strategy.should == Generators::Similarity::Default
9
+ category.indexing_exact.weights_strategy.should == Picky::Generators::Weights::Default
10
+ category.indexing_exact.partial_strategy.should be_kind_of(Picky::Generators::Partial::None)
11
+ category.indexing_exact.similarity_strategy.should == Picky::Generators::Similarity::Default
12
12
 
13
- category.indexing_partial.weights_strategy.should be_kind_of(Generators::Weights::Logarithmic)
14
- category.indexing_partial.partial_strategy.should == Generators::Partial::Default
15
- category.indexing_partial.similarity_strategy.should be_kind_of(Generators::Similarity::None)
13
+ category.indexing_partial.weights_strategy.should be_kind_of(Picky::Generators::Weights::Logarithmic)
14
+ category.indexing_partial.partial_strategy.should == Picky::Generators::Partial::Default
15
+ category.indexing_partial.similarity_strategy.should be_kind_of(Picky::Generators::Similarity::None)
16
16
 
17
- category.indexed_exact.similarity_strategy.should == Generators::Similarity::Default
17
+ category.indexed_exact.similarity_strategy.should == Picky::Generators::Similarity::Default
18
18
 
19
- category.indexed_partial.similarity_strategy.should be_kind_of(Generators::Similarity::None)
19
+ category.indexed_partial.similarity_strategy.should be_kind_of(Picky::Generators::Similarity::None)
20
20
  end
21
21
 
22
22
  end
@@ -2,19 +2,20 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe CharacterSubstituters do
5
+ describe Picky::CharacterSubstituters::WestEuropean do
6
+
6
7
  before(:all) do
7
- @substituter = CharacterSubstituters::WestEuropean.new.tap { |s| s.substitute '' }
8
+ @substituter = described_class.new.tap { |s| s.substitute '' }
8
9
  end
9
10
 
10
11
  # A bit of metaprogramming to help with the myriads of its.
11
12
  #
12
- def self.it_should_substitute(special_character, normal_character)
13
+ def self.it_should_substitute special_character, normal_character
13
14
  it "should substitute #{special_character} with #{normal_character}" do
14
15
  @substituter.substitute(special_character).should == normal_character
15
16
  end
16
17
  end
17
- def self.it_should_not_substitute(special_character)
18
+ def self.it_should_not_substitute special_character
18
19
  it "should not substitute #{special_character}" do
19
20
  @substituter.substitute(special_character).should == special_character
20
21
  end
@@ -36,7 +37,7 @@ describe CharacterSubstituters do
36
37
 
37
38
  describe 'to_s' do
38
39
  it 'outputs correctly' do
39
- @substituter.to_s.should == 'CharacterSubstituters::WestEuropean'
40
+ @substituter.to_s.should == 'Picky::CharacterSubstituters::WestEuropean'
40
41
  end
41
42
  end
42
43
 
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe Cores do
4
+ describe Picky::Cores do
5
5
 
6
6
  describe ".forked" do
7
7
  before(:each) do
@@ -10,13 +10,13 @@ describe Cores do
10
10
  context "with array" do
11
11
  context "with block" do
12
12
  it "runs ok" do
13
- Cores.forked([1, 2]) do |e|
13
+ described_class.forked([1, 2]) do |e|
14
14
 
15
15
  end
16
16
  end
17
17
  it "yields the elements" do
18
18
  result = []
19
- Cores.forked([1, 2]) do |e|
19
+ described_class.forked([1, 2]) do |e|
20
20
  result << e
21
21
  end
22
22
  result.should == [1, 2]
@@ -25,7 +25,7 @@ describe Cores do
25
25
  context "without block" do
26
26
  it "fails" do
27
27
  lambda {
28
- Cores.forked [1, 2]
28
+ described_class.forked [1, 2]
29
29
  }.should raise_error("Block argument needed when running Cores.forked")
30
30
  end
31
31
  end
@@ -33,14 +33,14 @@ describe Cores do
33
33
  context "with empty array" do
34
34
  context "with block" do
35
35
  it "runs ok" do
36
- Cores.forked([]) do
36
+ described_class.forked([]) do
37
37
 
38
38
  end
39
39
  end
40
40
  end
41
41
  context "without block" do
42
42
  it "runs ok" do
43
- Cores.forked []
43
+ described_class.forked []
44
44
  end
45
45
  end
46
46
  end
@@ -50,57 +50,57 @@ describe Cores do
50
50
  before(:each) do
51
51
  @linux = mock :linux, :null_object => true
52
52
  @darwin = mock :darwin, :null_object => true
53
- Cores.stub! :os_to_core_mapping => {
53
+ described_class.stub! :os_to_core_mapping => {
54
54
  'linux' => @linux,
55
55
  'darwin' => @darwin
56
56
  }
57
57
  end
58
58
  context 'default' do
59
59
  before(:each) do
60
- Cores.stub! :platform => 'mswin'
60
+ described_class.stub! :platform => 'mswin'
61
61
  end
62
62
  it 'should return 1' do
63
- Cores.number_of_cores.should == 1
63
+ described_class.number_of_cores.should == 1
64
64
  end
65
65
  end
66
66
  context 'osx' do
67
67
  before(:each) do
68
- Cores.stub! :platform => 'i386-darwin9.8.0'
68
+ described_class.stub! :platform => 'i386-darwin9.8.0'
69
69
  end
70
70
  it 'should return whatever darwin returns' do
71
71
  @darwin.stub! :call => '1234'
72
72
 
73
- Cores.number_of_cores.should == 1234
73
+ described_class.number_of_cores.should == 1234
74
74
  end
75
75
  it 'should call darwin' do
76
76
  @darwin.should_receive(:call).once
77
77
 
78
- Cores.number_of_cores
78
+ described_class.number_of_cores
79
79
  end
80
80
  it 'should not call linux' do
81
81
  @linux.should_receive(:call).never
82
82
 
83
- Cores.number_of_cores
83
+ described_class.number_of_cores
84
84
  end
85
85
  end
86
86
  context 'linux' do
87
87
  before(:each) do
88
- Cores.stub! :platform => 'x86_64-linux'
88
+ described_class.stub! :platform => 'x86_64-linux'
89
89
  end
90
90
  it 'should return whatever linux returns' do
91
91
  @linux.stub! :call => '1234'
92
92
 
93
- Cores.number_of_cores.should == 1234
93
+ described_class.number_of_cores.should == 1234
94
94
  end
95
95
  it 'should call linux' do
96
96
  @linux.should_receive(:call).once
97
97
 
98
- Cores.number_of_cores
98
+ described_class.number_of_cores
99
99
  end
100
100
  it 'should not call darwin' do
101
101
  @darwin.should_receive(:call).never
102
102
 
103
- Cores.number_of_cores
103
+ described_class.number_of_cores
104
104
  end
105
105
  end
106
106
  end
@@ -1,9 +1,11 @@
1
+ # encoding: utf-8
2
+ #
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Symbol do
4
6
 
5
7
  context 'performance' do
6
- include Helpers::Measuring
8
+ include Picky::Helpers::Measuring
7
9
  before(:each) do
8
10
  @token = (((0..9).to_a)*10).to_s.to_sym
9
11
  end
@@ -99,6 +101,18 @@ describe Symbol do
99
101
  end
100
102
  end
101
103
  end
104
+ context 'japanese symbol' do
105
+ before(:each) do
106
+ @sym = :日本語
107
+ end
108
+ it "should return an array of japanese symbols, each 1 smaller than the other" do
109
+ result = []
110
+ @sym.each_subtoken do |subtoken|
111
+ result << subtoken
112
+ end
113
+ result.should == [:日本語, :日本, :日]
114
+ end
115
+ end
102
116
  context 'very short symbol' do
103
117
  before(:each) do
104
118
  @sym = :r