elastify 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/lib/elastify/active_record_extensions.rb +14 -9
- data/lib/elastify/elastic_search_helper.rb +2 -1
- data/lib/elastify/version.rb +1 -1
- data/lib/elastify.rb +27 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39b47345213b76f73caeca0ede7a9eee9714f969
|
4
|
+
data.tar.gz: dd96aae8aa98923485139aee53348e6d4749d989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a751e4ac6c914c472b472155a4090bceba325b8f341bf9ce2f03a4ad03a5204c23261241056ca6218f9e51b48eb68115268ba55155e12cf1d1297cd78c8e277
|
7
|
+
data.tar.gz: 1e958d6c57eeeceb74d4374231109b7c5596a496667236cda47e6638e3d794f8ba4bd3fc8e762c957039410e03c41e82fdda4b06d4b3cf3dccd3f0a7ddc0109c
|
@@ -1,22 +1,23 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'backgrounded'
|
3
3
|
require 'elastify/elastic_search_helper'
|
4
|
+
require 'elastify'
|
4
5
|
|
5
6
|
module Elastify
|
6
7
|
module ActiveRecordExtensions
|
7
8
|
extend ActiveSupport::Concern
|
8
9
|
|
9
10
|
module ClassMethods
|
10
|
-
def elastify
|
11
|
+
def elastify type, index, &block
|
11
12
|
include Elastify::ActiveRecordExtensions::LocalMethods
|
12
13
|
cattr_accessor :elastify_options, :elastify_model_block
|
13
14
|
attr_accessor :elastify_serialized_document
|
14
15
|
|
15
16
|
self.elastify_options = {
|
16
|
-
base_url: Elastify.
|
17
|
-
index:
|
18
|
-
type:
|
19
|
-
map:
|
17
|
+
base_url: Elastify.configs[:base_url],
|
18
|
+
index: index,
|
19
|
+
type: type,
|
20
|
+
map: Elastify.mappings.symbolize_keys[type.to_sym]
|
20
21
|
}
|
21
22
|
|
22
23
|
self.elastify_options.each do |key, value|
|
@@ -28,9 +29,13 @@ module Elastify
|
|
28
29
|
if block_given?
|
29
30
|
self.elastify_model_block = block
|
30
31
|
else
|
31
|
-
self.
|
32
|
-
next
|
33
|
-
|
32
|
+
if self.respond_to?(:to_elastify)
|
33
|
+
self.elastify_model_block = Proc.new { |item| next item.to_elastify }
|
34
|
+
elsif self.respond_to?(:to_serial)
|
35
|
+
self.elastify_model_block = Proc.new { |item| next item.to_serial }
|
36
|
+
else
|
37
|
+
self.elastify_model_block = Proc.new { |item| next item.serializable_hash }
|
38
|
+
end
|
34
39
|
end
|
35
40
|
end
|
36
41
|
end
|
@@ -106,4 +111,4 @@ module Elastify
|
|
106
111
|
end
|
107
112
|
end
|
108
113
|
|
109
|
-
ActiveRecord::Base.send(:include, Elastify::ActiveRecordExtensions)
|
114
|
+
ActiveRecord::Base.send(:include, Elastify::ActiveRecordExtensions)
|
@@ -80,7 +80,8 @@ module Elastify
|
|
80
80
|
end
|
81
81
|
def self.create_mapping options
|
82
82
|
url = "#{options[:base_url]}/#{options[:index]}/_mappings/#{options[:type]}"
|
83
|
-
|
83
|
+
puts options[:map]
|
84
|
+
response = JSON.parse(RestClient.put(url, options[:map].squish, {})).to_hash
|
84
85
|
end
|
85
86
|
end
|
86
87
|
class SearchResultSet
|
data/lib/elastify/version.rb
CHANGED
data/lib/elastify.rb
CHANGED
@@ -2,12 +2,35 @@ require "elastify/version"
|
|
2
2
|
require "elastify/active_record_extensions"
|
3
3
|
|
4
4
|
module Elastify
|
5
|
-
cattr_accessor :defaults
|
6
5
|
|
7
|
-
|
8
6
|
class << self
|
9
|
-
|
10
|
-
|
7
|
+
def configure &block
|
8
|
+
mappings = {}
|
9
|
+
configs = OpenStruct.new({
|
10
|
+
base_url: "http://localhost:9200",
|
11
|
+
mappings_path: Rails.root.join("config/elastify/mappings")
|
12
|
+
})
|
13
|
+
block.call(configs) if block_given?
|
14
|
+
dir = configs.mappings_path
|
15
|
+
if Dir.exist?(dir)
|
16
|
+
Dir.glob("#{dir}/*.json") do |file_path|
|
17
|
+
mappings[File.basename(file_path, ".json")] = JSON.parse(File.read(file_path))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
Rails.application.config.elastify = {
|
21
|
+
configs: configs,
|
22
|
+
mappings: mappings,
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def configs
|
27
|
+
return Rails.application.config.elastify[:configs]
|
28
|
+
end
|
11
29
|
|
30
|
+
def mappings
|
31
|
+
return Rails.application.config.elastify[:mappings]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
12
35
|
class ElastifyError < StandardError; end
|
13
36
|
end
|