ohm-elasticsearch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: bf819f7c97a81455d79c99c8a31316713339c364
4
+ data.tar.gz: e398060d55c5b5b98e1ccf11fe613f2535d19447
5
+ SHA512:
6
+ metadata.gz: f9f614d22579ae894d42e00431d166d484da0eb1ddaba26d455c46502b53d742e73f1bded0b063c0242594148dac0da8d83b7e420d0b2366e710227d3b431ce0
7
+ data.tar.gz: d80eb065a0e1e7b383166bdf4b58304b37972ecc43b1ee57fae39131a738aa79d607b7071bb6863468d4915229be7c7856edefb9d40121e362a5c6ddb9005cbf
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ohm-elasticsearch.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 chebyte
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # Ohm::Elasticsearch
2
+
3
+ Very small Ruby implementation for Elasticsearch (https://github.com/elasticsearch) and OHM (https://github.com/soveran/ohm).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ohm-elasticsearch'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ohm-elasticsearch
18
+
19
+ ## Usage
20
+
21
+ class Event < Ohm::Model
22
+ include Ohm::Elasticsearch
23
+ include Ohm::Callbacks #It's necessary for indexing records
24
+
25
+ attribute :name
26
+ end
27
+
28
+ protected
29
+
30
+ def after_save
31
+ index_save
32
+ end
33
+
34
+ def before_delete
35
+ index_delete
36
+ end
37
+
38
+
39
+ # Event.search({body: { query: { match: { name: 'test' } } } })
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/hashdog/ohm-elasticsearch/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,80 @@
1
+ require "ohm/elasticsearch/version"
2
+ require 'elasticsearch'
3
+
4
+ module Ohm
5
+ module Elasticsearch
6
+ class ConnectException < IOError;end
7
+
8
+ @@_current_indexer = nil
9
+
10
+ def self.current_indexer
11
+ @@_current_indexer or raise ConnectException, "Can't connect to ELasticsearch server"
12
+ end
13
+
14
+ def self.connect(arguments={})
15
+ @@_current_indexer = ::Elasticsearch::Client.new(arguments)
16
+ end
17
+
18
+ def self.included(model)
19
+ model.extend(ClassMethods)
20
+ model.send(:include, InstanceMethods)
21
+ end
22
+
23
+ module ClassMethods
24
+ def indexer
25
+ Ohm::Elasticsearch.current_indexer
26
+ end
27
+
28
+ def index_name
29
+ "#{name}_main".downcase
30
+ end
31
+
32
+ def index_type
33
+ name.downcase
34
+ end
35
+
36
+ # args:
37
+ # {body: { query: { match: { title: 'test' } } } }
38
+ def search(args={})
39
+ params = {index: index_name}.merge(args)
40
+ indexer.search params
41
+ end
42
+
43
+ # args:
44
+ # {body: {
45
+ # template: {
46
+ # query: {
47
+ # range: {
48
+ # date: { gte: "{{start}}", lte: "{{end}}" }
49
+ # }
50
+ # }
51
+ # },
52
+ # params: { start: "2014-02-01", end: "2014-03-01" }
53
+ # }
54
+ # }
55
+ def search_template(args={})
56
+ template = {index: index_name}
57
+ template.merge!(body: args)
58
+
59
+ indexer.search_template template
60
+ end
61
+ end
62
+
63
+ module InstanceMethods
64
+
65
+ def index_attributes
66
+ attributes
67
+ end
68
+
69
+ protected
70
+
71
+ def index_save
72
+ self.class.indexer.index(index: self.class.index_name, type: self.class.index_type, id: id, body: index_attributes)
73
+ end
74
+
75
+ def index_delete
76
+ self.class.indexer.delete(index: self.class.index_name, type: self.class.index_type, id: id)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ module Ohm
2
+ module Elasticsearch
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ohm/elasticsearch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ohm-elasticsearch"
8
+ spec.version = Ohm::Elasticsearch::VERSION
9
+ spec.authors = ["chebyte", "lguardiola"]
10
+ spec.email = ["mauro@hashdog.com", "lguardiola@gmail.com"]
11
+ spec.summary = %q{Very small ruby implementation for Elasticsearch and OHM.}
12
+ spec.description = %q{Very small ruby implementation for Elasticsearch (https://github.com/elasticsearch) and OHM (https://github.com/soveran/ohm).}
13
+ spec.homepage = "http://hashdog.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency 'rake', '~> 0'
23
+ spec.add_runtime_dependency 'elasticsearch', '~> 1.0', '>= 1.0.5'
24
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ohm-elasticsearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - chebyte
8
+ - lguardiola
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.6'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: elasticsearch
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.0'
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: 1.0.5
52
+ type: :runtime
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: '1.0'
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.5
62
+ description: Very small ruby implementation for Elasticsearch (https://github.com/elasticsearch)
63
+ and OHM (https://github.com/soveran/ohm).
64
+ email:
65
+ - mauro@hashdog.com
66
+ - lguardiola@gmail.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - lib/ohm/elasticsearch.rb
77
+ - lib/ohm/elasticsearch/version.rb
78
+ - ohm-elasticsearch.gemspec
79
+ homepage: http://hashdog.io
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.2.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Very small ruby implementation for Elasticsearch and OHM.
103
+ test_files: []