picky 1.5.4 → 2.0.0.pre1
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.
- data/lib/picky/application.rb +7 -29
- data/lib/picky/internals/adapters/rack/query.rb +12 -8
- data/lib/picky/internals/query/indexes.rb +20 -20
- data/lib/picky/loader.rb +6 -10
- data/lib/picky/results.rb +93 -0
- data/lib/picky/search.rb +180 -0
- data/lib/picky/sources/base.rb +5 -3
- data/lib/tasks/todo.rake +8 -0
- data/spec/lib/application_spec.rb +2 -10
- data/spec/lib/character_substituters/west_european_spec.rb +14 -11
- data/spec/lib/internals/adapters/rack/query_spec.rb +8 -2
- data/spec/lib/internals/frontend_adapters/rack_spec.rb +13 -13
- data/spec/lib/{internals/results/base_spec.rb → results_spec.rb} +10 -9
- data/spec/lib/{query/base_spec.rb → search_spec.rb} +39 -39
- metadata +12 -23
- data/lib/picky/internals/results/base.rb +0 -99
- data/lib/picky/internals/results/full.rb +0 -17
- data/lib/picky/internals/results/live.rb +0 -17
- data/lib/picky/query/base.rb +0 -190
- data/lib/picky/query/full.rb +0 -20
- data/lib/picky/query/live.rb +0 -24
- data/spec/lib/internals/results/full_spec.rb +0 -78
- data/spec/lib/internals/results/live_spec.rb +0 -88
- data/spec/lib/query/full_spec.rb +0 -19
- data/spec/lib/query/live_spec.rb +0 -31
@@ -47,7 +47,7 @@ describe Internals::FrontendAdapters::Rack do
|
|
47
47
|
end
|
48
48
|
context 'with routes' do
|
49
49
|
before(:each) do
|
50
|
-
@rack_adapter.route %r{something} =>
|
50
|
+
@rack_adapter.route %r{something} => Search.new
|
51
51
|
end
|
52
52
|
it 'returns the right answer' do
|
53
53
|
@rack_adapter.empty?.should == false
|
@@ -101,11 +101,11 @@ describe Internals::FrontendAdapters::Rack do
|
|
101
101
|
it 'should route correctly' do
|
102
102
|
env = rack_defaults_for '/searches/some_route?query=some_query'
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
search = stub :search
|
105
|
+
search.should_receive(:search_with_text).once.with(anything, 20, 0).and_return(Internals::Results.new)
|
106
|
+
Search.stub! :new => search
|
107
107
|
|
108
|
-
@rack_adapter.route '/searches/some_route' =>
|
108
|
+
@rack_adapter.route '/searches/some_route' => Search.new(:some_index, :some_other_index)
|
109
109
|
|
110
110
|
@rack_adapter.routes.freeze
|
111
111
|
@rack_adapter.call(env).should == [200, {"Content-Type"=>"application/json", "Content-Length"=>"52"}, ["{\"allocations\":[],\"offset\":0,\"duration\":0,\"total\":0}"]]
|
@@ -113,11 +113,11 @@ describe Internals::FrontendAdapters::Rack do
|
|
113
113
|
it 'should route correctly' do
|
114
114
|
env = rack_defaults_for '/searches/some_route?query=some_query&type=some_type'
|
115
115
|
|
116
|
-
|
117
|
-
|
118
|
-
|
116
|
+
search = stub :search
|
117
|
+
search.should_receive(:search_with_text).once.with(anything, 20, 0).and_return(Internals::Results.new)
|
118
|
+
Search.stub! :new => search
|
119
119
|
|
120
|
-
@rack_adapter.route '/searches/some_route' =>
|
120
|
+
@rack_adapter.route '/searches/some_route' => Search.new(:some_index, :some_other_index), :query => { :type => :some_type }
|
121
121
|
|
122
122
|
@rack_adapter.routes.freeze
|
123
123
|
@rack_adapter.call(env).should == [200, {"Content-Type"=>"application/json", "Content-Length"=>"52"}, ["{\"allocations\":[],\"offset\":0,\"duration\":0,\"total\":0}"]]
|
@@ -125,11 +125,11 @@ describe Internals::FrontendAdapters::Rack do
|
|
125
125
|
it 'should route correctly' do
|
126
126
|
env = rack_defaults_for '/searches/some_wrong_route?query=some_query'
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
search = stub :search
|
129
|
+
search.should_receive(:search_with_text).never
|
130
|
+
Search.stub! :new => search
|
131
131
|
|
132
|
-
@rack_adapter.route '/searches/some_route' =>
|
132
|
+
@rack_adapter.route '/searches/some_route' => Search.new(:some_index, :some_other_index)
|
133
133
|
|
134
134
|
@rack_adapter.routes.freeze
|
135
135
|
@rack_adapter.call(env).should == [404, {"Content-Type"=>"text/html", "X-Cascade"=>"pass"}, ["Not Found"]]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Internals::Results
|
3
|
+
describe Internals::Results do
|
4
4
|
|
5
5
|
describe "from" do
|
6
6
|
before(:each) do
|
@@ -10,14 +10,14 @@ describe Internals::Results::Base do
|
|
10
10
|
@results.stub! :prepare!
|
11
11
|
end
|
12
12
|
it "should generate a result" do
|
13
|
-
described_class.from(0, @allocations).should == @results
|
13
|
+
described_class.from(20, 0, @allocations).should == @results
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "ids" do
|
18
18
|
before(:each) do
|
19
19
|
@allocations = stub :allocations
|
20
|
-
@results = described_class.new :unimportant, @allocations
|
20
|
+
@results = described_class.new :unimportant, :unimportant, @allocations
|
21
21
|
end
|
22
22
|
it "delegates" do
|
23
23
|
@allocations.should_receive(:ids).once.with :anything
|
@@ -36,20 +36,21 @@ describe Internals::Results::Base do
|
|
36
36
|
@results = described_class.new
|
37
37
|
end
|
38
38
|
it 'should output a default log' do
|
39
|
-
@results.to_log('some_query').should == '
|
39
|
+
@results.to_log('some_query').should == '.|0-08-16 10:07:33|0.000000|some_query | 0| 0| 0|'
|
40
40
|
end
|
41
41
|
end
|
42
42
|
context 'with results' do
|
43
43
|
before(:each) do
|
44
44
|
@allocations = stub :allocations,
|
45
|
-
:process! => nil,
|
45
|
+
:process! => nil,
|
46
|
+
:size => 12
|
46
47
|
|
47
|
-
@results = described_class.new 1234, @allocations
|
48
|
+
@results = described_class.new 20, 1234, @allocations
|
48
49
|
@results.stub! :duration => 0.1234567890,
|
49
50
|
:total => 12345678
|
50
51
|
end
|
51
52
|
it 'should output a specific log' do
|
52
|
-
@results.to_log('some_query').should == '
|
53
|
+
@results.to_log('some_query').should == '>|0-08-16 10:07:33|0.123457|some_query |12345678|1234|12|'
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
@@ -69,7 +70,7 @@ describe Internals::Results::Base do
|
|
69
70
|
before(:each) do
|
70
71
|
@allocations = stub :allocations, :process! => nil, :to_result => :allocations, :total => :some_total
|
71
72
|
|
72
|
-
@results = described_class.new :some_offset, @allocations
|
73
|
+
@results = described_class.new :some_results_amount, :some_offset, @allocations
|
73
74
|
@results.duration = :some_duration
|
74
75
|
end
|
75
76
|
it 'should do it correctly' do
|
@@ -81,7 +82,7 @@ describe Internals::Results::Base do
|
|
81
82
|
|
82
83
|
describe "accessors" do
|
83
84
|
before(:each) do
|
84
|
-
@results = described_class.new :anything
|
85
|
+
@results = described_class.new :anything, :anything
|
85
86
|
@some_stub = stub(:some)
|
86
87
|
end
|
87
88
|
it "should have accessors for duration" do
|
@@ -2,84 +2,84 @@
|
|
2
2
|
#
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe Search do
|
6
6
|
|
7
7
|
describe 'combinations_type_for' do
|
8
|
-
let(:
|
8
|
+
let(:search) { described_class.new }
|
9
9
|
it 'returns a specific Combination for a specific input' do
|
10
10
|
some_source = stub(:source, :harvest => nil)
|
11
|
-
|
11
|
+
search.combinations_type_for([Index::Memory.new(:gu, some_source)]).should == Internals::Query::Combinations::Memory
|
12
12
|
end
|
13
13
|
it 'just works on the same types' do
|
14
|
-
|
14
|
+
search.combinations_type_for([:blorf, :blarf]).should == Internals::Query::Combinations::Memory
|
15
15
|
end
|
16
16
|
it 'just uses standard combinations' do
|
17
|
-
|
17
|
+
search.combinations_type_for([:blorf]).should == Internals::Query::Combinations::Memory
|
18
18
|
end
|
19
19
|
it 'raises on multiple types' do
|
20
20
|
expect do
|
21
|
-
|
22
|
-
end.to raise_error(
|
21
|
+
search.combinations_type_for [:blorf, "blarf"]
|
22
|
+
end.to raise_error(Search::DifferentTypesError)
|
23
23
|
end
|
24
24
|
it 'raises with the right message on multiple types' do
|
25
25
|
expect do
|
26
|
-
|
27
|
-
end.to raise_error("Currently it isn't possible to mix Symbol and String Indexes in the same
|
26
|
+
search.combinations_type_for [:blorf, "blarf"]
|
27
|
+
end.to raise_error("Currently it isn't possible to mix Symbol and String Indexes in the same Search instance.")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "weights handling" do
|
32
32
|
it "creates a default weight when no weights are given" do
|
33
|
-
|
33
|
+
search = described_class.new
|
34
34
|
|
35
|
-
|
35
|
+
search.weights.should be_kind_of(Query::Weights)
|
36
36
|
end
|
37
37
|
it "handles :weights options when not yet wrapped" do
|
38
|
-
|
38
|
+
search = described_class.new :weights => { [:a, :b] => +3 }
|
39
39
|
|
40
|
-
|
40
|
+
search.weights.should be_kind_of(Query::Weights)
|
41
41
|
end
|
42
42
|
it "handles :weights options when already wrapped" do
|
43
|
-
|
43
|
+
search = described_class.new :weights => Query::Weights.new([:a, :b] => +3)
|
44
44
|
|
45
|
-
|
45
|
+
search.weights.should be_kind_of(Query::Weights)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
# describe "empty_results" do
|
50
50
|
# before(:each) do
|
51
|
-
# @
|
51
|
+
# @search = search::Full.new
|
52
52
|
#
|
53
53
|
# @result_type = stub :result_type
|
54
|
-
# @
|
54
|
+
# @search.stub! :result_type => @result_type
|
55
55
|
# end
|
56
56
|
# it "returns a new result type" do
|
57
57
|
# @result_type.should_receive(:new).once.with :some_offset
|
58
58
|
#
|
59
|
-
# @
|
59
|
+
# @search.empty_results :some_offset
|
60
60
|
# end
|
61
61
|
# it "returns a new result type with default offset" do
|
62
62
|
# @result_type.should_receive(:new).once.with 0
|
63
63
|
#
|
64
|
-
# @
|
64
|
+
# @search.empty_results
|
65
65
|
# end
|
66
66
|
# end
|
67
67
|
|
68
68
|
describe "search_with_text" do
|
69
69
|
before(:each) do
|
70
|
-
@
|
70
|
+
@search = Search.new
|
71
71
|
end
|
72
72
|
it "delegates to search" do
|
73
|
-
@
|
73
|
+
@search.stub! :tokenized => :tokens
|
74
74
|
|
75
|
-
@
|
75
|
+
@search.should_receive(:search).once.with :tokens, :results, :offset
|
76
76
|
|
77
|
-
@
|
77
|
+
@search.search_with_text :text, :results, :offset
|
78
78
|
end
|
79
79
|
it "uses the tokenizer" do
|
80
|
-
@
|
80
|
+
@search.should_receive(:tokenized).once.with :text
|
81
81
|
|
82
|
-
@
|
82
|
+
@search.search_with_text :text, :anything
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -87,46 +87,46 @@ describe Query::Base do
|
|
87
87
|
context 'real' do
|
88
88
|
before(:each) do
|
89
89
|
@allocations = stub :allocations
|
90
|
-
@
|
90
|
+
@search = Search.new
|
91
91
|
end
|
92
92
|
context 'reduce_to_amount not set' do
|
93
93
|
it 'should not call anything on the allocations' do
|
94
94
|
@allocations.should_receive(:reduce_to).never
|
95
95
|
|
96
|
-
@
|
96
|
+
@search.reduce @allocations
|
97
97
|
end
|
98
98
|
end
|
99
99
|
context 'reduce_to_amount set' do
|
100
100
|
before(:each) do
|
101
|
-
@
|
101
|
+
@search.reduce_to_amount = :some_amount
|
102
102
|
end
|
103
103
|
it 'should call reduce_to on the allocations' do
|
104
104
|
@allocations.should_receive(:reduce_to).once.with :some_amount
|
105
105
|
|
106
|
-
@
|
106
|
+
@search.reduce @allocations
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
110
110
|
context 'stubbed' do
|
111
111
|
before(:each) do
|
112
112
|
@allocations = stub :allocations
|
113
|
-
@
|
113
|
+
@search = Search.new
|
114
114
|
end
|
115
115
|
context 'reduce_to_amount not set' do
|
116
116
|
it 'should not call anything on the allocations' do
|
117
117
|
@allocations.should_receive(:reduce_to).never
|
118
118
|
|
119
|
-
@
|
119
|
+
@search.reduce @allocations
|
120
120
|
end
|
121
121
|
end
|
122
122
|
context 'reduce_to_amount set' do
|
123
123
|
before(:each) do
|
124
|
-
@
|
124
|
+
@search.stub! :reduce_to_amount => :some_amount
|
125
125
|
end
|
126
126
|
it 'should call reduce_to on the allocations' do
|
127
127
|
@allocations.should_receive(:reduce_to).once.with :some_amount
|
128
128
|
|
129
|
-
@
|
129
|
+
@search.reduce @allocations
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
@@ -141,10 +141,10 @@ describe Query::Base do
|
|
141
141
|
context 'with tokenizer' do
|
142
142
|
before(:each) do
|
143
143
|
@tokenizer = stub :tokenizer, :tokenize => :some_tokenized_text
|
144
|
-
@
|
144
|
+
@search = Search.new @index, tokenizer: @tokenizer
|
145
145
|
end
|
146
146
|
it 'should tokenize using the tokenizer' do
|
147
|
-
@
|
147
|
+
@search.tokenized('some text').should == :some_tokenized_text
|
148
148
|
end
|
149
149
|
end
|
150
150
|
end
|
@@ -155,18 +155,18 @@ describe Query::Base do
|
|
155
155
|
end
|
156
156
|
context 'with weights' do
|
157
157
|
before(:each) do
|
158
|
-
@
|
158
|
+
@search = Search.new @index, weights: :some_weights
|
159
159
|
end
|
160
160
|
it 'works correctly' do
|
161
|
-
@
|
161
|
+
@search.to_s.should == 'Search(some_index, weights: some_weights)'
|
162
162
|
end
|
163
163
|
end
|
164
164
|
context 'without weights' do
|
165
165
|
before(:each) do
|
166
|
-
@
|
166
|
+
@search = Search.new @index
|
167
167
|
end
|
168
168
|
it 'works correctly' do
|
169
|
-
@
|
169
|
+
@search.to_s.should == 'Search(some_index)'
|
170
170
|
end
|
171
171
|
end
|
172
172
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version:
|
4
|
+
prerelease: 6
|
5
|
+
version: 2.0.0.pre1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Florian Hanke
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-18 00:00:00 +01:00
|
14
14
|
default_executable: picky
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -123,20 +123,16 @@ files:
|
|
123
123
|
- lib/picky/internals/query/token.rb
|
124
124
|
- lib/picky/internals/query/tokens.rb
|
125
125
|
- lib/picky/internals/query/weights.rb
|
126
|
-
- lib/picky/internals/results/base.rb
|
127
|
-
- lib/picky/internals/results/full.rb
|
128
|
-
- lib/picky/internals/results/live.rb
|
129
126
|
- lib/picky/internals/solr/schema_generator.rb
|
130
127
|
- lib/picky/internals/tokenizers/base.rb
|
131
128
|
- lib/picky/internals/tokenizers/index.rb
|
132
129
|
- lib/picky/internals/tokenizers/query.rb
|
133
130
|
- lib/picky/loader.rb
|
134
131
|
- lib/picky/loggers/search.rb
|
135
|
-
- lib/picky/query/base.rb
|
136
|
-
- lib/picky/query/full.rb
|
137
|
-
- lib/picky/query/live.rb
|
138
132
|
- lib/picky/query/solr.rb
|
139
133
|
- lib/picky/rack/harakiri.rb
|
134
|
+
- lib/picky/results.rb
|
135
|
+
- lib/picky/search.rb
|
140
136
|
- lib/picky/signals.rb
|
141
137
|
- lib/picky/sources/base.rb
|
142
138
|
- lib/picky/sources/couch.rb
|
@@ -158,6 +154,7 @@ files:
|
|
158
154
|
- lib/tasks/solr.rake
|
159
155
|
- lib/tasks/spec.rake
|
160
156
|
- lib/tasks/statistics.rake
|
157
|
+
- lib/tasks/todo.rake
|
161
158
|
- lib/tasks/try.rake
|
162
159
|
- lib/picky/internals/ext/ruby19/performant.c
|
163
160
|
- spec/ext/performant_spec.rb
|
@@ -216,9 +213,6 @@ files:
|
|
216
213
|
- spec/lib/internals/indexing/index_spec.rb
|
217
214
|
- spec/lib/internals/indexing/indexes_spec.rb
|
218
215
|
- spec/lib/internals/interfaces/live_parameters_spec.rb
|
219
|
-
- spec/lib/internals/results/base_spec.rb
|
220
|
-
- spec/lib/internals/results/full_spec.rb
|
221
|
-
- spec/lib/internals/results/live_spec.rb
|
222
216
|
- spec/lib/internals/solr/schema_generator_spec.rb
|
223
217
|
- spec/lib/internals/tokenizers/base_spec.rb
|
224
218
|
- spec/lib/internals/tokenizers/index_spec.rb
|
@@ -227,20 +221,19 @@ files:
|
|
227
221
|
- spec/lib/loggers/search_spec.rb
|
228
222
|
- spec/lib/query/allocation_spec.rb
|
229
223
|
- spec/lib/query/allocations_spec.rb
|
230
|
-
- spec/lib/query/base_spec.rb
|
231
224
|
- spec/lib/query/combination_spec.rb
|
232
225
|
- spec/lib/query/combinations/base_spec.rb
|
233
226
|
- spec/lib/query/combinations/memory_spec.rb
|
234
227
|
- spec/lib/query/combinations/redis_spec.rb
|
235
|
-
- spec/lib/query/full_spec.rb
|
236
228
|
- spec/lib/query/indexes_spec.rb
|
237
|
-
- spec/lib/query/live_spec.rb
|
238
229
|
- spec/lib/query/qualifiers_spec.rb
|
239
230
|
- spec/lib/query/solr_spec.rb
|
240
231
|
- spec/lib/query/token_spec.rb
|
241
232
|
- spec/lib/query/tokens_spec.rb
|
242
233
|
- spec/lib/query/weights_spec.rb
|
243
234
|
- spec/lib/rack/harakiri_spec.rb
|
235
|
+
- spec/lib/results_spec.rb
|
236
|
+
- spec/lib/search_spec.rb
|
244
237
|
- spec/lib/sources/couch_spec.rb
|
245
238
|
- spec/lib/sources/csv_spec.rb
|
246
239
|
- spec/lib/sources/db_spec.rb
|
@@ -268,9 +261,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
268
261
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
269
262
|
none: false
|
270
263
|
requirements:
|
271
|
-
- - "
|
264
|
+
- - ">"
|
272
265
|
- !ruby/object:Gem::Version
|
273
|
-
version:
|
266
|
+
version: 1.3.1
|
274
267
|
requirements: []
|
275
268
|
|
276
269
|
rubyforge_project: http://rubyforge.org/projects/picky
|
@@ -335,9 +328,6 @@ test_files:
|
|
335
328
|
- spec/lib/internals/indexing/index_spec.rb
|
336
329
|
- spec/lib/internals/indexing/indexes_spec.rb
|
337
330
|
- spec/lib/internals/interfaces/live_parameters_spec.rb
|
338
|
-
- spec/lib/internals/results/base_spec.rb
|
339
|
-
- spec/lib/internals/results/full_spec.rb
|
340
|
-
- spec/lib/internals/results/live_spec.rb
|
341
331
|
- spec/lib/internals/solr/schema_generator_spec.rb
|
342
332
|
- spec/lib/internals/tokenizers/base_spec.rb
|
343
333
|
- spec/lib/internals/tokenizers/index_spec.rb
|
@@ -346,20 +336,19 @@ test_files:
|
|
346
336
|
- spec/lib/loggers/search_spec.rb
|
347
337
|
- spec/lib/query/allocation_spec.rb
|
348
338
|
- spec/lib/query/allocations_spec.rb
|
349
|
-
- spec/lib/query/base_spec.rb
|
350
339
|
- spec/lib/query/combination_spec.rb
|
351
340
|
- spec/lib/query/combinations/base_spec.rb
|
352
341
|
- spec/lib/query/combinations/memory_spec.rb
|
353
342
|
- spec/lib/query/combinations/redis_spec.rb
|
354
|
-
- spec/lib/query/full_spec.rb
|
355
343
|
- spec/lib/query/indexes_spec.rb
|
356
|
-
- spec/lib/query/live_spec.rb
|
357
344
|
- spec/lib/query/qualifiers_spec.rb
|
358
345
|
- spec/lib/query/solr_spec.rb
|
359
346
|
- spec/lib/query/token_spec.rb
|
360
347
|
- spec/lib/query/tokens_spec.rb
|
361
348
|
- spec/lib/query/weights_spec.rb
|
362
349
|
- spec/lib/rack/harakiri_spec.rb
|
350
|
+
- spec/lib/results_spec.rb
|
351
|
+
- spec/lib/search_spec.rb
|
363
352
|
- spec/lib/sources/couch_spec.rb
|
364
353
|
- spec/lib/sources/csv_spec.rb
|
365
354
|
- spec/lib/sources/db_spec.rb
|
@@ -1,99 +0,0 @@
|
|
1
|
-
module Internals
|
2
|
-
|
3
|
-
module Results # :nodoc:all
|
4
|
-
|
5
|
-
# This is the internal results object. Usually, to_marshal, or to_json
|
6
|
-
# is called on it to get a string for the answer.
|
7
|
-
#
|
8
|
-
class Base
|
9
|
-
|
10
|
-
# Duration is set externally by the query.
|
11
|
-
#
|
12
|
-
attr_writer :duration
|
13
|
-
attr_reader :allocations, :offset
|
14
|
-
|
15
|
-
# Takes instances of Query::Allocations as param.
|
16
|
-
#
|
17
|
-
def initialize offset = 0, allocations = Query::Allocations.new
|
18
|
-
@offset = offset
|
19
|
-
@allocations = allocations
|
20
|
-
end
|
21
|
-
# Create new results and calculate the ids.
|
22
|
-
#
|
23
|
-
def self.from offset, allocations
|
24
|
-
results = new offset, allocations
|
25
|
-
results.prepare!
|
26
|
-
results
|
27
|
-
end
|
28
|
-
|
29
|
-
# Returns a hash with the allocations, offset, duration and total.
|
30
|
-
#
|
31
|
-
def serialize
|
32
|
-
{ allocations: allocations.to_result,
|
33
|
-
offset: offset,
|
34
|
-
duration: duration,
|
35
|
-
total: total }
|
36
|
-
end
|
37
|
-
# The default format is json.
|
38
|
-
#
|
39
|
-
def to_response options = {}
|
40
|
-
to_json options
|
41
|
-
end
|
42
|
-
# Convert to json format.
|
43
|
-
#
|
44
|
-
def to_json options = {}
|
45
|
-
serialize.to_json options
|
46
|
-
end
|
47
|
-
|
48
|
-
# This starts the actual processing.
|
49
|
-
#
|
50
|
-
# Without this, the allocations are not processed,
|
51
|
-
# and no ids are calculated.
|
52
|
-
#
|
53
|
-
def prepare!
|
54
|
-
allocations.process! self.max_results, self.offset
|
55
|
-
end
|
56
|
-
|
57
|
-
# Duration default is 0.
|
58
|
-
#
|
59
|
-
def duration
|
60
|
-
@duration || 0
|
61
|
-
end
|
62
|
-
# The total results. Delegates to the allocations.
|
63
|
-
#
|
64
|
-
# Caches.
|
65
|
-
#
|
66
|
-
def total
|
67
|
-
@total || @total = allocations.total || 0
|
68
|
-
end
|
69
|
-
|
70
|
-
# How many results are returned.
|
71
|
-
#
|
72
|
-
# Set in config using
|
73
|
-
# Results::Full.max_results = 20
|
74
|
-
#
|
75
|
-
class_inheritable_accessor :max_results
|
76
|
-
def max_results
|
77
|
-
self.class.max_results
|
78
|
-
end
|
79
|
-
|
80
|
-
# Convenience methods.
|
81
|
-
#
|
82
|
-
|
83
|
-
# Delegates to allocations.
|
84
|
-
#
|
85
|
-
def ids amount = 20
|
86
|
-
allocations.ids amount
|
87
|
-
end
|
88
|
-
|
89
|
-
# Human readable log.
|
90
|
-
#
|
91
|
-
def to_log query
|
92
|
-
"|#{Time.now.to_s(:db)}|#{'%8f' % duration}|#{'%-50s' % query}|#{'%8d' % total}|#{'%4d' % offset}|#{'%2d' % allocations.size}|"
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|