picky 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/lib/picky/application.rb +38 -37
  2. data/lib/picky/cacher/partial/default.rb +1 -3
  3. data/lib/picky/cacher/partial/subtoken.rb +44 -18
  4. data/lib/picky/configuration/field.rb +6 -2
  5. data/lib/picky/configuration/indexes.rb +16 -7
  6. data/lib/picky/configuration/queries.rb +3 -13
  7. data/lib/picky/extensions/symbol.rb +19 -4
  8. data/lib/picky/generator.rb +9 -0
  9. data/lib/picky/helpers/measuring.rb +3 -3
  10. data/lib/picky/index/bundle.rb +5 -4
  11. data/lib/picky/index/category.rb +14 -7
  12. data/lib/picky/index/combined.rb +6 -1
  13. data/lib/picky/indexers/no_source_specified_error.rb +2 -0
  14. data/lib/picky/indexes.rb +3 -9
  15. data/lib/picky/query/allocation.rb +1 -1
  16. data/lib/picky/query/allocations.rb +2 -2
  17. data/lib/picky/rack/harakiri.rb +10 -8
  18. data/lib/picky/routing.rb +19 -21
  19. data/lib/picky/solr/schema_generator.rb +4 -4
  20. data/lib/picky/sources/base.rb +16 -4
  21. data/lib/picky/sources/csv.rb +3 -0
  22. data/lib/picky/sources/db.rb +30 -22
  23. data/lib/picky/tokenizers/base.rb +7 -5
  24. data/lib/picky/tokenizers/index.rb +5 -5
  25. data/lib/picky/tokenizers/query.rb +9 -9
  26. data/prototype_project/app/application.rb +36 -29
  27. data/prototype_project/app/db.yml +1 -1
  28. data/prototype_project/config.ru +3 -2
  29. data/spec/ext/performant_spec.rb +2 -2
  30. data/spec/lib/application_spec.rb +54 -8
  31. data/spec/lib/cacher/partial/default_spec.rb +15 -0
  32. data/spec/lib/cacher/partial/subtoken_spec.rb +54 -2
  33. data/spec/lib/extensions/symbol_spec.rb +124 -30
  34. data/spec/lib/index/bundle_partial_generation_speed_spec.rb +1 -1
  35. data/spec/lib/query/allocations_spec.rb +5 -5
  36. data/spec/lib/query/combinations_spec.rb +3 -3
  37. data/spec/lib/rack/harakiri_spec.rb +29 -0
  38. data/spec/lib/routing_spec.rb +22 -98
  39. data/spec/lib/tokenizers/index_spec.rb +1 -1
  40. data/spec/specific/speed_spec.rb +4 -5
  41. metadata +7 -3
@@ -62,21 +62,21 @@ describe 'Query::Combinations' do
62
62
  @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
63
63
  @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
64
64
 
65
- Benchmark.realtime { @combinations.ids }.should <= 0.004
65
+ Benchmark.realtime { @combinations.ids }.should < 0.004
66
66
  end
67
67
  it "should be fast" do
68
68
  @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
69
69
  @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
70
70
  @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
71
71
 
72
- Benchmark.realtime { @combinations.ids }.should <= 0.00015
72
+ Benchmark.realtime { @combinations.ids }.should < 0.00015
73
73
  end
74
74
  it "should be fast" do
75
75
  @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
76
76
  @combination2.should_receive(:ids).once.with.and_return (901..1000).to_a
77
77
  @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
78
78
 
79
- Benchmark.realtime { @combinations.ids }.should <= 0.0001
79
+ Benchmark.realtime { @combinations.ids }.should < 0.0001
80
80
  end
81
81
  end
82
82
 
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Rack::Harakiri do
5
+ before(:each) do
6
+ @app = stub :app
7
+ end
8
+ context "defaults" do
9
+ before(:each) do
10
+ @harakiri = Rack::Harakiri.new @app
11
+ end
12
+ it "should quit after an amount of requests" do
13
+ @harakiri.quit_after_requests.should == 50
14
+ end
15
+ end
16
+ context "with harakiri set" do
17
+ before(:each) do
18
+ Rack::Harakiri.after = 100
19
+ @harakiri = Rack::Harakiri.new @app
20
+ end
21
+ after(:each) do
22
+ Rack::Harakiri.after = nil
23
+ end
24
+ it "should quit after an amount of requests" do
25
+ @harakiri.quit_after_requests.should == 100
26
+ end
27
+ end
28
+
29
+ end
@@ -78,54 +78,6 @@ describe Routing do
78
78
  @routing.routes.freeze
