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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30ce86d71e0cf9b67506dd0caf1651b91ae836c9e7981e46a238446c8afde078
4
- data.tar.gz: 9ec1069cbb8106743d5832f94fbce5d2c937037a62a746350e736385f3b78cdc
3
+ metadata.gz: 0a099bc1faa2e68ba9683a7a578ea9138414986771c8a0487e905f6e2f83f492
4
+ data.tar.gz: ee9d1e6e77c80eaa1c69f984c8b03cdfc61176d9d38298ec0b67bce4e0d7e229
5
5
  SHA512:
6
- metadata.gz: f2a5012e3d3dab0b3894f8e8fb1665be2a57c8538a3fc02bce2ac089510bd63b982f8f919554a9f16d6e8dafe5d93d9f5614d99ca4f170d82cc41e413fec0209
7
- data.tar.gz: 034b15fd5cfc4f6ebdd97ba9d73ed284f50c209225b2c6a43b27216a57578ca1b91d9c92d4e020c4a1c7910038cf5978054bfa4b491bafb431bcfc1dcbc0a706
6
+ metadata.gz: be3d90b078ccf2a0df311e57cb0a1d4da0726343ce0cb704b527b3d1ec663c42a4ee4d039b5d1c9776d76ca39ee9784aae225d11e9f932c9f7364f52fae1d8b7
7
+ data.tar.gz: 859626e5330adec7013b992271ccf72cb08a7c91d0cdad64447c192b712621779592ecf64d27f0a1d2d6962af0da0c03ac155850f3cc2a222e390d027baee732
data/exec/esse CHANGED
@@ -6,6 +6,8 @@ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
6
6
  require 'esse'
7
7
  require 'esse/cli'
8
8
 
9
+ Esse::CLI::ExtensionsLoader.load!
10
+
9
11
  Esse::CLI.with_friendly_errors do
10
12
  Esse::CLI.start(ARGV)
11
13
  end
@@ -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
@@ -6,6 +6,7 @@ require_relative 'primitives/output'
6
6
  require_relative 'cli/index'
7
7
  require_relative 'cli/generate'
8
8
  require_relative 'cli/event_listener'
9
+ require_relative 'cli/extensions_loader'
9
10
 
10
11
  module Esse
11
12
  module CLI
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
 
@@ -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
- cluster.search(self, **kwargs, &block)
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
@@ -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.map do |index|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Esse
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.4'
5
5
  end
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.3
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 00:00:00.000000000 Z
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