elastic_searchable 0.2.2 → 0.3.0
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.
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/elastic_searchable.gemspec +6 -6
- data/lib/elastic_searchable/active_record.rb +2 -7
- data/lib/elastic_searchable/callbacks.rb +5 -2
- data/lib/elastic_searchable/index.rb +45 -22
- data/lib/elastic_searchable/queries.rb +14 -47
- data/lib/elastic_searchable.rb +28 -6
- data/test/test_elastic_searchable.rb +90 -38
- metadata +42 -42
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
gem "activerecord", "~> 2.3.5"
|
4
|
-
gem '
|
4
|
+
gem 'httparty', '~> 0.7.3'
|
5
5
|
gem 'backgrounded', '~> 0.7.0'
|
6
6
|
gem 'will_paginate', '~> 2.3.15'
|
7
7
|
gem 'larsklevan-after_commit', '~> 1.0.5', :require => 'after_commit'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/elastic_searchable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{elastic_searchable}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ryan Sonnek"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-03}
|
13
13
|
s.description = %q{integrate the elastic search engine with rails}
|
14
14
|
s.email = %q{ryan@codecrate.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
s.homepage = %q{http://github.com/wireframe/elastic_searchable}
|
37
37
|
s.licenses = ["MIT"]
|
38
38
|
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version = %q{1.
|
39
|
+
s.rubygems_version = %q{1.5.0}
|
40
40
|
s.summary = %q{elastic search for activerecord}
|
41
41
|
s.test_files = [
|
42
42
|
"test/helper.rb",
|
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
|
|
48
48
|
|
49
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
50
|
s.add_runtime_dependency(%q<activerecord>, ["~> 2.3.5"])
|
51
|
-
s.add_runtime_dependency(%q<
|
51
|
+
s.add_runtime_dependency(%q<httparty>, ["~> 0.7.3"])
|
52
52
|
s.add_runtime_dependency(%q<backgrounded>, ["~> 0.7.0"])
|
53
53
|
s.add_runtime_dependency(%q<will_paginate>, ["~> 2.3.15"])
|
54
54
|
s.add_runtime_dependency(%q<larsklevan-after_commit>, ["~> 1.0.5"])
|
@@ -60,7 +60,7 @@ Gem::Specification.new do |s|
|
|
60
60
|
s.add_development_dependency(%q<sqlite3-ruby>, ["~> 1.3.2"])
|
61
61
|
else
|
62
62
|
s.add_dependency(%q<activerecord>, ["~> 2.3.5"])
|
63
|
-
s.add_dependency(%q<
|
63
|
+
s.add_dependency(%q<httparty>, ["~> 0.7.3"])
|
64
64
|
s.add_dependency(%q<backgrounded>, ["~> 0.7.0"])
|
65
65
|
s.add_dependency(%q<will_paginate>, ["~> 2.3.15"])
|
66
66
|
s.add_dependency(%q<larsklevan-after_commit>, ["~> 1.0.5"])
|
@@ -73,7 +73,7 @@ Gem::Specification.new do |s|
|
|
73
73
|
end
|
74
74
|
else
|
75
75
|
s.add_dependency(%q<activerecord>, ["~> 2.3.5"])
|
76
|
-
s.add_dependency(%q<
|
76
|
+
s.add_dependency(%q<httparty>, ["~> 0.7.3"])
|
77
77
|
s.add_dependency(%q<backgrounded>, ["~> 0.7.0"])
|
78
78
|
s.add_dependency(%q<will_paginate>, ["~> 2.3.15"])
|
79
79
|
s.add_dependency(%q<larsklevan-after_commit>, ["~> 1.0.5"])
|
@@ -15,7 +15,7 @@ module ElasticSearchable
|
|
15
15
|
attr_accessor :elastic_options
|
16
16
|
|
17
17
|
# Valid options:
|
18
|
-
# :index (optional) configure index to store data in. default to
|
18
|
+
# :index (optional) configure index to store data in. default to ElasticSearchable.default_index
|
19
19
|
# :type (optional) configue type to store data in. default to model table name
|
20
20
|
# :index_options (optional) configure index properties (ex: tokenizer)
|
21
21
|
# :mapping (optional) configure field properties for this model (ex: skip analyzer for field)
|
@@ -24,11 +24,6 @@ module ElasticSearchable
|
|
24
24
|
# :json (optional) configure the json document to be indexed (see http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html#method-i-as_json for available options)
|
25
25
|
def elastic_searchable(options = {})
|
26
26
|
options.symbolize_keys!
|
27
|
-
options[:index] ||= self.table_name
|
28
|
-
options[:type] ||= self.table_name
|
29
|
-
options[:index_options] ||= {}
|
30
|
-
options[:mapping] ||= false
|
31
|
-
options[:json] ||= {}
|
32
27
|
self.elastic_options = options
|
33
28
|
|
34
29
|
extend ElasticSearchable::ActiveRecord::Index
|
@@ -46,7 +41,7 @@ module ElasticSearchable
|
|
46
41
|
self.as_json self.class.elastic_options[:json]
|
47
42
|
end
|
48
43
|
def index_in_elastic_search(lifecycle = nil)
|
49
|
-
ElasticSearchable.
|
44
|
+
ElasticSearchable.request :put, self.class.index_type_path(self.id), :body => self.indexed_json_document.to_json
|
50
45
|
|
51
46
|
self.run_callbacks("after_index_on_#{lifecycle}".to_sym) if lifecycle
|
52
47
|
self.run_callbacks(:after_index)
|
@@ -3,12 +3,15 @@ module ElasticSearchable
|
|
3
3
|
def self.included(base)
|
4
4
|
base.send :extend, ClassMethods
|
5
5
|
end
|
6
|
+
def self.backgrounded_options
|
7
|
+
{:queue => 'elasticsearch'}
|
8
|
+
end
|
6
9
|
|
7
10
|
module ClassMethods
|
8
11
|
def add_indexing_callbacks
|
9
|
-
backgrounded :update_index_on_create => ElasticSearchable.backgrounded_options, :update_index_on_update => ElasticSearchable.backgrounded_options
|
12
|
+
backgrounded :update_index_on_create => ElasticSearchable::Callbacks.backgrounded_options, :update_index_on_update => ElasticSearchable::Callbacks.backgrounded_options
|
10
13
|
class << self
|
11
|
-
backgrounded :delete_id_from_index => ElasticSearchable.backgrounded_options
|
14
|
+
backgrounded :delete_id_from_index => ElasticSearchable::Callbacks.backgrounded_options
|
12
15
|
end
|
13
16
|
|
14
17
|
define_callbacks :after_index_on_create, :after_index_on_update, :after_index
|
@@ -1,50 +1,73 @@
|
|
1
1
|
module ElasticSearchable
|
2
2
|
module ActiveRecord
|
3
3
|
module Index
|
4
|
-
def create_index
|
5
|
-
self.delete_index
|
6
|
-
ElasticSearchable.searcher.create_index index_name, self.elastic_options[:index_options]
|
7
|
-
if mapping = self.elastic_options[:mapping]
|
8
|
-
ElasticSearchable.searcher.update_mapping mapping, self.index_options
|
9
|
-
end
|
10
4
|
|
5
|
+
# helper method to clean out existing index and reindex all objects
|
6
|
+
def rebuild_index
|
7
|
+
self.clean_index
|
8
|
+
self.update_index_mapping
|
11
9
|
self.find_each do |record|
|
12
10
|
record.index_in_elastic_search if record.should_index?
|
13
11
|
end
|
14
12
|
self.refresh_index
|
15
13
|
end
|
14
|
+
|
15
|
+
# delete all documents of this type in the index
|
16
|
+
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/delete_mapping/
|
17
|
+
def clean_index
|
18
|
+
ElasticSearchable.request :delete, index_type_path
|
19
|
+
end
|
20
|
+
|
21
|
+
# configure the index for this type
|
22
|
+
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/put_mapping/
|
23
|
+
def update_index_mapping
|
24
|
+
if mapping = self.elastic_options[:mapping]
|
25
|
+
ElasticSearchable.request :put, index_type_path('_mapping'), :body => {index_type => mapping}.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# create the index
|
30
|
+
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/create_index/
|
31
|
+
def create_index
|
32
|
+
ElasticSearchable.request :put, index_path
|
33
|
+
end
|
34
|
+
|
16
35
|
# explicitly refresh the index, making all operations performed since the last refresh
|
17
36
|
# available for search
|
18
37
|
#
|
19
38
|
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/refresh/
|
20
39
|
def refresh_index
|
21
|
-
ElasticSearchable.
|
40
|
+
ElasticSearchable.request :post, index_path('_refresh')
|
22
41
|
end
|
23
42
|
|
24
|
-
# deletes the index
|
43
|
+
# deletes the entire index
|
44
|
+
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/delete_index/
|
25
45
|
def delete_index
|
26
|
-
|
27
|
-
ElasticSearchable.searcher.delete_index index_name
|
28
|
-
rescue ElasticSearch::RequestError
|
29
|
-
# it's ok, this means that the index doesn't exist
|
30
|
-
end
|
46
|
+
ElasticSearchable.request :delete, index_path
|
31
47
|
end
|
32
48
|
|
33
|
-
#
|
34
|
-
|
35
|
-
|
49
|
+
# delete one record from the index
|
50
|
+
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/delete/
|
51
|
+
def delete_id_from_index(id)
|
52
|
+
ElasticSearchable.request :delete, index_type_path(id)
|
36
53
|
end
|
37
54
|
|
38
|
-
#
|
39
|
-
def
|
40
|
-
|
55
|
+
# helper method to generate elasticsearch url for this object type
|
56
|
+
def index_type_path(action = nil)
|
57
|
+
index_path [index_type, action].compact.join('/')
|
58
|
+
end
|
59
|
+
|
60
|
+
# helper method to generate elasticsearch url for this index
|
61
|
+
def index_path(action = nil)
|
62
|
+
['', index_name, action].compact.join('/')
|
41
63
|
end
|
42
64
|
|
65
|
+
private
|
43
66
|
def index_name
|
44
|
-
self.elastic_options[:index]
|
67
|
+
self.elastic_options[:index] || ElasticSearchable.default_index
|
45
68
|
end
|
46
|
-
def
|
47
|
-
self.elastic_options
|
69
|
+
def index_type
|
70
|
+
self.elastic_options[:type] || self.table_name
|
48
71
|
end
|
49
72
|
end
|
50
73
|
end
|
@@ -3,59 +3,26 @@ require 'will_paginate/collection'
|
|
3
3
|
module ElasticSearchable
|
4
4
|
module Queries
|
5
5
|
# search returns a will_paginate collection of ActiveRecord objects for the search results
|
6
|
+
# options:
|
7
|
+
# :per_page/:limit
|
8
|
+
# :page/:offset
|
6
9
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# note that the collection may include nils if ElasticSearch returns a result hit for a
|
10
|
-
# record that has been deleted on the database
|
10
|
+
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/
|
11
11
|
def search(query, options = {})
|
12
|
+
page = (options.delete(:page) || 1).to_i
|
12
13
|
options[:fields] ||= '_id'
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
options[:q] ||= query
|
15
|
+
options[:size] ||= (options.delete(:per_page) || 20)
|
16
|
+
options[:from] ||= options[:size] * (page - 1)
|
17
|
+
|
18
|
+
response = ElasticSearchable.request :get, index_type_path('_search'), :query => options
|
19
|
+
hits = response['hits']
|
20
|
+
ids = hits['hits'].collect {|h| h['_id'].to_i }
|
21
|
+
results = self.find(ids).sort_by {|result| ids.index(result.id) }
|
19
22
|
|
20
|
-
page = WillPaginate::Collection.new(
|
23
|
+
page = WillPaginate::Collection.new(page, options[:size], hits['total'])
|
21
24
|
page.replace results
|
22
25
|
page
|
23
26
|
end
|
24
|
-
|
25
|
-
# counts the number of results for this query.
|
26
|
-
def search_count(query = "*", options = {})
|
27
|
-
if query.kind_of?(Hash)
|
28
|
-
query = {:query => query}
|
29
|
-
end
|
30
|
-
ElasticSearchable.searcher.count query, index_options.merge(options)
|
31
|
-
end
|
32
|
-
|
33
|
-
def facets(fields_list, options = {})
|
34
|
-
size = options.delete(:size) || 10
|
35
|
-
fields_list = [fields_list] unless fields_list.kind_of?(Array)
|
36
|
-
|
37
|
-
if !options[:query]
|
38
|
-
options[:query] = {:match_all => true}
|
39
|
-
elsif options[:query].kind_of?(String)
|
40
|
-
options[:query] = {:query_string => {:query => options[:query]}}
|
41
|
-
end
|
42
|
-
|
43
|
-
options[:facets] = {}
|
44
|
-
fields_list.each do |field|
|
45
|
-
options[:facets][field] = {:terms => {:field => field, :size => size}}
|
46
|
-
end
|
47
|
-
|
48
|
-
hits = ElasticSearchable.searcher.search options, index_options.merge(options)
|
49
|
-
out = {}
|
50
|
-
|
51
|
-
fields_list.each do |field|
|
52
|
-
out[field.to_sym] = {}
|
53
|
-
hits.facets[field.to_s]["terms"].each do |term|
|
54
|
-
out[field.to_sym][term["term"]] = term["count"]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
out
|
59
|
-
end
|
60
27
|
end
|
61
28
|
end
|
data/lib/elastic_searchable.rb
CHANGED
@@ -1,14 +1,36 @@
|
|
1
|
-
require '
|
1
|
+
require 'httparty'
|
2
2
|
require 'elastic_searchable/active_record'
|
3
3
|
|
4
4
|
module ElasticSearchable
|
5
|
+
include HTTParty
|
6
|
+
format :json
|
7
|
+
base_uri 'localhost:9200'
|
8
|
+
#debug_output
|
9
|
+
|
10
|
+
class ElasticError < StandardError; end
|
5
11
|
class << self
|
6
|
-
|
7
|
-
|
8
|
-
|
12
|
+
# setup the default index to use
|
13
|
+
# one index can hold many object 'types'
|
14
|
+
@@default_index = nil
|
15
|
+
def default_index=(index)
|
16
|
+
@@default_index = index
|
17
|
+
end
|
18
|
+
def default_index
|
19
|
+
@@default_index || 'elastic_searchable'
|
9
20
|
end
|
10
|
-
|
11
|
-
|
21
|
+
|
22
|
+
#perform a request to the elasticsearch server
|
23
|
+
def request(method, url, options = {})
|
24
|
+
response = self.send(method, url, options)
|
25
|
+
puts "elasticsearch request: #{method} #{url} #{" finished in #{response['took']}ms" if response['took']}"
|
26
|
+
assert_ok_response response
|
27
|
+
response
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def assert_ok_response(response)
|
32
|
+
error = response['error'] || "Error executing request: #{response.inspect}"
|
33
|
+
raise ElasticSearchable::ElasticError.new(error) if response['error'] || !response.success?
|
12
34
|
end
|
13
35
|
end
|
14
36
|
end
|
@@ -55,7 +55,6 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
55
55
|
@indexed_on_create
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
59
58
|
context 'Post class with default elastic_searchable config' do
|
60
59
|
setup do
|
61
60
|
@clazz = Post
|
@@ -66,26 +65,31 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
66
65
|
should 'define elastic_options' do
|
67
66
|
assert @clazz.elastic_options
|
68
67
|
end
|
69
|
-
should 'define index_name' do
|
70
|
-
assert_equal 'posts', @clazz.index_name
|
71
|
-
end
|
72
68
|
end
|
73
69
|
|
74
|
-
context '
|
70
|
+
context 'with empty index' do
|
75
71
|
setup do
|
76
|
-
|
77
|
-
|
72
|
+
begin
|
73
|
+
ElasticSearchable.delete '/elastic_searchable'
|
74
|
+
rescue ElasticSearchable::ElasticError
|
75
|
+
#already deleted
|
76
|
+
end
|
78
77
|
end
|
79
|
-
|
80
|
-
|
78
|
+
|
79
|
+
context 'Post.create_index' do
|
80
|
+
setup do
|
81
|
+
Post.create_index
|
82
|
+
@status = ElasticSearchable.request :get, '/elastic_searchable/_status'
|
83
|
+
end
|
84
|
+
should 'have created index' do
|
85
|
+
assert @status['ok']
|
86
|
+
end
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
84
|
-
context '
|
90
|
+
context 'Post.create' do
|
85
91
|
setup do
|
86
|
-
Post.delete_all
|
87
92
|
@post = Post.create :title => 'foo', :body => "bar"
|
88
|
-
Post.create_index
|
89
93
|
end
|
90
94
|
should 'have fired after_index callback' do
|
91
95
|
assert @post.indexed?
|
@@ -93,31 +97,69 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
93
97
|
should 'have fired after_index_on_create callback' do
|
94
98
|
assert @post.indexed_on_create?
|
95
99
|
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with index containing multiple results' do
|
103
|
+
setup do
|
104
|
+
Post.delete_all
|
105
|
+
@first_post = Post.create :title => 'foo', :body => "first bar"
|
106
|
+
@second_post = Post.create :title => 'foo', :body => "second bar"
|
107
|
+
Post.rebuild_index
|
108
|
+
Post.refresh_index
|
109
|
+
end
|
96
110
|
|
97
111
|
context 'searching for results' do
|
98
112
|
setup do
|
99
|
-
@results = Post.search '
|
113
|
+
@results = Post.search 'first'
|
100
114
|
end
|
101
115
|
should 'find created object' do
|
102
|
-
assert_equal @
|
116
|
+
assert_equal @first_post, @results.first
|
117
|
+
end
|
118
|
+
should 'be paginated' do
|
119
|
+
assert_equal 1, @results.current_page
|
120
|
+
assert_equal 20, @results.per_page
|
121
|
+
assert_nil @results.previous_page
|
122
|
+
assert_nil @results.next_page
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'searching for second page using will_paginate params' do
|
127
|
+
setup do
|
128
|
+
@results = Post.search 'foo', :page => 2, :per_page => 1, :sort => 'id'
|
129
|
+
end
|
130
|
+
should 'find object' do
|
131
|
+
assert_equal @second_post, @results.first
|
103
132
|
end
|
104
133
|
should 'be paginated' do
|
105
|
-
assert_equal
|
134
|
+
assert_equal 2, @results.current_page
|
135
|
+
assert_equal 1, @results.per_page
|
136
|
+
assert_equal 1, @results.previous_page
|
137
|
+
assert_nil @results.next_page
|
106
138
|
end
|
107
139
|
end
|
108
140
|
|
109
141
|
context 'sorting search results' do
|
110
142
|
setup do
|
111
|
-
@
|
112
|
-
Post.create_index
|
113
|
-
@results = Post.search 'foo', :sort => 'id:reverse'
|
143
|
+
@results = Post.search 'foo', :sort => 'id:desc'
|
114
144
|
end
|
115
145
|
should 'sort results correctly' do
|
116
146
|
assert_equal @second_post, @results.first
|
117
147
|
end
|
118
148
|
end
|
149
|
+
|
150
|
+
context 'destroying one object' do
|
151
|
+
setup do
|
152
|
+
@first_post.destroy
|
153
|
+
Post.refresh_index
|
154
|
+
end
|
155
|
+
should 'be removed from the index' do
|
156
|
+
@request = ElasticSearchable.get "/elastic_searchable/posts/#{@first_post.id}"
|
157
|
+
assert @request.not_found?, @request.inspect
|
158
|
+
end
|
159
|
+
end
|
119
160
|
end
|
120
161
|
|
162
|
+
|
121
163
|
class Blog < ActiveRecord::Base
|
122
164
|
elastic_searchable :if => proc {|b| b.should_index? }
|
123
165
|
def should_index?
|
@@ -128,19 +170,17 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
128
170
|
context 'when creating new instance' do
|
129
171
|
setup do
|
130
172
|
Blog.any_instance.expects(:index_in_elastic_search).never
|
131
|
-
Blog.delete_all
|
132
|
-
Blog.create_index
|
133
173
|
Blog.create! :title => 'foo'
|
134
174
|
end
|
135
175
|
should 'not index record' do end #see expectations
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
should 'not index record' do end #see expectations
|
176
|
+
end
|
177
|
+
context 'rebuilding new index' do
|
178
|
+
setup do
|
179
|
+
Blog.any_instance.expects(:index_in_elastic_search).never
|
180
|
+
Blog.create! :title => 'foo'
|
181
|
+
Blog.rebuild_index
|
143
182
|
end
|
183
|
+
should 'not index record' do end #see expectations
|
144
184
|
end
|
145
185
|
end
|
146
186
|
|
@@ -150,20 +190,18 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
150
190
|
context 'activerecord class with :mapping=>{}' do
|
151
191
|
context 'creating index' do
|
152
192
|
setup do
|
153
|
-
User.
|
154
|
-
@status = ElasticSearchable.
|
193
|
+
User.update_index_mapping
|
194
|
+
@status = ElasticSearchable.request :get, '/elastic_searchable/users/_mapping'
|
155
195
|
end
|
156
196
|
should 'have set mapping' do
|
157
197
|
expected = {
|
158
198
|
"users"=> {
|
159
|
-
"
|
160
|
-
"
|
161
|
-
"name"=> {"type"=>"string", "index"=>"not_analyzed"}
|
162
|
-
}
|
199
|
+
"properties"=> {
|
200
|
+
"name"=> {"type"=>"string", "index"=>"not_analyzed"}
|
163
201
|
}
|
164
202
|
}
|
165
203
|
}
|
166
|
-
assert_equal expected, @status
|
204
|
+
assert_equal expected, @status['elastic_searchable'], @status.inspect
|
167
205
|
end
|
168
206
|
end
|
169
207
|
end
|
@@ -176,13 +214,27 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
176
214
|
setup do
|
177
215
|
Friend.delete_all
|
178
216
|
@friend = Friend.create! :name => 'bob', :favorite_color => 'red'
|
179
|
-
Friend.
|
217
|
+
Friend.rebuild_index
|
180
218
|
end
|
181
219
|
should 'index json with configuration' do
|
182
|
-
@response = ElasticSearchable.
|
183
|
-
|
184
|
-
|
220
|
+
@response = ElasticSearchable.request :get, "/friends/friends/#{@friend.id}"
|
221
|
+
expected = {
|
222
|
+
"name" => 'bob' #favorite_color should not be indexed
|
223
|
+
}
|
224
|
+
assert_equal expected, @response['_source'], @response.inspect
|
185
225
|
end
|
186
226
|
end
|
187
227
|
end
|
228
|
+
|
229
|
+
context 'updating ElasticSearchable.default_index' do
|
230
|
+
setup do
|
231
|
+
ElasticSearchable.default_index = 'my_new_index'
|
232
|
+
end
|
233
|
+
teardown do
|
234
|
+
ElasticSearchable.default_index = nil
|
235
|
+
end
|
236
|
+
should 'change default index' do
|
237
|
+
assert_equal 'my_new_index', ElasticSearchable.default_index
|
238
|
+
end
|
239
|
+
end
|
188
240
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Sonnek
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-03 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
name: activerecord
|
23
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
@@ -31,27 +31,27 @@ dependencies:
|
|
31
31
|
- 3
|
32
32
|
- 5
|
33
33
|
version: 2.3.5
|
34
|
-
requirement: *id001
|
35
34
|
prerelease: false
|
36
|
-
name: activerecord
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
35
|
type: :runtime
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: httparty
|
39
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
44
|
+
hash: 5
|
45
45
|
segments:
|
46
46
|
- 0
|
47
|
-
-
|
48
|
-
-
|
49
|
-
version: 0.
|
50
|
-
requirement: *id002
|
47
|
+
- 7
|
48
|
+
- 3
|
49
|
+
version: 0.7.3
|
51
50
|
prerelease: false
|
52
|
-
name: rubberband
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
51
|
type: :runtime
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: backgrounded
|
55
55
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
56
|
none: false
|
57
57
|
requirements:
|
@@ -63,11 +63,11 @@ dependencies:
|
|
63
63
|
- 7
|
64
64
|
- 0
|
65
65
|
version: 0.7.0
|
66
|
-
requirement: *id003
|
67
66
|
prerelease: false
|
68
|
-
name: backgrounded
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
67
|
type: :runtime
|
68
|
+
requirement: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: will_paginate
|
71
71
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
@@ -79,11 +79,11 @@ dependencies:
|
|
79
79
|
- 3
|
80
80
|
- 15
|
81
81
|
version: 2.3.15
|
82
|
-
requirement: *id004
|
83
82
|
prerelease: false
|
84
|
-
name: will_paginate
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
83
|
type: :runtime
|
84
|
+
requirement: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: larsklevan-after_commit
|
87
87
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
@@ -95,11 +95,11 @@ dependencies:
|
|
95
95
|
- 0
|
96
96
|
- 5
|
97
97
|
version: 1.0.5
|
98
|
-
requirement: *id005
|
99
98
|
prerelease: false
|
100
|
-
|
99
|
+
type: :runtime
|
100
|
+
requirement: *id005
|
101
101
|
- !ruby/object:Gem::Dependency
|
102
|
-
|
102
|
+
name: shoulda
|
103
103
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
104
104
|
none: false
|
105
105
|
requirements:
|
@@ -109,11 +109,11 @@ dependencies:
|
|
109
109
|
segments:
|
110
110
|
- 0
|
111
111
|
version: "0"
|
112
|
-
requirement: *id006
|
113
112
|
prerelease: false
|
114
|
-
name: shoulda
|
115
|
-
- !ruby/object:Gem::Dependency
|
116
113
|
type: :development
|
114
|
+
requirement: *id006
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: bundler
|
117
117
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
119
|
requirements:
|
@@ -125,11 +125,11 @@ dependencies:
|
|
125
125
|
- 0
|
126
126
|
- 0
|
127
127
|
version: 1.0.0
|
128
|
-
requirement: *id007
|
129
128
|
prerelease: false
|
130
|
-
name: bundler
|
131
|
-
- !ruby/object:Gem::Dependency
|
132
129
|
type: :development
|
130
|
+
requirement: *id007
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: mocha
|
133
133
|
version_requirements: &id008 !ruby/object:Gem::Requirement
|
134
134
|
none: false
|
135
135
|
requirements:
|
@@ -139,11 +139,11 @@ dependencies:
|
|
139
139
|
segments:
|
140
140
|
- 0
|
141
141
|
version: "0"
|
142
|
-
requirement: *id008
|
143
142
|
prerelease: false
|
144
|
-
name: mocha
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
143
|
type: :development
|
144
|
+
requirement: *id008
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: jeweler
|
147
147
|
version_requirements: &id009 !ruby/object:Gem::Requirement
|
148
148
|
none: false
|
149
149
|
requirements:
|
@@ -155,11 +155,11 @@ dependencies:
|
|
155
155
|
- 5
|
156
156
|
- 2
|
157
157
|
version: 1.5.2
|
158
|
-
requirement: *id009
|
159
158
|
prerelease: false
|
160
|
-
name: jeweler
|
161
|
-
- !ruby/object:Gem::Dependency
|
162
159
|
type: :development
|
160
|
+
requirement: *id009
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
name: rcov
|
163
163
|
version_requirements: &id010 !ruby/object:Gem::Requirement
|
164
164
|
none: false
|
165
165
|
requirements:
|
@@ -169,11 +169,11 @@ dependencies:
|
|
169
169
|
segments:
|
170
170
|
- 0
|
171
171
|
version: "0"
|
172
|
-
requirement: *id010
|
173
172
|
prerelease: false
|
174
|
-
name: rcov
|
175
|
-
- !ruby/object:Gem::Dependency
|
176
173
|
type: :development
|
174
|
+
requirement: *id010
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: sqlite3-ruby
|
177
177
|
version_requirements: &id011 !ruby/object:Gem::Requirement
|
178
178
|
none: false
|
179
179
|
requirements:
|
@@ -185,9 +185,9 @@ dependencies:
|
|
185
185
|
- 3
|
186
186
|
- 2
|
187
187
|
version: 1.3.2
|
188
|
-
requirement: *id011
|
189
188
|
prerelease: false
|
190
|
-
|
189
|
+
type: :development
|
190
|
+
requirement: *id011
|
191
191
|
description: integrate the elastic search engine with rails
|
192
192
|
email: ryan@codecrate.com
|
193
193
|
executables: []
|
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
243
|
requirements: []
|
244
244
|
|
245
245
|
rubyforge_project:
|
246
|
-
rubygems_version: 1.
|
246
|
+
rubygems_version: 1.5.0
|
247
247
|
signing_key:
|
248
248
|
specification_version: 3
|
249
249
|
summary: elastic search for activerecord
|