79
79
  @routing.call(env).should == [333, {}, ['this is gurk']]
80
80
  end
81
- it 'should route correctly' do
82
- env = rack_defaults_for '/searches/live.json?query=some_query'
83
-
84
- live = stub :live
85
- live.should_receive(:search_with_text).once.with(anything, 0).and_return(Results::Live.new)
86
- Query::Live.stub! :new => live
87
-
88
- @routing.live %r{/searches/live}, :some_index
89
-
90
- @routing.routes.freeze
91
- @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>"52"}, ["{\"allocations\":[],\"offset\":0,\"duration\":0,\"total\":0}"]]
92
- end
93
- it 'should route correctly' do
94
- env = rack_defaults_for '/searches/live.json?query=some_query'
95
-
96
- live = stub :live
97
- live.should_receive(:search_with_text).once.with(anything, 0).and_return(Results::Live.new)
98
- Query::Live.stub! :new => live
99
-
100
- @routing.live '/searches/live', :some_index
101
-
102
- @routing.routes.freeze
103
- @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>"52"}, ["{\"allocations\":[],\"offset\":0,\"duration\":0,\"total\":0}"]]
104
- end
105
- it 'should route correctly' do
106
- env = rack_defaults_for '/searches/full?query=some_query'
107
-
108
- full = stub :full
109
- full.should_receive(:search_with_text).once.with(anything, 0).and_return(Results::Full.new)
110
- Query::Full.stub! :new => full
111
-
112
- @routing.full %r{/searches/full}, :some_index
113
-
114
- @routing.routes.freeze
115
- @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>"50"}, ["\x04\b{\t:\x10allocations[\x00:\voffseti\x00:\rdurationi\x00:\ntotali\x00"]]
116
- end
117
- it 'should route correctly' do
118
- env = rack_defaults_for '/searches/full?query=some_query'
119
-
120
- full = stub :full
121
- full.should_receive(:search_with_text).once.with(anything, 0).and_return(Results::Full.new)
122
- Query::Full.stub! :new => full
123
-
124
- @routing.full '/searches/full', :some_index
125
-
126
- @routing.routes.freeze
127
- @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>"50"}, ["\x04\b{\t:\x10allocations[\x00:\voffseti\x00:\rdurationi\x00:\ntotali\x00"]]
128
- end
129
81
  it 'should route correctly' do
130
82
  env = rack_defaults_for '/searches/some_route?query=some_query'
131
83
 
@@ -133,7 +85,7 @@ describe Routing do
133
85
  full.should_receive(:search_with_text).once.with(anything, 0).and_return(Results::Full.new)
134
86
  Query::Full.stub! :new => full
135
87
 
136
- @routing.route '/searches/some_route', Query::Full.new(:some_index, :some_other_index)
88
+ @routing.route '/searches/some_route' => Query::Full.new(:some_index, :some_other_index)
137
89
 
138
90
  @routing.routes.freeze
139
91
  @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>"50"}, ["\x04\b{\t:\x10allocations[\x00:\voffseti\x00:\rdurationi\x00:\ntotali\x00"]]
@@ -145,7 +97,7 @@ describe Routing do
145
97
  full.should_receive(:search_with_text).once.with(anything, 0).and_return(Results::Full.new)
146
98
  Query::Full.stub! :new => full
147
99
 
148
- @routing.route '/searches/some_route', Query::Full.new(:some_index, :some_other_index), :query => { :type => :some_type }
100
+ @routing.route '/searches/some_route' => Query::Full.new(:some_index, :some_other_index), :query => { :type => :some_type }
149
101
 
150
102
  @routing.routes.freeze
151
103
  @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>"50"}, ["\x04\b{\t:\x10allocations[\x00:\voffseti\x00:\rdurationi\x00:\ntotali\x00"]]
