de 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/de/de.rb +14 -21
- data/lib/de/sunspot_solr/search.rb +25 -2
- data/lib/de/version.rb +1 -1
- data/test/de_sunspot_solr_search_test.rb +58 -0
- metadata +4 -4
data/lib/de/de.rb
CHANGED
@@ -114,30 +114,23 @@ module De
|
|
114
114
|
str
|
115
115
|
end
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
117
|
+
def to_hash
|
118
|
+
{
|
119
|
+
:name => @name,
|
120
|
+
:content => @content,
|
121
|
+
:class => self.class.name,
|
122
|
+
:children => children.map { |child| child.to_hash }
|
123
|
+
}
|
124
|
+
end
|
125
125
|
|
126
126
|
class << self
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
# when -2,1 then [hash[:name]]
|
135
|
-
# else [hash[:name], hash[:content]]
|
136
|
-
# end
|
137
|
-
#
|
138
|
-
# obj = klass.send(:new, *params)
|
139
|
-
# hash[:children].each { |child| obj << load(child) }
|
140
|
-
# end
|
128
|
+
def load(hash)
|
129
|
+
raise Error::InvalidExpressionError if (hash.keys - [:name, :content, :class, :children]).length > 0
|
130
|
+
|
131
|
+
obj = hash[:class].constantize.send(:new, hash[:name], hash[:content])
|
132
|
+
hash[:children].each { |child| obj << load(child) }
|
133
|
+
end
|
141
134
|
end
|
142
135
|
|
143
136
|
private
|
@@ -143,8 +143,17 @@ module De
|
|
143
143
|
#
|
144
144
|
def |(obj)
|
145
145
|
expression_content = []
|
146
|
-
|
147
|
-
|
146
|
+
[self, obj].select { |element| element.has_children? }.each do |element|
|
147
|
+
if element.children.length == 1
|
148
|
+
if element.first_child.is_a?(De::SunspotSolr::Or)
|
149
|
+
element.first_child.children.each { |child| expression_content << child }
|
150
|
+
else
|
151
|
+
expression_content << element.first_child
|
152
|
+
end
|
153
|
+
else
|
154
|
+
expression_content << SunspotSolr::And.new(element.children)
|
155
|
+
end
|
156
|
+
end
|
148
157
|
|
149
158
|
Search.new("#{@name}+#{obj.name}", @klass, @options, expression_content.length > 0 ? [SunspotSolr::Or.new(expression_content)] : nil)
|
150
159
|
end
|
@@ -204,6 +213,20 @@ module De
|
|
204
213
|
evaluate(params).results
|
205
214
|
end
|
206
215
|
|
216
|
+
# def to_hash
|
217
|
+
# children_hash = children.inject({}) { |result, child| result.merge(child.to_hash) }
|
218
|
+
# {:options => options, :children => children_hash}
|
219
|
+
# end
|
220
|
+
#
|
221
|
+
# class << self
|
222
|
+
#
|
223
|
+
# def load(hash)
|
224
|
+
# raise Error::InvalidExpressionError if (hash.keys - [:name, :content, :class, :children]).length > 0
|
225
|
+
#
|
226
|
+
# obj = hash[:class].constantize.send(:new, hash[:name], hash[:content])
|
227
|
+
# hash[:children].each { |child| obj << load(child) }
|
228
|
+
# end
|
229
|
+
# end
|
207
230
|
end
|
208
231
|
end
|
209
232
|
end
|
data/lib/de/version.rb
CHANGED
@@ -209,6 +209,64 @@ class DeSunspotSolrSearchTest < Test::Unit::TestCase
|
|
209
209
|
assert_instance_of(And, and_operator2)
|
210
210
|
assert_equal(2, and_operator2.children.length)
|
211
211
|
assert(!and_operator2[operand.name].nil? && !and_operator2[operand2.name].nil? || !and_operator2[operand3.name].nil? && !and_operator2[operand4.name].nil?)
|
212
|
+
|
213
|
+
###########
|
214
|
+
search1 = Search.new('search_product1', 'SomeClass', {
|
215
|
+
:properties => {
|
216
|
+
:client_id => {:type => :integer, :dynamic => false},
|
217
|
+
},
|
218
|
+
:dynamics => {:integer => :int_params, :string => :string_params, :time => :time_params, :text => :string_params}
|
219
|
+
})
|
220
|
+
search1 << operand
|
221
|
+
search1 << operand2
|
222
|
+
search2 = Search.new('search_product1', 'SomeClass', {
|
223
|
+
:properties => {
|
224
|
+
:client_id => {:type => :integer, :dynamic => false},
|
225
|
+
},
|
226
|
+
:dynamics => {:integer => :int_params, :string => :string_params, :time => :time_params, :text => :string_params}
|
227
|
+
})
|
228
|
+
search2 << operand3
|
229
|
+
search2 << operand4
|
230
|
+
search3 = Search.new('search_product1', 'SomeClass', {
|
231
|
+
:properties => {
|
232
|
+
:client_id => {:type => :integer, :dynamic => false},
|
233
|
+
},
|
234
|
+
:dynamics => {:integer => :int_params, :string => :string_params, :time => :time_params, :text => :string_params}
|
235
|
+
})
|
236
|
+
operand5 = EqualTo.new(:client_id, 61)
|
237
|
+
operand6 = EqualTo.new(:client_id, 92)
|
238
|
+
search3 << operand5
|
239
|
+
search3 << operand6
|
240
|
+
search = search1 | search2 | search3
|
241
|
+
assert_equal(1, search.children.length)
|
242
|
+
assert_instance_of(De::SunspotSolr::Or, search.first_child)
|
243
|
+
assert_equal(3, search.first_child.children.length)
|
244
|
+
(0..2).each do |index|
|
245
|
+
assert_instance_of(De::SunspotSolr::And, search.first_child.children[index])
|
246
|
+
assert_equal(2,search.first_child.children[index].children.length)
|
247
|
+
end
|
248
|
+
|
249
|
+
#########
|
250
|
+
search1 = Search.new('search_product1', 'SomeClass', {
|
251
|
+
:properties => {
|
252
|
+
:client_id => {:type => :integer, :dynamic => false},
|
253
|
+
},
|
254
|
+
:dynamics => {:integer => :int_params, :string => :string_params, :time => :time_params, :text => :string_params}
|
255
|
+
})
|
256
|
+
search1 << operand
|
257
|
+
search2 = Search.new('search_product1', 'SomeClass', {
|
258
|
+
:properties => {
|
259
|
+
:client_id => {:type => :integer, :dynamic => false},
|
260
|
+
},
|
261
|
+
:dynamics => {:integer => :int_params, :string => :string_params, :time => :time_params, :text => :string_params}
|
262
|
+
})
|
263
|
+
search2 << operand3
|
264
|
+
search = search1 | search2
|
265
|
+
assert_equal(1, search.children.length)
|
266
|
+
assert_instance_of(De::SunspotSolr::Or, search.first_child)
|
267
|
+
assert_equal(2, search.first_child.children.length)
|
268
|
+
assert_equal(operand, search.first_child.children[0])
|
269
|
+
assert_equal(operand3, search.first_child.children[1])
|
212
270
|
end
|
213
271
|
|
214
272
|
def test_intersection
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: de
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Olga Gorun
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-04 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|