elastico 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWExODkwZTBhMGI1Y2RiYmY0YzlhNWRlOTExODZjODFmZGY5OTgwMA==
5
+ data.tar.gz: !binary |-
6
+ OTNjMWE2NGM4ZGU5YWI1MGQ2NDlkZDJjMWFjNmYxNWQ4YTkwZjZkOQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NGVlZDQzZjMwZDdkNmRhNDBmMjBhYjBhMzM3ZDlmMjI5ZTMwNjAxZTgxZWI4
10
+ OTlhYWY1NzFkYzg4MDkyOGY4OGM0MjQ2YWEyOWZkY2ZiNWFjMWM5MGJiNGJh
11
+ Y2ZiY2Q1NmY2ZjQwNmQxNzdmMjQzYTc0MzA5Mjc5ZDMxZjYxZjQ=
12
+ data.tar.gz: !binary |-
13
+ ODU3MWMxYmJkMDM2NmMzYjcwMGZhYmQxYWM2OTNiNWQ1NzIwNmQ5NTYyYWIx
14
+ OWI5M2U1YjNhMDVhOWY4ZWQxYWRkM2ZkY2I2ZWVjYzRmZjI0NGJmZjQ1YzRk
15
+ NDdiZWNmMmFmMzlkNzdiYzJjNWY2ZDFjMmRiZTZkZDExNTE5NWQ=
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
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
+ lib/elastico/nothing
19
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in elastico.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ elastico (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.1.0)
10
+ spawnling (2.1.1)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ elastico!
17
+ rake
18
+ spawnling (~> 2.1.1)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Eyal-Mac
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.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Elastico
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'elastico'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install elastico
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
31
+
32
+ Usage:
33
+ ======
34
+
35
+ 1. Setup (define the mapping and settings)
36
+ 2. Index current data (Rake task)
37
+ 3. Search (define how to search, what to search)
38
+ 4. Callbacks (automatically added)
39
+
40
+
41
+ class Someclass < ActiveRecord::Base
42
+ Elastico::Setup = { } (How to index)
43
+ Elastico::Search = {} (What to search)
44
+ Elastico:Index = {} (What to index)
45
+ end
46
+
47
+
48
+ Setup
49
+ =====
50
+ You should give a hash that looks something like that:
51
+ settings_json[:settings] = {
52
+ :settings => {
53
+ :number_of_shards => 2,
54
+ :number_of_replicas => 0,
55
+ :analysis => {
56
+ :filter => {
57
+ :my_ngram => {
58
+ "type" => "nGram",
59
+ "max_gram" => 15,
60
+ "min_gram" => 1
61
+ },
62
+ :my_stemmer => {
63
+ "type" => "stemmer",
64
+ "name" => "english"
65
+ }
66
+ },
67
+ :analyzer => {
68
+ :ngram_analyzer => {
69
+ "tokenizer" => "whitespace",
70
+ "filter" => ["stop", "my_ngram", "lowercase"],
71
+ "type" => "custom"
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+ a
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib/elastico'
8
+ t.test_files = FileList['test/lib/elastico/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
13
+
14
+ task :build do
15
+ system "gem build elastico.gemspec"
16
+ end
17
+
18
+ task :release => :build do
19
+ system "gem push elastico-#{Elastico::VERSION}"
20
+ end
data/elastico.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'elastico/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "elastico"
8
+ gem.version = Elastico::VERSION
9
+ gem.authors = ["Eyal Goren"]
10
+ gem.email = ["gneyal@gmail.com"]
11
+ gem.description = %q{A general way to use elasticsearch}
12
+ gem.summary = %q{Elastico is a simple alternative to work with elasticsearch}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency "spawnling", "~> 2.1.1"
22
+ end
@@ -0,0 +1,37 @@
1
+ module Elastico
2
+ module Callback
3
+ def self.included(base)
4
+ update_conditions = lambda { update_index_with_instance }
5
+
6
+ base.send :after_save, update_conditions
7
+ base.send :after_destroy, update_conditions
8
+ base.send :after_touch, update_conditions
9
+ end
10
+ end
11
+ end
12
+
13
+
14
+
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
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ module Elastico
2
+ module Client
3
+ def send_settings_mappings_to_elasticsearch_server
4
+ to_url = self.elastico_url + self.elastico_index_name
5
+ puts to_url
6
+ RestClient.put(to_url, self.settings_and_mappings_json, :content_type => :json, :accept => :json) do |response, request, result|
7
+ puts JSON.pretty_generate(JSON.parse(response.to_str))
8
+ end
9
+ end
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))
14
+ end
15
+ response
16
+ end
17
+
18
+ def elastico_search(hash_respond_wanted = true)
19
+ to_url = self.elastico_url + self.elastico_index_name + "/_search"
20
+ response = ""
21
+ RestClient.get(to_url, JSON.parse(self.search_query)) do |response, request, result|
22
+ ret = JSON.pretty_generate(JSON.parse(response.to_str))
23
+ hash_respond_wanted ? JSON.parse(ret) : ret
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Elastico
2
+ module Configuration
3
+ def elastico_url
4
+ @url || "http://localhost:9200/"
5
+ end
6
+
7
+ def elastico_url= url
8
+ @url = url
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module Elastico
2
+ module Index
3
+ def settings_and_mappings_json
4
+ @settings_and_mappings_json || nil
5
+ end
6
+
7
+ def settings_and_mappings_json= json
8
+ @settings_and_mappings_json = json
9
+ end
10
+
11
+ def elastico_index_name
12
+ (@index_name || self.name.gsub(/::/, "_").pluralize).downcase
13
+ end
14
+
15
+ def elastico_index_name= index_name
16
+ @index_name = index_name
17
+ end
18
+
19
+ def elastico_type_name
20
+ (@type_name || self.name.gsub(/::/, "_")).downcase
21
+ end
22
+
23
+ def elastico_type_name= type_name
24
+ @type_name = type_name
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module Elastico
2
+ module Search
3
+ def search_query
4
+ @search_query || nil
5
+ end
6
+
7
+ def search_query= json
8
+ @search_query = json
9
+ end
10
+
11
+ def raise_exception
12
+ raise 'An error has occured'
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Elastico
2
+ VERSION = "0.0.1"
3
+ end
data/lib/elastico.rb ADDED
@@ -0,0 +1,18 @@
1
+ require_relative "./elastico/configuration"
2
+ require_relative "./elastico/version"
3
+ require_relative "./elastico/index"
4
+ require_relative "./elastico/search"
5
+ require_relative "./elastico/client"
6
+
7
+
8
+ 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
+ def self.included(base)
13
+ base.extend Configuration
14
+ base.extend Index
15
+ base.extend Search
16
+ base.extend Client
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Elastico::Client do
4
+
5
+ describe "General" do
6
+ it "should assemble the settings and mapping message" do
7
+ ThisClass.must_respond_to :elastico_url
8
+ ThisClass.must_respond_to :general_request
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Elastico::Configuration do
4
+
5
+ describe "General" do
6
+ it "must respond to url" do
7
+ ThisClass.must_respond_to(:elastico_url)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Elastico::Index do
4
+
5
+ describe "reading from file" do
6
+
7
+ it "must respond to these class methods" do
8
+ ThisClass.must_respond_to(:settings_and_mappings_json)
9
+ ThisClass.must_respond_to(:elastico_index_name)
10
+ ThisClass.must_respond_to(:elastico_type_name)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Elastico::Search do
4
+
5
+ describe "Search" do
6
+
7
+ it "must respond to these class methods" do
8
+ ThisClass.must_respond_to(:search_query)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Elastico do
4
+
5
+ it "must be defined" do
6
+ Elastico::VERSION.wont_be_nil
7
+ end
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require File.expand_path('../../lib/elastico.rb', __FILE__)
4
+
5
+ class ThisClass
6
+ include Elastico
7
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elastico
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eyal Goren
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: spawnling
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.1
41
+ description: A general way to use elasticsearch
42
+ email:
43
+ - gneyal@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - elastico.gemspec
55
+ - lib/elastico.rb
56
+ - lib/elastico/callbacks.rb
57
+ - lib/elastico/client.rb
58
+ - lib/elastico/configuration.rb
59
+ - lib/elastico/index.rb
60
+ - lib/elastico/search.rb
61
+ - lib/elastico/version.rb
62
+ - test/lib/elastico/client_test.rb
63
+ - test/lib/elastico/configuration_test.rb
64
+ - test/lib/elastico/index_test.rb
65
+ - test/lib/elastico/search_test.rb
66
+ - test/lib/elastico/version_test.rb
67
+ - test/test_helper.rb
68
+ homepage: ''
69
+ licenses: []
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.0.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Elastico is a simple alternative to work with elasticsearch
91
+ test_files:
92
+ - test/lib/elastico/client_test.rb
93
+ - test/lib/elastico/configuration_test.rb
94
+ - test/lib/elastico/index_test.rb
95
+ - test/lib/elastico/search_test.rb
96
+ - test/lib/elastico/version_test.rb
97
+ - test/test_helper.rb