@@ -157,7 +109,7 @@ describe Routing do
157
109
  full.should_receive(:search_with_text).never
158
110
  Query::Full.stub! :new => full
159
111
 
160
- @routing.route '/searches/some_route', Query::Full.new(:some_index, :some_other_index)
112
+ @routing.route '/searches/some_route' => Query::Full.new(:some_index, :some_other_index)
161
113
 
162
114
  @routing.routes.freeze
163
115
  @routing.call(env).should == [404, {"Content-Type"=>"text/html", "X-Cascade"=>"pass"}, ["Not Found"]]
@@ -194,7 +146,22 @@ describe Routing do
194
146
  end
195
147
  end
196
148
 
197
- describe 'route' do
149
+ describe "route" do
150
+ it "should delegate correctly" do
151
+ @routing.should_receive(:route_one).once.with %r{regexp1}, :query1, {}
152
+ @routing.should_receive(:route_one).once.with %r{regexp2}, :query2, {}
153
+
154
+ @routing.route %r{regexp1} => :query1, %r{regexp2} => :query2
155
+ end
156
+ it "should split options correctly" do
157
+ @routing.should_receive(:route_one).once.with %r{regexp1}, :query1, :some => :option
158
+ @routing.should_receive(:route_one).once.with %r{regexp2}, :query2, :some => :option
159
+
160
+ @routing.route %r{regexp1} => :query1, %r{regexp2} => :query2, :some => :option
161
+ end
162
+ end
163
+
164
+ describe 'route_one' do
198
165
  before(:each) do
199
166
  @some_query_app = stub :some_query_app
200
167
  @routing.stub! :generate_app => @some_query_app
@@ -202,17 +169,17 @@ describe Routing do
202
169
  it 'should add the right route' do
203
170
  @routes.should_receive(:add_route).once.with @some_query_app, { :request_method => "GET", :path_info => /some_url/ }
204
171
 
205
- @routing.route %r{some_url}, :some_query, {}
172
+ @routing.route_one %r{some_url}, :some_query, {}
206
173
  end
207
174
  it 'should add the right route' do
208
175
  @routes.should_receive(:add_route).once.with @some_query_app, { :request_method => "GET", :path_info => /some_url/ }
209
176
 
210
- @routing.route 'some_url', :some_query, {}
177
+ @routing.route_one 'some_url', :some_query, {}
211
178
  end
212
179
  it 'should add the right route' do
213
180
  @routes.should_receive(:add_route).once.with @some_query_app, { :request_method => "GET", :glarf => :blarf, :path_info => /some_url/ }
214
181
 
215
- @routing.route 'some_url', :some_query, { :glarf => :blarf }
182
+ @routing.route_one 'some_url', :some_query, { :glarf => :blarf }
216
183
  end
217
184
  end
218
185
 
@@ -232,49 +199,6 @@ describe Routing do
232
199
  end
233
200
  end
234
201
 
235
- #
236
- describe 'live' do
237
- describe 'instance creation' do
238
- before(:each) do
239
- @routing.stub :route
240
- end
241
- context 'with options' do
242
- it 'should call route correctly' do
243
- Query::Live.should_receive(:new).once.with :some_index, :some_other_index
244
-
245
- @routing.live :url, :some_index, :some_other_index, { :query => { :param => :value } }
246
- end
247
- end
248
- context 'without options' do
249
- it 'should call route correctly' do
250
- Query::Live.should_receive(:new).once.with :some_index, :some_other_index
251
-
252
- @routing.live :url, :some_index, :some_other_index
253
- end
254
- end
255
- end
256
- describe 'delegation' do
257
- context 'with options' do
258
- it 'should call route correctly' do
259
- Query::Live.stub! :new => :live
260
-
261
- @routing.should_receive(:route).once.with :url, :live, { :query => { :param => :value } }
262
-
263
- @routing.live :url, :some_index, { :query => { :param => :value } }
264
- end
265
- end
266
- context 'without options' do
267
- it 'should call route correctly' do
268
- Query::Live.stub! :new => :live
269
-
270
- @routing.should_receive(:route).once.with :url, :live, {}
271
-
272
- @routing.live :url, :some_index
273
- end
274
- end
275
- end
276
- end
277
-
278
202
  describe 'answer' do
