elastico 0.0.1 → 0.0.3
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 +8 -8
- data/Gemfile.lock +1 -1
- data/README.md +13 -1
- data/elastico.gemspec +1 -1
- data/lib/elastico/callbacks.rb +12 -29
- data/lib/elastico/client.rb +4 -4
- data/lib/elastico/index.rb +4 -0
- data/lib/elastico/search.rb +0 -5
- data/lib/elastico/version.rb +1 -1
- data/lib/elastico.rb +7 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2JkZTg4NmYzZjZkM2QwNjEyZjFjMjFiOGU2OGIzY2YyYjZmMzM1Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGEwOTQ3ZDcwZWUzMDhkOGU5NjM4YWM0NTczMTE0N2U3MWQ0NDZiOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGRjYzhlZDUyNDhhOTZiYTg5MzYxNzVjMzhmMWE5NzgyNmQ4MTdjNTMwMWFl
|
10
|
+
MGZiMjBiMjY2ZDAwMGFlY2YyMDY0NWE4N2UxYmRkMmYyYTM2ZjNhNmZlMDZh
|
11
|
+
NTJjZjA1NGI5N2JkNWVhZTVjMWIxNWY1NjFlOGE1ZTM0YTM5NDA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGZlZjQ1MzUyMTE2MGFlODIxMjQxZWVmYWZkYTkzMTcwNjE2YjZhZDZjYjIz
|
14
|
+
OTQ5ZGEwOGI3YmU2NjVmNDFhNmUxOWJkMjg2NmJlNGI2NTY2OTM1YTlmNjI5
|
15
|
+
ZDA2MTI2MTQzNmU2YmJkMjU3MmM1NzYyNmY3YzJmMjhhMWQ2ODI=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -28,6 +28,18 @@ TODO: Write usage instructions here
|
|
28
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
29
|
5. Create new Pull Request
|
30
30
|
|
31
|
+
Usage:
|
32
|
+
|
33
|
+
In order to get a model work with elastic search you have to:
|
34
|
+
1. Set Elastico::Configuration.url= to be the ip of your elasticsearch server (defaults to "localhost").
|
35
|
+
2. Set Elastico::Index.settings_and_mappings_json= to be your settings and mapping json.
|
36
|
+
3. Set up Elastico::Search.search_json= to be your standard search query for that model.
|
37
|
+
4. Elastico will automatically save your active record models after every "save" call on that instance.
|
38
|
+
5. In later versions I will add an auto rake task to import all of your Elastico models to elasticsearch server.
|
39
|
+
|
40
|
+
|
41
|
+
In order to search this model, all you need to do is to do Model.elastic_search(term). This will return the elasticsearch results in an Elastico results object. You should override this method (elastic_search) if you want to get a better tailored solution.
|
42
|
+
=======
|
31
43
|
|
32
44
|
Usage:
|
33
45
|
======
|
@@ -75,4 +87,4 @@ settings_json[:settings] = {
|
|
75
87
|
}
|
76
88
|
}
|
77
89
|
|
78
|
-
a
|
90
|
+
a
|
data/elastico.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.authors = ["Eyal Goren"]
|
10
10
|
gem.email = ["gneyal@gmail.com"]
|
11
11
|
gem.description = %q{A general way to use elasticsearch}
|
12
|
-
gem.summary = %q{Elastico
|
12
|
+
gem.summary = %q{Elastico presents a simple way to work with elasticsearch. 1. Define your setup. 2. Define your search query. 3. Search.}
|
13
13
|
gem.homepage = ""
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
data/lib/elastico/callbacks.rb
CHANGED
@@ -1,37 +1,20 @@
|
|
1
1
|
module Elastico
|
2
|
-
module
|
2
|
+
module Callbacks
|
3
3
|
def self.included(base)
|
4
|
-
update_conditions = lambda {
|
4
|
+
update_conditions = lambda { update_index_with_instance_elastico }
|
5
5
|
|
6
6
|
base.send :after_save, update_conditions
|
7
7
|
base.send :after_destroy, update_conditions
|
8
|
-
|
8
|
+
base.send :after_touch, update_conditions
|
9
9
|
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
Spawnling.new do
|
23
|
-
account = Admin::Account.find(acc_id)
|
24
|
-
account.connect_to_target_db
|
25
|
-
update_index_with_instance
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
if AppConfig["enable_tire_callbacks"] && base.respond_to?(:after_save) && base.respond_to?(:after_destroy)
|
32
|
-
base.send :after_save, update_conditions
|
33
|
-
base.send :after_destroy, update_conditions
|
34
|
-
base.send :after_touch, update_conditions
|
35
|
-
end
|
11
|
+
def update_index_with_instance_elastico
|
12
|
+
type = self.class.elastico_type_name
|
13
|
+
index = self.class.elastico_index_name
|
14
|
+
id = self.id
|
15
|
+
url = self.class.elastico_url + index + "/" + type + "/" + id.to_s
|
16
|
+
instance = self.to_json
|
17
|
+
self.class.general_request(instance, url)
|
36
18
|
end
|
37
|
-
|
19
|
+
end
|
20
|
+
end
|
data/lib/elastico/client.rb
CHANGED
@@ -8,11 +8,11 @@ module Elastico
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def general_request(url=
|
12
|
-
RestClient.
|
13
|
-
|
11
|
+
def general_request(content=nil, url=self.elastico_url, hash_respond_wanted = true)
|
12
|
+
RestClient.post(url, content, :content_type => :json, :accept => :json) do |response, request, result|
|
13
|
+
ret = JSON.pretty_generate(JSON.parse(response.to_str))
|
14
|
+
hash_respond_wanted ? JSON.parse(ret) : ret
|
14
15
|
end
|
15
|
-
response
|
16
16
|
end
|
17
17
|
|
18
18
|
def elastico_search(hash_respond_wanted = true)
|
data/lib/elastico/index.rb
CHANGED
data/lib/elastico/search.rb
CHANGED
data/lib/elastico/version.rb
CHANGED
data/lib/elastico.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require_relative "./elastico/configuration"
|
2
2
|
require_relative "./elastico/version"
|
3
|
+
require_relative "./elastico/callbacks"
|
3
4
|
require_relative "./elastico/index"
|
4
5
|
require_relative "./elastico/search"
|
5
6
|
require_relative "./elastico/client"
|
6
7
|
|
7
8
|
|
8
9
|
module Elastico
|
9
|
-
# Your code goes here...
|
10
|
-
|
11
|
-
# making these modules class modules - meaning that the traits they define are set as class traits (not instance traits)
|
12
10
|
def self.included(base)
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
base.extend Configuration
|
12
|
+
base.extend Index
|
13
|
+
base.extend Search
|
16
14
|
base.extend Client
|
17
|
-
|
15
|
+
|
16
|
+
base.send :include_callbacks
|
17
|
+
end
|
18
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eyal Goren
|
@@ -87,7 +87,8 @@ rubyforge_project:
|
|
87
87
|
rubygems_version: 2.0.6
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
|
-
summary: Elastico
|
90
|
+
summary: Elastico presents a simple way to work with elasticsearch. 1. Define your
|
91
|
+
setup. 2. Define your search query. 3. Search.
|
91
92
|
test_files:
|
92
93
|
- test/lib/elastico/client_test.rb
|
93
94
|
- test/lib/elastico/configuration_test.rb
|