elastic_searchable 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -7
- data/lib/elastic_searchable/index.rb +6 -5
- data/lib/elastic_searchable/version.rb +1 -1
- data/test/setup_database.rb +1 -0
- data/test/test_elastic_searchable.rb +25 -23
- metadata +5 -7
data/README.rdoc
CHANGED
@@ -27,15 +27,12 @@ Integrate the elasticsearch library into Rails.
|
|
27
27
|
#defaults to localhost:9200
|
28
28
|
ElasticSearchable.base_uri = 'server:9200'
|
29
29
|
|
30
|
-
== Contributing
|
30
|
+
== Contributing
|
31
31
|
|
32
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
33
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
34
32
|
* Fork the project
|
35
|
-
*
|
36
|
-
*
|
37
|
-
*
|
38
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
33
|
+
* Fix the issue
|
34
|
+
* Add unit tests
|
35
|
+
* Submit pull request on github
|
39
36
|
|
40
37
|
== Copyright
|
41
38
|
|
@@ -18,11 +18,12 @@ module ElasticSearchable
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# create the index
|
21
|
-
# http://www.elasticsearch.
|
21
|
+
# http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html
|
22
22
|
def create_index
|
23
|
-
options =
|
24
|
-
|
25
|
-
self.
|
23
|
+
options = {}
|
24
|
+
options.merge! :settings => self.elastic_options[:index_options] if self.elastic_options[:index_options]
|
25
|
+
options.merge! :mappings => {index_type => self.elastic_options[:mapping]} if self.elastic_options[:mapping]
|
26
|
+
ElasticSearchable.request :put, index_path, :body => options.to_json
|
26
27
|
end
|
27
28
|
|
28
29
|
# explicitly refresh the index, making all operations performed since the last refresh
|
@@ -68,7 +69,7 @@ module ElasticSearchable
|
|
68
69
|
|
69
70
|
records = scope.paginate(options)
|
70
71
|
while records.any? do
|
71
|
-
ElasticSearchable.logger.
|
72
|
+
ElasticSearchable.logger.debug "reindexing batch ##{records.current_page}..."
|
72
73
|
|
73
74
|
actions = []
|
74
75
|
records.each do |record|
|
data/test/setup_database.rb
CHANGED
@@ -4,11 +4,10 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
delete_index
|
6
6
|
end
|
7
|
-
|
8
|
-
|
9
|
-
end
|
7
|
+
ElasticSearchable.debug_output
|
8
|
+
|
10
9
|
class Post < ActiveRecord::Base
|
11
|
-
elastic_searchable
|
10
|
+
elastic_searchable
|
12
11
|
after_index :indexed
|
13
12
|
after_index_on_create :indexed_on_create
|
14
13
|
def indexed
|
@@ -24,7 +23,7 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
24
23
|
@indexed_on_create
|
25
24
|
end
|
26
25
|
end
|
27
|
-
context '
|
26
|
+
context 'activerecord class with default elastic_searchable config' do
|
28
27
|
setup do
|
29
28
|
@clazz = Post
|
30
29
|
end
|
@@ -36,7 +35,7 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
context '
|
38
|
+
context 'Model.request with invalid url' do
|
40
39
|
should 'raise error' do
|
41
40
|
assert_raises ElasticSearchable::ElasticError do
|
42
41
|
ElasticSearchable.request :get, '/elastic_searchable/foobar/notfound'
|
@@ -44,25 +43,15 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
context '
|
46
|
+
context 'Model.create_index' do
|
48
47
|
setup do
|
49
48
|
Post.create_index
|
49
|
+
Post.refresh_index
|
50
50
|
@status = ElasticSearchable.request :get, '/elastic_searchable/_status'
|
51
51
|
end
|
52
52
|
should 'have created index' do
|
53
53
|
assert @status['ok']
|
54
54
|
end
|
55
|
-
should 'have used custom index_options' do
|
56
|
-
expected = {
|
57
|
-
"index.number_of_replicas" => "1",
|
58
|
-
"index.number_of_shards" => "5",
|
59
|
-
"index.analysis.analyzer.default.tokenizer" => "standard",
|
60
|
-
"index.analysis.analyzer.default.filter.0" => "standard",
|
61
|
-
"index.analysis.analyzer.default.filter.1" => "lowercase",
|
62
|
-
"index.analysis.analyzer.default.filter.2" => "porterStem"
|
63
|
-
}
|
64
|
-
assert_equal expected, @status['indices']['elastic_searchable']['settings'], @status.inspect
|
65
|
-
end
|
66
55
|
end
|
67
56
|
|
68
57
|
context 'deleting object that does not exist in search index' do
|
@@ -73,7 +62,7 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
73
62
|
end
|
74
63
|
end
|
75
64
|
|
76
|
-
context '
|
65
|
+
context 'Model.create' do
|
77
66
|
setup do
|
78
67
|
@post = Post.create :title => 'foo', :body => "bar"
|
79
68
|
end
|
@@ -96,7 +85,7 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
96
85
|
ElasticSearchable.expects(:request).raises(ElasticSearchable::ElasticError.new('faux error'))
|
97
86
|
Post.reindex
|
98
87
|
end
|
99
|
-
context '
|
88
|
+
context 'Model.reindex' do
|
100
89
|
setup do
|
101
90
|
Post.reindex :per_page => 1, :scope => Post.scoped(:order => 'body desc')
|
102
91
|
Post.refresh_index
|
@@ -195,15 +184,28 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
195
184
|
end
|
196
185
|
|
197
186
|
class User < ActiveRecord::Base
|
198
|
-
elastic_searchable :
|
187
|
+
elastic_searchable :index_options => { "analysis.analyzer.default.tokenizer" => 'standard', "analysis.analyzer.default.filter" => ["standard", "lowercase", 'porterStem'] },
|
188
|
+
:mapping => {:properties => {:name => {:type => :string, :index => :not_analyzed}}}
|
199
189
|
end
|
200
|
-
context 'activerecord class with :mapping
|
190
|
+
context 'activerecord class with :index_options and :mapping' do
|
201
191
|
context 'creating index' do
|
202
192
|
setup do
|
203
193
|
User.create_index
|
204
|
-
|
194
|
+
end
|
195
|
+
should 'have used custom index_options' do
|
196
|
+
@status = ElasticSearchable.request :get, '/elastic_searchable/_status'
|
197
|
+
expected = {
|
198
|
+
"index.number_of_replicas" => "1",
|
199
|
+
"index.number_of_shards" => "5",
|
200
|
+
"index.analysis.analyzer.default.tokenizer" => "standard",
|
201
|
+
"index.analysis.analyzer.default.filter.0" => "standard",
|
202
|
+
"index.analysis.analyzer.default.filter.1" => "lowercase",
|
203
|
+
"index.analysis.analyzer.default.filter.2" => "porterStem"
|
204
|
+
}
|
205
|
+
assert_equal expected, @status['indices']['elastic_searchable']['settings'], @status.inspect
|
205
206
|
end
|
206
207
|
should 'have set mapping' do
|
208
|
+
@status = ElasticSearchable.request :get, '/elastic_searchable/users/_mapping'
|
207
209
|
expected = {
|
208
210
|
"users"=> {
|
209
211
|
"properties"=> {
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_searchable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 6
|
10
|
+
version: 0.6.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Sonnek
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-04-11 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: activerecord
|
@@ -200,7 +199,6 @@ files:
|
|
200
199
|
- test/helper.rb
|
201
200
|
- test/setup_database.rb
|
202
201
|
- test/test_elastic_searchable.rb
|
203
|
-
has_rdoc: true
|
204
202
|
homepage: http://github.com/wireframe/elastic_searchable
|
205
203
|
licenses: []
|
206
204
|
|
@@ -230,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
228
|
requirements: []
|
231
229
|
|
232
230
|
rubyforge_project: elastic_searchable
|
233
|
-
rubygems_version: 1.
|
231
|
+
rubygems_version: 1.7.2
|
234
232
|
signing_key:
|
235
233
|
specification_version: 3
|
236
234
|
summary: elastic search for activerecord
|