esse 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exec/esse +2 -0
- data/lib/esse/cli/extensions_loader.rb +22 -0
- data/lib/esse/cli.rb +1 -0
- data/lib/esse/cluster.rb +7 -1
- data/lib/esse/index/search.rb +8 -1
- data/lib/esse/primitives/hash_utils.rb +11 -0
- data/lib/esse/search/query/dsl.rb +61 -0
- data/lib/esse/search/query.rb +7 -9
- data/lib/esse/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a099bc1faa2e68ba9683a7a578ea9138414986771c8a0487e905f6e2f83f492
|
4
|
+
data.tar.gz: ee9d1e6e77c80eaa1c69f984c8b03cdfc61176d9d38298ec0b67bce4e0d7e229
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be3d90b078ccf2a0df311e57cb0a1d4da0726343ce0cb704b527b3d1ec663c42a4ee4d039b5d1c9776d76ca39ee9784aae225d11e9f932c9f7364f52fae1d8b7
|
7
|
+
data.tar.gz: 859626e5330adec7013b992271ccf72cb08a7c91d0cdad64447c192b712621779592ecf64d27f0a1d2d6962af0da0c03ac155850f3cc2a222e390d027baee732
|
data/exec/esse
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
module CLI
|
5
|
+
class ExtensionsLoader
|
6
|
+
GEMS = %w[
|
7
|
+
esse-rails
|
8
|
+
esse-active_record
|
9
|
+
esse-sequel
|
10
|
+
esse-kaminari
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
def self.load!
|
14
|
+
GEMS.each do |gem_name|
|
15
|
+
require gem_name
|
16
|
+
rescue LoadError
|
17
|
+
# do nothing
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/esse/cli.rb
CHANGED
data/lib/esse/cluster.rb
CHANGED
@@ -4,6 +4,12 @@ require_relative 'cluster_engine'
|
|
4
4
|
require_relative 'transport'
|
5
5
|
|
6
6
|
module Esse
|
7
|
+
class << self
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators :config, :cluster
|
11
|
+
end
|
12
|
+
|
7
13
|
class Cluster
|
8
14
|
ATTRIBUTES = %i[index_prefix settings mappings client wait_for_status readonly].freeze
|
9
15
|
WAIT_FOR_STATUSES = %w[green yellow red].freeze
|
@@ -133,7 +139,7 @@ module Esse
|
|
133
139
|
end
|
134
140
|
|
135
141
|
def engine
|
136
|
-
@engine ||=ClusterEngine.new(**info)
|
142
|
+
@engine ||= ClusterEngine.new(**info)
|
137
143
|
end
|
138
144
|
alias_method :warm_up!, :engine
|
139
145
|
|
data/lib/esse/index/search.rb
CHANGED
@@ -6,6 +6,13 @@ module Esse
|
|
6
6
|
# @param query_or_payload [String,Hash] The search request definition or query in the Lucene query string syntax
|
7
7
|
# @param kwargs [Hash] The options to pass to the search.
|
8
8
|
def search(*args, &block)
|
9
|
+
kwargs = extract_search_options!(args)
|
10
|
+
cluster.search(self, **kwargs, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def extract_search_options!(args)
|
9
16
|
query_or_payload = args.shift
|
10
17
|
kwargs = args.last.is_a?(Hash) ? args.pop : {}
|
11
18
|
|
@@ -18,7 +25,7 @@ module Esse
|
|
18
25
|
elsif query_or_payload.is_a?(String)
|
19
26
|
kwargs[:q] = query_or_payload
|
20
27
|
end
|
21
|
-
|
28
|
+
kwargs
|
22
29
|
end
|
23
30
|
end
|
24
31
|
|
@@ -6,6 +6,17 @@ module Esse
|
|
6
6
|
module HashUtils
|
7
7
|
module_function
|
8
8
|
|
9
|
+
def deep_dup(hash)
|
10
|
+
hash.each_with_object({}) do |(key, value), result|
|
11
|
+
result[key] = \
|
12
|
+
if value.is_a?(Hash)
|
13
|
+
deep_dup(value)
|
14
|
+
else
|
15
|
+
value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
9
20
|
def deep_transform_keys(hash, &block)
|
10
21
|
hash.each_with_object({}) do |(key, value), result|
|
11
22
|
result[yield(key)] = \
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
module Search
|
5
|
+
class Query
|
6
|
+
module DSL
|
7
|
+
def limit(value)
|
8
|
+
return self if value.to_i <= 0
|
9
|
+
|
10
|
+
mutate do |defn|
|
11
|
+
defn.delete(:size)
|
12
|
+
if (body = defn[:body]).is_a?(Hash)
|
13
|
+
body[body.key?('size') ? 'size' : :size] = value.to_i
|
14
|
+
else
|
15
|
+
defn.update(size: value.to_i)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def offset(value)
|
21
|
+
return self if value.to_i < 0
|
22
|
+
|
23
|
+
mutate do |defn|
|
24
|
+
defn.delete(:from)
|
25
|
+
if (body = defn[:body]).is_a?(Hash)
|
26
|
+
body[body.key?('from') ? 'from' : :from] = value.to_i
|
27
|
+
else
|
28
|
+
defn.update(from: value.to_i)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def limit_value
|
34
|
+
raw_limit_value || 10
|
35
|
+
end
|
36
|
+
|
37
|
+
def offset_value
|
38
|
+
raw_offset_value || 0
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def mutate(&block)
|
44
|
+
relation = clone
|
45
|
+
relation.send(:reset!)
|
46
|
+
relation.instance_variable_set(:@definition, HashUtils.deep_dup(definition))
|
47
|
+
relation.instance_exec(relation.definition, &block) if block
|
48
|
+
relation
|
49
|
+
end
|
50
|
+
|
51
|
+
def raw_limit_value
|
52
|
+
definition.dig(:body, :size) || definition.dig(:body, 'size') || definition.dig(:size) || definition.dig('size')
|
53
|
+
end
|
54
|
+
|
55
|
+
def raw_offset_value
|
56
|
+
definition.dig(:body, :from) || definition.dig(:body, 'from') || definition.dig(:from) || definition.dig('from')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/esse/search/query.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'query/dsl'
|
3
4
|
module Esse
|
4
5
|
module Search
|
5
6
|
class Query
|
7
|
+
include DSL
|
6
8
|
attr_reader :transport, :definition
|
7
9
|
|
8
10
|
# @param transport [Esse::Transport] The client proxy to use for the query
|
@@ -11,7 +13,11 @@ module Esse
|
|
11
13
|
def initialize(transport, *indices, suffix: nil, **definition, &_block)
|
12
14
|
@transport = transport
|
13
15
|
@definition = definition
|
14
|
-
@definition[:index] = indices.
|
16
|
+
@definition[:index] = self.class.normalize_indices(*indices, suffix: suffix) if indices.size > 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.normalize_indices(*indices, suffix: nil)
|
20
|
+
indices.map do |index|
|
15
21
|
if index.is_a?(Class) && index < Esse::Index
|
16
22
|
index.index_name(suffix: suffix)
|
17
23
|
elsif index.is_a?(String) || index.is_a?(Symbol)
|
@@ -92,14 +98,6 @@ module Esse
|
|
92
98
|
def reset!
|
93
99
|
@response = nil
|
94
100
|
end
|
95
|
-
|
96
|
-
def raw_limit_value
|
97
|
-
definition.dig(:body, :size) || definition.dig(:body, 'size') || definition.dig(:size) || definition.dig('size')
|
98
|
-
end
|
99
|
-
|
100
|
-
def raw_offset_value
|
101
|
-
definition.dig(:body, :from) || definition.dig(:body, 'from') || definition.dig(:from) || definition.dig('from')
|
102
|
-
end
|
103
101
|
end
|
104
102
|
end
|
105
103
|
end
|
data/lib/esse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos G. Zimmermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exec
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- lib/esse/cli.rb
|
216
216
|
- lib/esse/cli/base.rb
|
217
217
|
- lib/esse/cli/event_listener.rb
|
218
|
+
- lib/esse/cli/extensions_loader.rb
|
218
219
|
- lib/esse/cli/generate.rb
|
219
220
|
- lib/esse/cli/index.rb
|
220
221
|
- lib/esse/cli/index/base_operation.rb
|
@@ -285,6 +286,7 @@ files:
|
|
285
286
|
- lib/esse/repository/documents.rb
|
286
287
|
- lib/esse/repository/object_document_mapper.rb
|
287
288
|
- lib/esse/search/query.rb
|
289
|
+
- lib/esse/search/query/dsl.rb
|
288
290
|
- lib/esse/search/response.rb
|
289
291
|
- lib/esse/template_loader.rb
|
290
292
|
- lib/esse/transport.rb
|