infopark_cloud_connector 6.8.0.406.131718077 → 6.8.0.444.171626367
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.
@@ -21,58 +21,32 @@ module RailsConnector
|
|
21
21
|
# Accesses Cms Api Search using #query and fetches search hits.
|
22
22
|
# @api public
|
23
23
|
def fetch_hits
|
24
|
-
|
25
|
-
:query => query,
|
26
|
-
:offset => @options[:offset],
|
27
|
-
:size => @options[:limit],
|
28
|
-
})
|
24
|
+
search_enum = search_results
|
29
25
|
|
30
|
-
result = SES::SearchResult.new(
|
31
|
-
|
26
|
+
result = SES::SearchResult.new(search_enum.size)
|
27
|
+
search_enum.take(@options[:limit] || 10).each do |obj|
|
32
28
|
hard_coded_score = 1
|
33
|
-
result << SES::Hit.new(
|
29
|
+
result << SES::Hit.new(obj.id, hard_coded_score, {}, obj)
|
34
30
|
end
|
31
|
+
|
35
32
|
result
|
36
33
|
end
|
37
34
|
|
38
35
|
private
|
39
36
|
|
40
|
-
def
|
41
|
-
"revisions/#{Workspace.current.revision_id}/objs/search"
|
42
|
-
end
|
43
|
-
|
44
|
-
def query
|
37
|
+
def search_results
|
45
38
|
now = Time.now
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
"value" => "Image",
|
52
|
-
"negate" => true
|
53
|
-
},
|
54
|
-
{
|
55
|
-
"field" => "_valid_from",
|
56
|
-
"operator" => "less_than",
|
57
|
-
"value" => now.to_iso
|
58
|
-
},
|
59
|
-
{
|
60
|
-
"field" => "_valid_until",
|
61
|
-
"operator" => "less_than",
|
62
|
-
"value" => now.to_iso,
|
63
|
-
"negate" => true
|
64
|
-
}
|
65
|
-
]
|
39
|
+
search_enum = Obj.where(:_valid_from, :is_less_than, now.to_iso
|
40
|
+
).and_not(:_valid_until, :is_less_than, now.to_iso
|
41
|
+
).and_not(:_obj_class, :equals, 'Image'
|
42
|
+
).offset(@options[:offset] || 0
|
43
|
+
).batch_size(@options[:limit] || 10)
|
66
44
|
|
67
45
|
@query_string.strip.split(/[\s]+/).each do |word|
|
68
|
-
|
69
|
-
"field" => "*",
|
70
|
-
"operator" => "prefix_search",
|
71
|
-
"value" => word,
|
72
|
-
}
|
46
|
+
search_enum.and(:*, :contains_prefix, word)
|
73
47
|
end
|
74
48
|
|
75
|
-
|
49
|
+
search_enum
|
76
50
|
end
|
77
51
|
end
|
78
52
|
|
data/lib/rails_connector/obj.rb
CHANGED
@@ -39,6 +39,8 @@ module RailsConnector
|
|
39
39
|
|
40
40
|
# Find an Obj by it's id.
|
41
41
|
# If the paremeter is an Array containing ids, return a list of corresponding Objs.
|
42
|
+
# @param [String, Integer, Array<String, Integer>]id_or_list
|
43
|
+
# @return [Obj, Array<Obj>]
|
42
44
|
# @api public
|
43
45
|
def self.find(id_or_list)
|
44
46
|
case id_or_list
|
@@ -50,8 +52,28 @@ module RailsConnector
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
55
|
+
# Returns a {ObjSearchEnumerator} with the given initial subquery consisting of the four arguments.
|
56
|
+
#
|
57
|
+
# Note that +field+ and +value+ can also be arrays for searching several fields or searching for several values.
|
58
|
+
#
|
59
|
+
# {ObjSearchEnumerator}s can be chained using one of the chainable methods (e.g. {ObjSearchEnumerator#and} and {ObjSearchEnumerator#and_not}).
|
60
|
+
#
|
61
|
+
# @example Look for the first 10 Objs whose ObjClass is "Pressrelease" and whose title contains "quarterly":
|
62
|
+
# Obj.where(:_obj_class, :equals, 'Pressrelease').and(:title, :contains, 'quarterly').take(10).map{ |obj| obj.valid_from }
|
63
|
+
# @param [Symbol, String, Array<Symbol, String>] field See {ObjSearchEnumerator#and} for details
|
64
|
+
# @param [Symbol, String] operator See {ObjSearchEnumerator#and} for details
|
65
|
+
# @param [String, Array<String>] value See {ObjSearchEnumerator#and} for details
|
66
|
+
# @param [Hash] boost See {ObjSearchEnumerator#and} for details
|
67
|
+
# @return [ObjSearchEnumerator]
|
68
|
+
# @api public
|
69
|
+
def self.where(field, operator, value, boost = nil)
|
70
|
+
ObjSearchEnumerator.new(nil).and(field, operator, value, boost)
|
71
|
+
end
|
72
|
+
|
53
73
|
# Returns a {ObjSearchEnumerator} of all Objs.
|
54
74
|
# If invoked on a subclass of Obj, the result will be restricted to Obj of that subclass.
|
75
|
+
# @return [ObjSearchEnumerator]
|
76
|
+
# @api public
|
55
77
|
def self.all
|
56
78
|
if self.name == 'RailsConnector::Obj'
|
57
79
|
ObjSearchEnumerator.new(nil)
|
@@ -60,13 +82,18 @@ module RailsConnector
|
|
60
82
|
end
|
61
83
|
end
|
62
84
|
|
63
|
-
# Returns
|
85
|
+
# Returns a {ObjSearchEnumerator} of all Objs with the given +obj_class+.
|
86
|
+
# @param [String] obj_class Name of the ObjClass.
|
87
|
+
# @return [ObjSearchEnumerator]
|
88
|
+
# @api public
|
64
89
|
def self.find_all_by_obj_class(obj_class)
|
65
|
-
|
90
|
+
where(:_obj_class, :equals, obj_class)
|
66
91
|
end
|
67
92
|
|
68
93
|
# Find the Obj with the given path.
|
69
|
-
# Returns nil if no matching Obj exists.
|
94
|
+
# Returns +nil+ if no matching Obj exists.
|
95
|
+
# @param [String] path Path of the {Obj}.
|
96
|
+
# @return [Obj]
|
70
97
|
# @api public
|
71
98
|
def self.find_by_path(path)
|
72
99
|
find_objs_by(:path, [path]).first.first
|
@@ -77,26 +104,34 @@ module RailsConnector
|
|
77
104
|
end
|
78
105
|
|
79
106
|
# Find an Obj with the given name.
|
80
|
-
# If several Objs
|
81
|
-
# If no Obj with the name exits, nil is returned.
|
107
|
+
# If several Objs with the given name exist, an arbitrary one of these Objs is chosen and returned.
|
108
|
+
# If no Obj with the name exits, +nil+ is returned.
|
109
|
+
# @param [String] name Name of the {Obj}.
|
110
|
+
# @return [Obj]
|
111
|
+
# @api public
|
82
112
|
def self.find_by_name(name)
|
83
|
-
|
84
|
-
[{:field => '_name', :operator => 'equal', :value => name}], {:batch_size => 1})
|
85
|
-
enum.first
|
113
|
+
where(:_name, :equals, name).batch_size(1).first
|
86
114
|
end
|
87
115
|
|
88
|
-
# Returns
|
116
|
+
# Returns a {ObjSearchEnumerator} of all Objs with the given name.
|
117
|
+
# @param [String] name Name of the {Obj}.
|
118
|
+
# @return [ObjSearchEnumerator]
|
119
|
+
# @api public
|
89
120
|
def self.find_all_by_name(name)
|
90
|
-
|
121
|
+
where(:_name, :equals, name)
|
91
122
|
end
|
92
123
|
|
93
|
-
#
|
124
|
+
# Returns the Obj with the given permalink, or +nil+ if no matching Obj exists.
|
125
|
+
# @param [String] permalink The permalink of the {Obj}.
|
126
|
+
# @return [Obj]
|
94
127
|
# @api public
|
95
128
|
def self.find_by_permalink(permalink)
|
96
129
|
find_objs_by(:permalink, [permalink]).first.first
|
97
130
|
end
|
98
131
|
|
99
|
-
#
|
132
|
+
# Returns the Obj with the given permalink, or raise ResourceNotFound if no matching Obj exists.
|
133
|
+
# @param [String] permalink The permalink of the {Obj}.
|
134
|
+
# @return [Obj]
|
100
135
|
# @api public
|
101
136
|
def self.find_by_permalink!(permalink)
|
102
137
|
find_by_permalink(permalink) or
|
@@ -136,13 +171,14 @@ module RailsConnector
|
|
136
171
|
end
|
137
172
|
|
138
173
|
# return the Obj that is the parent of this Obj.
|
139
|
-
# returns nil for the root Obj.
|
174
|
+
# returns +nil+ for the root Obj.
|
140
175
|
# @api public
|
141
176
|
def parent
|
142
177
|
root? ? nil : Obj.find_by_path(parent_path)
|
143
178
|
end
|
144
179
|
|
145
180
|
# Returns an Array of all the ancestor objects, starting at the root and ending at this object's parent.
|
181
|
+
# @return [Array<Obj>]
|
146
182
|
# @api public
|
147
183
|
def ancestors
|
148
184
|
return [] if root?
|
@@ -154,6 +190,7 @@ module RailsConnector
|
|
154
190
|
end
|
155
191
|
|
156
192
|
# return a list of all child Objs.
|
193
|
+
# @return [Array<Obj>]
|
157
194
|
# @api public
|
158
195
|
def children
|
159
196
|
Obj.find_objs_by(:ppath, [path]).first
|
@@ -201,6 +238,7 @@ module RailsConnector
|
|
201
238
|
end
|
202
239
|
|
203
240
|
# Returns the root Obj, i.e. the Obj with the path "/"
|
241
|
+
# @return [Obj]
|
204
242
|
# @api public
|
205
243
|
def self.root
|
206
244
|
Obj.find_by_path("/") or raise ResourceNotFound, "Obj.root not found: There is no Obj with path '/'."
|
@@ -208,6 +246,7 @@ module RailsConnector
|
|
208
246
|
|
209
247
|
# Returns the homepage object. This can be overwritten in your application's +ObjExtensions+.
|
210
248
|
# Use <tt>Obj#homepage?</tt> to check if an object is the homepage.
|
249
|
+
# @return [Obj]
|
211
250
|
# @api public
|
212
251
|
def self.homepage
|
213
252
|
root
|
@@ -223,6 +262,7 @@ module RailsConnector
|
|
223
262
|
# By default a controller matching the Obj's obj_class will be used.
|
224
263
|
# If the controller does not exist, the CmsController will be used as a fallback.
|
225
264
|
# Overwrite this method to force a different controller to be used.
|
265
|
+
# @return [String]
|
226
266
|
# @api public
|
227
267
|
def controller_name
|
228
268
|
obj_class
|
@@ -231,6 +271,7 @@ module RailsConnector
|
|
231
271
|
# This method determines the action that should be invoked when the Obj is requested.
|
232
272
|
# The default action is 'index'.
|
233
273
|
# Overwrite this method to force a different action to be used.
|
274
|
+
# @return [String]
|
234
275
|
# @api public
|
235
276
|
def controller_action_name
|
236
277
|
"index"
|
@@ -243,6 +284,7 @@ module RailsConnector
|
|
243
284
|
end
|
244
285
|
|
245
286
|
# Returns the title of the content or the name.
|
287
|
+
# @return [String]
|
246
288
|
# @api public
|
247
289
|
def display_title
|
248
290
|
self.title || name
|
@@ -335,6 +377,7 @@ module RailsConnector
|
|
335
377
|
|
336
378
|
# Returns a list of exportable? children excluding the binary? ones unless :all is specfied.
|
337
379
|
# This is mainly used for navigations.
|
380
|
+
# @return [Array<Obj>]
|
338
381
|
# @api public
|
339
382
|
def toclist(*args)
|
340
383
|
return [] unless publication?
|
@@ -345,6 +388,7 @@ module RailsConnector
|
|
345
388
|
end
|
346
389
|
|
347
390
|
# Returns the sorted +toclist+, respecting sort order and type of this Obj.
|
391
|
+
# @return [Array<Obj>]
|
348
392
|
# @api public
|
349
393
|
def sorted_toclist(*args)
|
350
394
|
list = self.toclist(*args)
|
@@ -406,7 +450,9 @@ module RailsConnector
|
|
406
450
|
end
|
407
451
|
|
408
452
|
# Returns the Object with the given name next in the hierarchy
|
409
|
-
# returns nil if no object with the given name was found.
|
453
|
+
# returns +nil+ if no object with the given name was found.
|
454
|
+
# @param [String] name
|
455
|
+
# @return [Obj]
|
410
456
|
# @api public
|
411
457
|
def find_nearest(name)
|
412
458
|
obj = self.class.find_by_path(root? ? "/#{name}" : "#{path}/#{name}")
|
@@ -440,7 +486,7 @@ module RailsConnector
|
|
440
486
|
])
|
441
487
|
|
442
488
|
# Returns the value of an internal or external attribute specified by its name.
|
443
|
-
# Passing an invalid key will not raise an error, but return nil
|
489
|
+
# Passing an invalid key will not raise an error, but return +nil+.
|
444
490
|
# @api public
|
445
491
|
def [](key)
|
446
492
|
key = key.to_s
|
@@ -469,6 +515,7 @@ module RailsConnector
|
|
469
515
|
read_attribute('_text_links')
|
470
516
|
end
|
471
517
|
|
518
|
+
# @return [String]
|
472
519
|
# @api public
|
473
520
|
def obj_class
|
474
521
|
read_attribute('_obj_class')
|
@@ -494,6 +541,7 @@ module RailsConnector
|
|
494
541
|
# Override this method in subclasses to define a different content_type.
|
495
542
|
# Note that only Objs with content_type "text/html"
|
496
543
|
# will be rendered with layout and templates by the DefaultCmsController.
|
544
|
+
# @return [String]
|
497
545
|
# @api public
|
498
546
|
def content_type
|
499
547
|
if binary?
|
@@ -506,13 +554,15 @@ module RailsConnector
|
|
506
554
|
|
507
555
|
# returns the extension (the part after the last dot) from the Obj's name.
|
508
556
|
# returns an empty string if no extension is present in the Obj's name.
|
557
|
+
# @return [String]
|
509
558
|
# @api public
|
510
559
|
def file_extension
|
511
560
|
File.extname(name)[1..-1] || ""
|
512
561
|
end
|
513
562
|
|
514
563
|
# Returns the body (main content) of the Obj for non-binary Objs.
|
515
|
-
# Returns nil for binary Objs.
|
564
|
+
# Returns +nil+ for binary Objs.
|
565
|
+
# @return [String]
|
516
566
|
# @api public
|
517
567
|
def body
|
518
568
|
if binary?
|
@@ -535,7 +585,8 @@ module RailsConnector
|
|
535
585
|
end
|
536
586
|
|
537
587
|
# returns an URL to retrieve the Obj's body for binary Objs.
|
538
|
-
# returns nil for non-binary Objs.
|
588
|
+
# returns +nil+ for non-binary Objs.
|
589
|
+
# @return [String]
|
539
590
|
# @api public
|
540
591
|
def body_data_url
|
541
592
|
if binary?
|
@@ -550,7 +601,8 @@ module RailsConnector
|
|
550
601
|
end
|
551
602
|
|
552
603
|
# returns the content type of the Obj's body for binary Objs.
|
553
|
-
# returns nil for non-binary Objs.
|
604
|
+
# returns +nil+ for non-binary Objs.
|
605
|
+
# @return [String]
|
554
606
|
# @api public
|
555
607
|
def body_content_type
|
556
608
|
if binary?
|
@@ -1,39 +1,251 @@
|
|
1
1
|
module RailsConnector
|
2
|
-
# Provides an enumerator
|
3
|
-
# This is done using the {http://ruby-doc.org/core-1.8.7/Enumerable.html <code>Enumerable</code> mixin},
|
2
|
+
# Provides an enumerator for iterating over obj search results and retrieving obj instances.
|
3
|
+
# This is done using the {http://ruby-doc.org/core-1.8.7/Enumerable.html <code>Enumerable</code> mixin},
|
4
|
+
# which provides methods such as <code>map</code>, <code>select</code> or <code>take</code>.
|
4
5
|
#
|
5
|
-
# This enumerator is lazy.
|
6
|
-
#
|
6
|
+
# This enumerator is lazy. If for example you are looking for Objs with the ObjClass "Publication",
|
7
|
+
# and there are 93 objs in total, than <code>enum.take(10)</code> will fetch the first 10 objs only,
|
8
|
+
# ignoring the other 83 objs.
|
9
|
+
# This also means, that iterating multiple times over this enumerator causes the search results and objs to be fetched again.
|
10
|
+
# If you want to get all objs at once, use <code>enum.to_a</code>.
|
7
11
|
#
|
8
|
-
#
|
9
|
-
# There is one exception: To adjust how many search results should be fetch with one chunk, use the option <code>:batch_size</code>. The default is <code>10</code>. The <code>:size</code> option will be silently ignored.
|
12
|
+
# To start searching use one of the {Obj} methods that returns an {ObjSearchEnumerator}. The preferred way is to start with {Obj.where}.
|
10
13
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
+
# == Currently available fields and their values
|
15
|
+
#
|
16
|
+
# [+:*+] Searches all fields.
|
17
|
+
# This is only possible with the operators +contais+ or +starts_with+.
|
18
|
+
# [+:id+] Id of an {Obj}. This is a +string+ field.
|
19
|
+
# [+:_path+] Path of an {Obj}. This is a +string+ field.
|
20
|
+
# [+:_name+] Name of an {Obj}. This is a +string+ field.
|
21
|
+
# [+:title+] Title of an {Obj}. This is a +string+ field.
|
22
|
+
# [+:body+] Body of an {Obj}. This is an +html+ field. Thus, only the +contains+ and
|
23
|
+
# +contains_prefix+ operators can be applied to this field.
|
24
|
+
# [+:_obj_class+] ObjClass of an {Obj}. This is a +string+ field.
|
25
|
+
# [+:_permalink+] Permalink of an {Obj}. This is a +string+ field.
|
26
|
+
# [+:_valid_from+] The valid-from date of an {Obj}.
|
27
|
+
# [+:_valid_until+] The valid-until date of an {Obj}.
|
28
|
+
# [+:_last_changed+] Date of last change of an {Obj}.
|
29
|
+
# [every <em><code>:custom_attribute</code></em>] Custom attribute of an {Obj}. Note that
|
30
|
+
# depending on the attribute type (e.g. an
|
31
|
+
# +html+ field), some operators can not be applied.
|
32
|
+
#
|
33
|
+
# All values are stored as strings.
|
34
|
+
#
|
35
|
+
# Date values are stored in the format YYYYMMDDHHMMSS in UTC. For example, 2000-01-01 00:00:00 UTC is stored as "<code>20000101000000</code>".
|
36
|
+
# This is relevant for string comparisons using the +is_less_than+ and +is_greater_than+ operators.
|
37
|
+
#
|
38
|
+
# == Currently available operators
|
39
|
+
#
|
40
|
+
# For +:contains+ and +:contains_prefix+, the examples are based on the following field value:
|
41
|
+
# "Behind every cloud is another cloud."
|
42
|
+
#
|
43
|
+
# [+:contains+] Searches for one or more whole words. Each word needs to be present.
|
44
|
+
#
|
45
|
+
# Example subquery values:
|
46
|
+
#
|
47
|
+
# ✔ "behind cloud" (case insensitive)
|
48
|
+
#
|
49
|
+
# ✘ "behi clo" (not whole words)
|
50
|
+
#
|
51
|
+
# ✘ "behind everything" (second word does not match)
|
52
|
+
# [+:contains_prefix+] Searches for one prefix. A whole word is also a prefix.
|
53
|
+
#
|
54
|
+
# Example subquery values:
|
55
|
+
#
|
56
|
+
# ✔ "Clou" (case insensitive)
|
57
|
+
#
|
58
|
+
# ✔ "Every" (case insensitive)
|
59
|
+
#
|
60
|
+
# For +:equals+ and +:starts_with+, the examples are based on the following field value:
|
61
|
+
# "Some content."
|
62
|
+
#
|
63
|
+
# [+:equals+] The +field+ value needs to be identical to the +value+ of this subquery.
|
64
|
+
#
|
65
|
+
# Only applicable to +string+, +enum+, +multienum+ and +date+ fields.
|
66
|
+
#
|
67
|
+
# Example subquery values:
|
68
|
+
#
|
69
|
+
# ✔ "Some content." (exact value)
|
70
|
+
#
|
71
|
+
# ✘ "Some" (not exact value)
|
72
|
+
#
|
73
|
+
# [+:starts_with+] The +field+ value needs to start exactly with the +value+ of this subquery.
|
74
|
+
#
|
75
|
+
# Only applicable to +string+, +enum+, +multienum+ and +date+ fields.
|
76
|
+
#
|
77
|
+
# Example subquery values:
|
78
|
+
#
|
79
|
+
# ✔ "Som" (prefix of the value)
|
80
|
+
#
|
81
|
+
# ✘ "som" (incorrect case of prefix)
|
82
|
+
#
|
83
|
+
# ✘ "content" (not prefix of the whole value)
|
84
|
+
#
|
85
|
+
# For +:is_less_than+ and +:is_greater_than+, the examples are based on the following field value (date string):
|
86
|
+
# "20000101000000"
|
87
|
+
#
|
88
|
+
# [+:is_less_than+] Matches if the field string value is less than the subquery string value.
|
89
|
+
#
|
90
|
+
# Only applicable to +string+, +enum+, +multienum+ and +date+ fields.
|
91
|
+
#
|
92
|
+
# Example subquery values:
|
93
|
+
#
|
94
|
+
# ✔ "19991231235959" (is less than "20000101000000")
|
95
|
+
#
|
96
|
+
# ✘ "20000101000000" (equal, not less than)
|
97
|
+
#
|
98
|
+
# [+:is_greater_than+] Matches if the field string value is greater than the subquery string value.
|
99
|
+
#
|
100
|
+
# Only applicable to +string+, +enum+, +multienum+ and +date+ fields.
|
101
|
+
#
|
102
|
+
# Example subquery values:
|
103
|
+
#
|
104
|
+
# ✔ "20000101000001" (is greater than "20000101000000")
|
105
|
+
#
|
106
|
+
# ✘ "20000101000000" (equal, not greater than)
|
107
|
+
#
|
108
|
+
# @api public
|
14
109
|
class ObjSearchEnumerator
|
15
110
|
include Enumerable
|
16
111
|
|
17
112
|
attr_reader :query
|
18
113
|
attr_reader :options
|
114
|
+
attr_reader :initial_offset
|
19
115
|
|
20
|
-
#
|
116
|
+
# For all possible <code>query</code>'s and <code>options</code> have a look at the cms api documentation about objs/search.
|
117
|
+
# There is one exception: To adjust how many search results should be fetch with one chunk, use the option <code>:batch_size</code>. The default is <code>10</code>. The <code>:size</code> option will be silently ignored.
|
118
|
+
#
|
119
|
+
# @example All objs, which are Publications
|
120
|
+
# enum = ObjSearchEnumerator([{:field => '_obj_class', :operator => 'equal', :value => 'Publication'}])
|
121
|
+
# enum.each { |obj| puts obj.path }
|
122
|
+
#
|
123
|
+
# @param [Array<Hash>] query
|
21
124
|
# @param [Hash] options
|
22
|
-
|
125
|
+
# @param [Integer] initial_offset
|
126
|
+
def initialize(query, options = {}, initial_offset = 0)
|
23
127
|
@query = query
|
24
|
-
@
|
128
|
+
@options = options.symbolize_keys
|
129
|
+
@initial_offset = initial_offset
|
130
|
+
end
|
131
|
+
|
132
|
+
# @group Chainable methods
|
133
|
+
|
134
|
+
# Adds this additional AND subquery to this {ObjSearchEnumerator}.
|
135
|
+
#
|
136
|
+
# Compares the +field(s)+ with the +value(s)+ using the +operator+ of this subquery.
|
137
|
+
# All objs to which this criterion applies remain in the result set.
|
138
|
+
#
|
139
|
+
# @param [Symbol, String, Array<Symbol, String>] field Name(s) of the field(s) to be searched.
|
140
|
+
# For arrays, the subquery matches, if one or more of these fields meet this criterion.
|
141
|
+
# @param [Symbol, String] operator See "Currently available operators" at the top.
|
142
|
+
# @param [String, Array<String>] value The value(s) with which the field value(s) are compared using the +operator+ of this subquery.
|
143
|
+
# For arrays, the subquery matches, if the condition is met for one or more of the array elements.
|
144
|
+
# @param [Hash] boost A hash where the keys are field names and their values are boosting factors.
|
145
|
+
# Boosting factors must be in the range from 1 to 10.
|
146
|
+
# Boosting can only be applied to subqueries in which the +contains+ or +contains_prefix+ operator is used.
|
147
|
+
# @return [ObjSearchEnumerator]
|
148
|
+
# @api public
|
149
|
+
def and(field, operator, value, boost = nil)
|
150
|
+
real_operator = operator_mapping(operator)
|
151
|
+
subquery = {:field => field, :operator => real_operator, :value => convert_value(value)}
|
152
|
+
if boost.present?
|
153
|
+
valid_boost_operators = [:contains, :contains_prefix]
|
154
|
+
if valid_boost_operators.include?(operator.to_sym)
|
155
|
+
subquery[:boost] = boost
|
156
|
+
else
|
157
|
+
raise "Boost is not allowed with operator '#{operator}'. " +
|
158
|
+
"Valid operators are: #{valid_boost_operators.join(', ')}"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
@query = (query || []) + [subquery]
|
162
|
+
|
163
|
+
self
|
164
|
+
end
|
25
165
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
166
|
+
# Adds this additional negated AND subquery to this {ObjSearchEnumerator}.
|
167
|
+
#
|
168
|
+
# Compares the +field(s)+ with the +value(s)+ using the negated +operator+ of this subquery.
|
169
|
+
# All objs to which this criterion applies are removed from the result set.
|
170
|
+
#
|
171
|
+
# @param [Symbol, String, Array<Symbol, String>] field Name(s) of the field(s) to be searched.
|
172
|
+
# For arrays, the subquery matches, if one or more of these fields meet this criterion.
|
173
|
+
# @param [Symbol, String] operator Only applicable to subqueries in which the +equals+,
|
174
|
+
# +starts_with+, +is_greater_than+ and +is_less_than+ operator is used
|
175
|
+
# (See "Currently available operators" at the top).
|
176
|
+
# @param [String, Array<String>] value The value(s) with which the field value(s) are compared using the +operator+ of this subquery.
|
177
|
+
# For arrays, the subquery matches, if the condition is met for one or more of the array elements.
|
178
|
+
# @return [ObjSearchEnumerator]
|
179
|
+
# @api public
|
180
|
+
def and_not(field, operator, value)
|
181
|
+
real_operator = operator_mapping(operator)
|
182
|
+
valid_negated_operators = [:equals, :starts_with, :is_greater_than, :is_less_than]
|
183
|
+
unless valid_negated_operators.include?(operator.to_sym)
|
184
|
+
raise "Negating operator '#{operator}' is not valid."
|
30
185
|
end
|
31
|
-
|
32
|
-
|
186
|
+
subquery = {:field => field, :operator => real_operator, :value => convert_value(value),
|
187
|
+
:negate => true}
|
188
|
+
@query = (query || []) + [subquery]
|
189
|
+
|
190
|
+
self
|
191
|
+
end
|
192
|
+
|
193
|
+
# Orders the results by +field_name+.
|
194
|
+
# @param [Symbol, String] field_name This parameter determines by which field the hits are sorted (e.g. +:_path+).
|
195
|
+
# @return [ObjSearchEnumerator]
|
196
|
+
# @api public
|
197
|
+
def order(field_name)
|
198
|
+
@options[:sort_by] = field_name.to_sym
|
199
|
+
|
200
|
+
self
|
201
|
+
end
|
202
|
+
|
203
|
+
# Reverses the order of the results.
|
204
|
+
# @return [ObjSearchEnumerator]
|
205
|
+
# @api public
|
206
|
+
def reverse_order
|
207
|
+
@options[:sort_order] = case options[:sort_order]
|
208
|
+
when :asc
|
209
|
+
:desc
|
210
|
+
when :desc
|
211
|
+
:asc
|
212
|
+
else
|
213
|
+
options[:sort_by].present? ? :desc : :asc
|
214
|
+
end
|
215
|
+
|
216
|
+
self
|
33
217
|
end
|
34
218
|
|
219
|
+
# Sets the internal batch_size to +size+.
|
220
|
+
# The default is +10+, the maximum is +100+.
|
221
|
+
# @param [Integer] size A value in the range from +1+ to +100+.
|
222
|
+
# @return [ObjSearchEnumerator]
|
223
|
+
# @api public
|
224
|
+
def batch_size(size)
|
225
|
+
@options[:size] = size
|
226
|
+
|
227
|
+
self
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
# Omits the first +amount+ number of {Obj}s from the results. The default is +0+.
|
232
|
+
# @param [Integer] amount
|
233
|
+
# @return [ObjSearchEnumerator]
|
234
|
+
# @api public
|
235
|
+
def offset(amount)
|
236
|
+
@initial_offset += amount
|
237
|
+
|
238
|
+
self
|
239
|
+
end
|
240
|
+
|
241
|
+
# @!endgroup
|
242
|
+
|
243
|
+
# Iterates over the search result.
|
244
|
+
# @yield [Obj]
|
245
|
+
# @return [void]
|
246
|
+
# @api public
|
35
247
|
def each
|
36
|
-
offset =
|
248
|
+
offset = @initial_offset
|
37
249
|
current_batch, total = fetch_next_batch(offset)
|
38
250
|
loop do
|
39
251
|
if current_batch.size == 0
|
@@ -50,19 +262,56 @@ module RailsConnector
|
|
50
262
|
end
|
51
263
|
end
|
52
264
|
|
53
|
-
# The total
|
265
|
+
# The total number of hits.
|
54
266
|
# @return [Integer]
|
267
|
+
# @api public
|
55
268
|
def size
|
56
269
|
if @size.blank?
|
57
|
-
@size = CmsRestApi.get(resource_path, {:query => query, :size =>
|
270
|
+
@size = CmsRestApi.get(resource_path, {:query => query, :size => 0})['total'].to_i
|
58
271
|
end
|
59
272
|
@size
|
60
273
|
end
|
61
274
|
|
275
|
+
# @api public
|
62
276
|
alias_method :length, :size
|
63
277
|
|
64
278
|
private
|
65
279
|
|
280
|
+
def convert_value(value)
|
281
|
+
if value.kind_of?(Array)
|
282
|
+
value.map{ |v| convert_single_value(v) }
|
283
|
+
else
|
284
|
+
convert_single_value(value)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def convert_single_value(value)
|
289
|
+
if value.kind_of?(Time)
|
290
|
+
value.to_iso
|
291
|
+
else
|
292
|
+
value
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def operator_mapping(operator)
|
297
|
+
case operator.to_sym
|
298
|
+
when :contains
|
299
|
+
:search
|
300
|
+
when :contains_prefix
|
301
|
+
:prefix_search
|
302
|
+
when :equals
|
303
|
+
:equal
|
304
|
+
when :starts_with
|
305
|
+
:prefix
|
306
|
+
when :is_greater_than
|
307
|
+
:greater_than
|
308
|
+
when :is_less_than
|
309
|
+
:less_than
|
310
|
+
else
|
311
|
+
raise "Operator '#{operator}'' is not valid!"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
66
315
|
def fetch_next_batch(offset)
|
67
316
|
request_result = CmsRestApi.get(resource_path, search_dsl(offset))
|
68
317
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark_cloud_connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 343251185
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 6
|
8
8
|
- 8
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
-
|
12
|
-
version: 6.8.0.
|
10
|
+
- 444
|
11
|
+
- 171626367
|
12
|
+
version: 6.8.0.444.171626367
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Infopark AG
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2012-12-
|
20
|
+
date: 2012-12-06 00:00:00 +01:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -57,14 +57,14 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - "="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
60
|
+
hash: 343251185
|
61
61
|
segments:
|
62
62
|
- 6
|
63
63
|
- 8
|
64
64
|
- 0
|
65
|
-
-
|
66
|
-
-
|
67
|
-
version: 6.8.0.
|
65
|
+
- 444
|
66
|
+
- 171626367
|
67
|
+
version: 6.8.0.444.171626367
|
68
68
|
version_requirements: *id003
|
69
69
|
name: kvom
|
70
70
|
prerelease: false
|