elastico 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWExODkwZTBhMGI1Y2RiYmY0YzlhNWRlOTExODZjODFmZGY5OTgwMA==
4
+ M2JkZTg4NmYzZjZkM2QwNjEyZjFjMjFiOGU2OGIzY2YyYjZmMzM1Nw==
5
5
  data.tar.gz: !binary |-
6
- OTNjMWE2NGM4ZGU5YWI1MGQ2NDlkZDJjMWFjNmYxNWQ4YTkwZjZkOQ==
6
+ OGEwOTQ3ZDcwZWUzMDhkOGU5NjM4YWM0NTczMTE0N2U3MWQ0NDZiOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NGVlZDQzZjMwZDdkNmRhNDBmMjBhYjBhMzM3ZDlmMjI5ZTMwNjAxZTgxZWI4
10
- OTlhYWY1NzFkYzg4MDkyOGY4OGM0MjQ2YWEyOWZkY2ZiNWFjMWM5MGJiNGJh
11
- Y2ZiY2Q1NmY2ZjQwNmQxNzdmMjQzYTc0MzA5Mjc5ZDMxZjYxZjQ=
9
+ OGRjYzhlZDUyNDhhOTZiYTg5MzYxNzVjMzhmMWE5NzgyNmQ4MTdjNTMwMWFl
10
+ MGZiMjBiMjY2ZDAwMGFlY2YyMDY0NWE4N2UxYmRkMmYyYTM2ZjNhNmZlMDZh
11
+ NTJjZjA1NGI5N2JkNWVhZTVjMWIxNWY1NjFlOGE1ZTM0YTM5NDA=
12
12
  data.tar.gz: !binary |-
13
- ODU3MWMxYmJkMDM2NmMzYjcwMGZhYmQxYWM2OTNiNWQ1NzIwNmQ5NTYyYWIx
14
- OWI5M2U1YjNhMDVhOWY4ZWQxYWRkM2ZkY2I2ZWVjYzRmZjI0NGJmZjQ1YzRk
15
- NDdiZWNmMmFmMzlkNzdiYzJjNWY2ZDFjMmRiZTZkZDExNTE5NWQ=
13
+ NGZlZjQ1MzUyMTE2MGFlODIxMjQxZWVmYWZkYTkzMTcwNjE2YjZhZDZjYjIz
14
+ OTQ5ZGEwOGI3YmU2NjVmNDFhNmUxOWJkMjg2NmJlNGI2NTY2OTM1YTlmNjI5
15
+ ZDA2MTI2MTQzNmU2YmJkMjU3MmM1NzYyNmY3YzJmMjhhMWQ2ODI=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elastico (0.0.1)
4
+ elastico (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 is a simple alternative to work with elasticsearch}
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($/)
@@ -1,37 +1,20 @@
1
1
  module Elastico
2
- module Callback
2
+ module Callbacks
3
3
  def self.included(base)
4
- update_conditions = lambda { update_index_with_instance }
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
- base.send :after_touch, update_conditions
8
+ base.send :after_touch, update_conditions
9
9
  end
10
- end
11
- end
12
-
13
-
14
10
 
15
- module Callbacks
16
-
17
- def self.included(base)
18
- update_conditions = lambda do
19
- if ElasticSearch.elasticsearch_alive
20
- acc_id = self.account_id
21
- if LG_FEATURES[:elastic_search].enabled? account_id
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
- end
19
+ end
20
+ end
@@ -8,11 +8,11 @@ module Elastico
8
8
  end
9
9
  end
10
10
 
11
- def general_request(url=Elastico::Configuration.url, content=nil)
12
- RestClient.put(url, content, :content_type => :json, :accept => :json) do |response, request, result|
13
- puts JSON.pretty_generate(JSON.parse(response.to_str))
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)
@@ -1,5 +1,9 @@
1
1
  module Elastico
2
2
  module Index
3
+ def include_callbacks
4
+ include Elastico::Callbacks
5
+ end
6
+
3
7
  def settings_and_mappings_json
4
8
  @settings_and_mappings_json || nil
5
9
  end
@@ -7,10 +7,5 @@ module Elastico
7
7
  def search_query= json
8
8
  @search_query = json
9
9
  end
10
-
11
- def raise_exception
12
- raise 'An error has occured'
13
-
14
- end
15
10
  end
16
11
  end
@@ -1,3 +1,3 @@
1
1
  module Elastico
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
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
- base.extend Configuration
14
- base.extend Index
15
- base.extend Search
11
+ base.extend Configuration
12
+ base.extend Index
13
+ base.extend Search
16
14
  base.extend Client
17
- end
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.1
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 is a simple alternative to work with elasticsearch
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