elasticsearch_hermes 0.0.4.2 → 0.0.8

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
  SHA1:
3
- metadata.gz: 3923c6822a3a4f1f1fff0d0ba1bce68cbdda83c2
4
- data.tar.gz: d15724eb798e20cfecbb0b641a71a8383eb516ff
3
+ metadata.gz: b316c65bf4c95f6855434198e9961b1c7be60a06
4
+ data.tar.gz: 1385dc3839fbede3bdf1780b052bd3bf7596e402
5
5
  SHA512:
6
- metadata.gz: a7172c9c57053c493ec15d79b0ad302c71dc9ad2b4cb0151f1cdcab2cab1bfaa956445c73adf25651d2013e1154cbf112fe7e475c1cd34f920a02e22a3f772d5
7
- data.tar.gz: 40e4a5ef7d2462610a57ad4fd5ea574345f414f9ade32e4921337ed63e7a7dd0ea5d8ab54470dda05a86937ab0a89efa083d6842fa3eefda3af3734a5f14ba1b
6
+ metadata.gz: c1f77c052089896350412915642063cd9afa4606320e4c0c61fa4490a1553275f631709f8b4aba6fd71245ccd09805bd55f89656a2de1e687e15e184ba18e44f
7
+ data.tar.gz: 33ba96fdd202c3ca06b70923f4e3ec997fbb680e8e0e557f417df3f54162c94ddcf3567274610f949d9d312cd32040ba6258ae6337f41d632d2a87c36dff939e
@@ -5,6 +5,10 @@ require 'elasticsearch_hermes/railtie'
5
5
  require 'elasticsearch_hermes/errors'
6
6
  require 'elasticsearch_hermes/configuration'
7
7
  require 'elasticsearch_hermes/index'
8
+ require 'elasticsearch_hermes/indexing/model'
9
+ require 'elasticsearch_hermes/indexing/helper'
10
+ require 'elasticsearch_hermes/query'
11
+ require 'elasticsearch_hermes/result/base'
8
12
  require 'elasticsearch_hermes/hook'
9
13
  require 'elasticsearch_hermes/logger'
10
14
  require 'elasticsearch_hermes/elasticsearch_hermes'
@@ -3,15 +3,14 @@
3
3
  module ElasticsearchHermes
4
4
  class Configuration
5
5
  attr_accessor :request_timeout, :retry_on_failure, :es_user, :es_password
6
- attr_accessor :es_url, :enable_logs, :fields
6
+ attr_accessor :es_url, :enable_logs
7
7
  def initialize
8
8
  @request_timeout = nil
9
9
  @retry_on_failure = nil
10
10
  @es_user = nil
11
11
  @es_password = nil
12
12
  @es_url = nil
13
- @enable_logs = nil
14
- @fields = nil
13
+ @enable_logs = false
15
14
  end
16
15
  end
17
16
  end
@@ -22,7 +22,11 @@ module ElasticsearchHermes
22
22
  def self.default_connect_options
23
23
  base_es_urls = configuration.es_url
24
24
  urls = base_es_urls.split(',').compact.uniq
25
- options = { url: urls, retry_on_failure: 2, log: true }
25
+ options = {
26
+ url: urls,
27
+ retry_on_failure: configuration.retry_on_failure,
28
+ log: configuration.enable_logs
29
+ }
26
30
  options
27
31
  end
28
32
 
@@ -34,19 +38,9 @@ module ElasticsearchHermes
34
38
  configuration.fields
35
39
  end
36
40
 
37
-
38
41
  def self.connect!
39
42
  return unless client
40
43
 
41
-
42
- indices = fields.map { |field| field[:index_name] }.uniq
43
-
44
- indices.each do |index|
45
- Logger.log("Checking index #{index}")
46
- index_s = ElasticsearchHermes::Index.new(index)
47
- index_s.create unless index_s.exist?
48
- end
49
-
50
44
  info = @client.info
51
45
  cluster_version = info['version']['number']
52
46
  msg = "Connected to Elastic version #{cluster_version}."
@@ -2,8 +2,5 @@
2
2
 
3
3
  module ElasticsearchHermes
4
4
  module Hook
5
- class << self
6
-
7
- end
8
5
  end
9
6
  end
@@ -4,28 +4,30 @@ module ElasticsearchHermes
4
4
  class Index
5
5
  attr_reader :name
6
6
 
7
- def initialize(name)
7
+ def initialize(name:, fields: [])
8
8
  @name = name
9
+ @fields = fields
9
10
  end
10
11
 
11
12
  def create
12
13
  ElasticsearchHermes.client.indices.create index: @name, body: index_options
13
14
  end
14
15
 
16
+ def delete
17
+ ElasticsearchHermes.client.indices.delete index: @name
18
+ end
19
+
15
20
  def exist?
16
21
  ElasticsearchHermes.client.indices.exists? index: @name
