delsolr 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +0,0 @@
1
- require 'test/unit'
2
- require File.expand_path(File.dirname(__FILE__)) + '/../lib/delsolr'
@@ -1,179 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
-
3
- class QueryBuilderTest < Test::Unit::TestCase
4
-
5
- include Test::Unit::Assertions
6
-
7
- def test_001
8
- qb = nil
9
-
10
- opts = {}
11
- opts[:limit] = 13
12
- opts[:offset] = 3
13
- opts[:fl] = 'id'
14
- opts[:query] = 'good book'
15
-
16
- assert_nothing_raised { qb = DelSolr::Client::QueryBuilder.new('query_name', opts) }
17
-
18
- assert(qb)
19
-
20
- p = get_params(qb.request_string)
21
- assert_equal('3', p['start'])
22
- assert_equal('13', p['rows'])
23
- assert_equal('id', p['fl'])
24
- assert_equal('good book', p['q'])
25
- end
26
-
27
- def test_002
28
- qb = nil
29
-
30
- opts = {}
31
- opts[:query] = "blahblah"
32
- opts[:fields] = 'id,unique_id,score'
33
-
34
- assert_nothing_raised { qb = DelSolr::Client::QueryBuilder.new('query_name', opts) }
35
-
36
- assert(qb)
37
-
38
- p = get_params(qb.request_string)
39
- assert_equal('id,unique_id,score', p['fl'])
40
- assert_equal('blahblah', p['q'])
41
- end
42
-
43
- def test_003
44
- qb = nil
45
-
46
- opts = {}
47
- opts[:query] = {:index_type => 'books'}
48
- opts[:fields] = 'id,unique_id,score'
49
-
50
- assert_nothing_raised { qb = DelSolr::Client::QueryBuilder.new('query_name', opts) }
51
-
52
- assert(qb)
53
-
54
- p = get_params(qb.request_string)
55
- assert_equal('id,unique_id,score', p['fl'])
56
- assert_equal('index_type:books', p['q'])
57
- end
58
-
59
- def test_004
60
- qb = nil
61
-
62
- opts = {}
63
- opts[:query] = {:index_type => 'books'}
64
- opts[:filters] = {:location => 'seattle'}
65
-
66
- assert_nothing_raised { qb = DelSolr::Client::QueryBuilder.new('query_name', opts) }
67
-
68
- assert(qb)
69
-
70
- p = get_params(qb.request_string)
71
- assert_equal('location:seattle', p['fq'])
72
- assert_equal('index_type:books', p['q'])
73
- end
74
-
75
- def test_005
76
- qb = nil
77
-
78
- opts = {}
79
- opts[:query] = {:index_type => 'books'}
80
- opts[:filters] = "location:seattle"
81
-
82
- assert_nothing_raised { qb = DelSolr::Client::QueryBuilder.new('query_name', opts) }
83
-
84
- assert(qb)
85
-
86
- p = get_params(qb.request_string)
87
-
88
- assert_equal('location:seattle', p['fq'])
89
- assert_equal('index_type:books', p['q'])
90
- end
91
-
92
- def test_facets_001
93
- qb = nil
94
- opts = {}
95
- opts[:query] = "games"
96
- opts[:facets] = [{:field => 'instock_b'}, {:field => 'on_sale_b', :limit => 1}]
97
-
98
- assert_nothing_raised { qb = DelSolr::Client::QueryBuilder.new('onebox-books', opts) }
99
-
100
- assert(qb)
101
-
102
- p = get_params(qb.request_string)
103
-
104
- assert_equal('true', p['facet'])
105
- assert_equal(['instock_b', 'on_sale_b'].sort, p['facet.field'].sort)
106
- assert_equal('1', p['f.on_sale_b.facet.limit'])
107
- end
108
-
109
- def test_facets_002
110
- qb = nil
111
- opts = {}
112
- opts[:query] = "games"
113
- opts[:facets] = [{:query => {:city_idm => 19596}, :name => 'seattle'}, {:field => 'language_idm'}]
114
-
115
- assert_nothing_raised { qb = DelSolr::Client::QueryBuilder.new('onebox-books', opts) }
116
-
117
- assert(qb)
118
-
119
- p = get_params(qb.request_string)
120
-
121
- assert_equal('true', p['facet'])
122
- assert_equal('language_idm', p['facet.field'])
123
- assert_equal('{!key=seattle}city_idm:19596', p['facet.query'])
124
- end
125
-
126
- def test_facets_003
127
- qb = nil
128
- opts = {}
129
- opts[:query] = "games"
130
- opts[:facets] = [{:query => {:city_idm => 19596}, :localparams => {:key => 'seattle', :ex => 'exclusion'}}, {:field => 'language_idm'}]
131
-
132
- assert_nothing_raised { qb = DelSolr::Client::QueryBuilder.new('onebox-books', opts) }
133
-
134
- assert(qb)
135
-
136
- p = get_params(qb.request_string)
137
-
138
- assert_equal('true', p['facet'])
139
- assert_equal('language_idm', p['facet.field'])
140
- assert_match('city_idm:19596', p['facet.query'])
141
- assert_match('key=seattle', p['facet.query'])
142
- assert_match('ex=exclusion', p['facet.query'])
143
- end
144
-
145
- def test_range
146
- qb = nil
147
- opts = {}
148
- opts[:query] = "games"
149
- opts[:filters] = {:id => (1..3)}
150
-
151
- assert_nothing_raised { qb = DelSolr::Client::QueryBuilder.new('onebox-books', opts) }
152
-
153
- assert(qb)
154
-
155
- p = get_params(qb.request_string)
156
-
157
- assert_equal(p['fq'], 'id:[1 TO 3]')
158
- end
159
-
160
-
161
- private
162
-
163
- # given a url returns a hash of the query params (for each duplicate key, it returns an array)
164
- def get_params(url)
165
- query = url.split('&')
166
- h = {}
167
- query.each do |p|
168
- a = p.split('=')
169
- if h[a[0]]
170
- h[a[0]] = (Array(h[a[0]]) << CGI::unescape(a[1])) # convert it to an array
171
- else
172
- h[a[0]] = CGI::unescape(a[1])
173
- end
174
- end
175
- h
176
- end
177
-
178
-
179
- end
@@ -1,145 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
-
3
- class ResponseTest < Test::Unit::TestCase
4
-
5
- include Test::Unit::Assertions
6
-
7
- @@test_001 = %{
8
- {
9
- 'responseHeader'=>{
10
- 'status'=>0,
11
- 'QTime'=>151,
12
- 'params'=>{
13
- 'wt'=>'ruby',
14
- 'rows'=>'10',
15
- 'explainOther'=>'',
16
- 'start'=>'0',
17
- 'hl.fl'=>'',
18
- 'indent'=>'on',
19
- 'hl'=>'on',
20
- 'q'=>'index_type:widget',
21
- 'fl'=>'*,score',
22
- 'qt'=>'standard',
23
- 'version'=>'2.2'}},
24
- 'response'=>{'numFound'=>1522698,'start'=>0,'maxScore'=>1.5583541,'docs'=>[
25
- {
26
- 'index_type'=>'widget',
27
- 'id'=>1,
28
- 'unique_id'=>'1_widget',
29
- 'score'=>1.5583541},
30
- {
31
- 'index_type'=>'widget',
32
- 'id'=>3,
33
- 'unique_id'=>'3_widget',
34
- 'score'=>1.5583541},
35
- {
36
- 'index_type'=>'widget',
37
- 'id'=>4,
38
- 'unique_id'=>'4_widget',
39
- 'score'=>1.5583541},
40
- {
41
- 'index_type'=>'widget',
42
- 'id'=>5,
43
- 'unique_id'=>'5_widget',
44
- 'score'=>1.5583541},
45
- {
46
- 'index_type'=>'widget',
47
- 'id'=>7,
48
- 'unique_id'=>'7_widget',
49
- 'score'=>1.5583541},
50
- {
51
- 'index_type'=>'widget',
52
- 'id'=>8,
53
- 'unique_id'=>'8_widget',
54
- 'score'=>1.5583541},
55
- {
56
- 'index_type'=>'widget',
57
- 'id'=>9,
58
- 'unique_id'=>'9_widget',
59
- 'score'=>1.5583541},
60
- {
61
- 'index_type'=>'widget',
62
- 'id'=>10,
63
- 'unique_id'=>'10_widget',
64
- 'score'=>1.5583541},
65
- {
66
- 'index_type'=>'widget',
67
- 'id'=>11,
68
- 'unique_id'=>'11_widget',
69
- 'score'=>1.5583541},
70
- {
71
- 'index_type'=>'widget',
72
- 'id'=>12,
73
- 'unique_id'=>'12_widget',
74
- 'score'=>1.5583541}]
75
- },
76
- 'facet_counts'=>{
77
- 'facet_queries'=>{
78
- '19596' => 392},
79
- 'facet_fields'=>{
80
- 'available_b'=>[
81
- 'false',1328],
82
- 'onsale_b'=>[
83
- 'false',1182,
84
- 'true',174]}},
85
- 'highlighting'=>{
86
- '1_widget'=>{},
87
- '3_widget'=>{},
88
- '4_widget'=>{},
89
- '5_widget'=>{},
90
- '7_widget'=>{},
91
- '8_widget'=>{},
92
- '9_widget'=>{},
93
- '10_widget'=>{},
94
- '11_widget'=>{},
95
- '12_widget'=>{}},
96
- 'spellcheck'=>{
97
- 'suggestions'=>[
98
- 'fishh',{'numFound'=>1,'startOffset'=>0,'endOffset'=>4,'suggestion'=>['fish']},
99
- 'collation','fish']}}
100
- }
101
-
102
- def test_001
103
- r = nil
104
- qb = DelSolr::Client::QueryBuilder.new('standard', :query => {:index_type => 'widget'}, :facets => {:query => 'city_idm:19596', :prefix => {:key => 19596}} )
105
- qb.request_string # need to generate this...
106
- assert_nothing_raised { r = DelSolr::Client::Response.new(@@test_001, qb) }
107
-
108
- assert_equal(151, r.qtime)
109
- assert_equal(1.5583541, r.max_score)
110
- assert_equal(10, r.docs.length)
111
- assert_equal([1, 3, 4, 5, 7, 8, 9, 10, 11, 12], r.ids)
112
- assert_equal({
113
- 'available_b'=>[
114
- 'false',1328],
115
- 'onsale_b'=>[
116
- 'false',1182,
117
- 'true',174]}, r.facet_fields)
118
- assert_equal(1182, r.facet_field_count('onsale_b', false))
119
- assert_equal(174, r.facet_field_count('onsale_b', true))
120
- assert_equal(1328, r.facet_field_count('available_b', false))
121
- assert_equal(392, r.facet_query_count_by_key(19596))
122
- end
123
-
124
- def test_shortcuts
125
- r = nil
126
- qb = DelSolr::Client::QueryBuilder.new('standard', :query => {:index_type => 'widget'}, :facets => {:query => 'city_idm:19596', :prefix => {:key => 19596}} )
127
- qb.request_string # need to generate this...
128
- assert_nothing_raised { r = DelSolr::Client::Response.new(@@test_001, qb, :shortcuts => [:index_type, :id]) }
129
-
130
- assert(r.respond_to?(:index_types))
131
- assert(r.respond_to?(:ids))
132
- assert(!r.respond_to?(:scores))
133
- end
134
-
135
- def test_spellcheck
136
- r = nil
137
- qb = DelSolr::Client::QueryBuilder.new('standard', :query => {:index_type => 'widget'}, :facets => {:query => 'city_idm:19596', :prefix => {:key => 19596}} )
138
- qb.request_string # need to generate this...
139
- assert_nothing_raised { r = DelSolr::Client::Response.new(@@test_001, qb) }
140
-
141
- assert_equal('fish', r.collation)
142
- assert_equal('fish', r.correction['fishh'])
143
- end
144
-
145
- end