279
203
  context 'with app' do
280
204
  before(:each) do
@@ -8,7 +8,7 @@ describe Tokenizers::Index do
8
8
  @tokenizer = Tokenizers::Index.new
9
9
  end
10
10
 
11
- describe "remove_illegal_characters" do
11
+ describe "remove_removes_characters" do
12
12
  it "should not remove ' from a query by default" do
13
13
  @tokenizer.remove_illegals("Lugi's").should == "Lugi's"
14
14
  end
@@ -1,7 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe "Speccing Ruby for speed" do
4
-
5
4
  describe "various versions for allocation id concatenating" do
6
5
  before(:each) do
7
6
  @allocs = [:hello, :speed, :test]
@@ -22,14 +21,14 @@ describe "Speccing Ruby for speed" do
22
21
  @allocs.inject([]) do |total, alloc|
23
22
  total + @ids[alloc]
24
23
  end
25
- end.should <= 0.0025
24
+ end.should < 0.0025
26
25
  end
27
26
  end
28
27
  describe "map and flatten!(1)" do
29
28
  it "should be fast" do
30
29
  Benchmark.realtime do
31
30
  @allocs.map { |alloc| @ids[alloc] }.flatten!(1)
32
- end.should <= 0.02
31
+ end.should < 0.02
33
32
  end
34
33
  end
35
34
  describe "<< and flatten!(1)" do
@@ -38,7 +37,7 @@ describe "Speccing Ruby for speed" do
38
37
  @allocs.inject([]) do |total, alloc|
39
38
  total << @ids[alloc]
40
39
  end.flatten!(1)
41
- end.should <= 0.02
40
+ end.should < 0.02
42
41
  end
43
42
  end
44
43
  describe "<< and flatten!" do
@@ -47,7 +46,7 @@ describe "Speccing Ruby for speed" do
47
46
  @allocs.inject([]) do |total, alloc|
48
47
  total << @ids[alloc]
49
48
  end.flatten!
50
- end.should <= 0.02
49
+ end.should < 0.02
51
50
  end
52
51
  end
53
52
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 9
9
- version: 0.0.9
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-09 00:00:00 +02:00
17
+ date: 2010-10-12 00:00:00 +02:00
18
18
  default_executable: picky
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -143,6 +143,7 @@ files:
143
143
  - prototype_project/unicorn.ru
144
144
  - spec/ext/performant_spec.rb
145
145
  - spec/lib/application_spec.rb
146
+ - spec/lib/cacher/partial/default_spec.rb
146
147
  - spec/lib/cacher/partial/subtoken_spec.rb
147
148
  - spec/lib/cacher/partial_generator_spec.rb
148
149
  - spec/lib/cacher/similarity/double_levenshtone_spec.rb
@@ -180,6 +181,7 @@ files:
180
181
  - spec/lib/query/token_spec.rb
181
182
  - spec/lib/query/tokens_spec.rb
182
183
  - spec/lib/query/weights_spec.rb
184
+ - spec/lib/rack/harakiri_spec.rb
183
185
  - spec/lib/results/base_spec.rb
184
186
  - spec/lib/routing_spec.rb
185
187
  - spec/lib/solr/schema_generator_spec.rb
@@ -226,6 +228,7 @@ summary: Picky the Search Engine
226
228
  test_files:
227
229
  - spec/ext/performant_spec.rb
228
230
  - spec/lib/application_spec.rb
231
+ - spec/lib/cacher/partial/default_spec.rb
229
232
  - spec/lib/cacher/partial/subtoken_spec.rb
230
233
  - spec/lib/cacher/partial_generator_spec.rb
231
234
  - spec/lib/cacher/similarity/double_levenshtone_spec.rb
@@ -263,6 +266,7 @@ test_files:
263
266
  - spec/lib/query/token_spec.rb
264
267
  - spec/lib/query/tokens_spec.rb
265
268
  - spec/lib/query/weights_spec.rb
269
+ - spec/lib/rack/harakiri_spec.rb
266
270
  - spec/lib/results/base_spec.rb
267
271
  - spec/lib/routing_spec.rb
268
272
  - spec/lib/solr/schema_generator_spec.rb