17
22
  end
18
23
 
19
- def fields
20
- ElasticsearchHermes.fields || []
21
- end
24
+ private
22
25
 
23
26
  def build_field_mappings
24
- fields_to_index = fields.select { |field| field[:index_name] == @name }
25
27
  properties = {}
26
28
  analyzer = {}
27
29
  tokenizer = {}
28
- fields_to_index.each do |field|
30
+ @fields.each do |field|
29
31
  # add checks for full_match
30
32
  if field[:search_type] == :partial_match
31
33
  @field_token = ngram_builder(field[:minimum_match], field[:field_name])
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElasticsearchHermes
4
+ module Indexing
5
+ module Helper
6
+ def re_index(index_name: to_s.underscore)
7
+ delete_index(index_name: index_name)
8
+ @index_object.create
9
+ all.find_each(&:touch)
10
+ end
11
+
12
+ def delete_index(index_name: to_s.underscore)
13
+ @index_object ||= ElasticsearchHermes::Index.new(name: index_name, fields: @fields)
14
+ @index_object.delete
15
+ rescue Elasticsearch::Transport::Transport::Errors::NotFound
16
+ Logger.log("No Such index: #{index_name}")
17
+ end
18
+
19
+ def index_on(fields: [])
20
+ @fields = fields
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElasticsearchHermes
4
+ module Indexing
5
+ module Model
6
+ def elastic_update(type: '_doc', index_name: self.class.to_s.underscore, id:, body:)
7
+ ElasticsearchHermes.client.index index_payload(
8
+ index_name: index_name,
9
+ type: type,
10
+ body: body,
11
+ id: id
12
+ )
13
+ end
14
+
15
+ def index_payload(index_name:, type:, id:, body:)
16
+ {
17
+ type: type,
18
+ index: index_name,
19
+ id: id,
20
+ body: body
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElasticsearchHermes
4
+ module Query
5
+ def search(query: '', index_name: to_s.underscore, fields: @hermes_search_on)
6
+ @results = ElasticsearchHermes.client.search query_payload(
7
+ query: query,
8
+ index_name: index_name,
9
+ fields: fields
10
+ )
11
+ ElasticsearchHermes::Result::Base.new(@results.symbolize_keys)
12
+ end
13
+
14
+ def hermes_search_on(fields: [])
15
+ @hermes_search_on ||= fields.map(&:to_s)
16
+ end
17
+
18
+ def search_type; end
19
+
20
+ def field_type; end
21
+
22
+ def minimum_match; end
23
+
24
+ def query_payload(query:, index_name:, fields:)
25
+ {
26
+ index: index_name,
27
+ body: {
28
+ query: {
29
+ multi_match: {
30
+ query: query,
31
+ fields: fields
32
+ }
33
+ }
34
+ }
35
+ }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElasticsearchHermes
4
+ module Result
5
+ class Base
6
+ attr_reader :took, :timed_out, :shards, :hits
7
+
8
+ def initialize(took:, timed_out:, hits:, _shards:)
9
+ @took = took
10
+ @timed_out = timed_out
11
+ @shards = _shards
12
+ @hits = hits
13
+ end
14
+
15
+ def ids
16
+ @ids ||= @hits['hits'].map { |hit| hit['_id'] }
17
+ end
18
+
19
+ def models
20
+ @models ||= ''
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElasticsearchHermes
4
+ module Result
5
+ class Hit
6
+ #TODO: abstract hits from results class
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElasticsearchHermes
4
- VERSION = '0.0.4.2'
4
+ VERSION = '0.0.8'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch_hermes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.2
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronald Ekambi
@@ -42,8 +42,13 @@ files:
42
42
  - lib/elasticsearch_hermes/errors.rb
43
43
  - lib/elasticsearch_hermes/hook.rb
44
44
  - lib/elasticsearch_hermes/index.rb
45
+ - lib/elasticsearch_hermes/indexing/helper.rb
46
+ - lib/elasticsearch_hermes/indexing/model.rb
45
47
  - lib/elasticsearch_hermes/logger.rb
48
+ - lib/elasticsearch_hermes/query.rb
46
49
  - lib/elasticsearch_hermes/railtie.rb
50
+ - lib/elasticsearch_hermes/result/base.rb
51
+ - lib/elasticsearch_hermes/result/hit.rb
47
52
  - lib/elasticsearch_hermes/version.rb
48
53
  homepage: https://github.com/roncodingenthusiast/elasticsearch_hermes
49
54
  licenses:
@@ -68,6 +73,5 @@ rubyforge_project:
68
73
  rubygems_version: 2.6.14.3
69
74
  signing_key:
70
75
  specification_version: 4
71
- summary: elasticsearch_hermes is a layer on top of elasticsearch-ruby to handle the
72
- complicated configuration of elastic
76
+ summary: I will fix this eventually
73
77
  test_files: []