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 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 to elastic_searchable
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
- * Start a feature/bugfix branch
36
- * Commit and push until you are happy with your contribution
37
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
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.com/docs/elasticsearch/rest_api/admin/indices/create_index/
21
+ # http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html
22
22
  def create_index
23
- options = self.elastic_options[:index_options] ? self.elastic_options[:index_options].to_json : ''
24
- ElasticSearchable.request :put, index_path, :body => options
25
- self.update_index_mapping
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.info "reindexing batch ##{records.current_page}..."
72
+ ElasticSearchable.logger.debug "reindexing batch ##{records.current_page}..."
72
73
 
73
74
  actions = []
74
75
  records.each do |record|
@@ -1,4 +1,4 @@
1
1
  module ElasticSearchable
2
- VERSION = '0.6.5'
2
+ VERSION = '0.6.6'
3
3
  end
4
4
 
@@ -6,6 +6,7 @@ ActiveRecord::Schema.define(:version => 1) do
6
6
  create_table :posts, :force => true do |t|
7
7
  t.column :title, :string
8
8
  t.column :body, :string
9
+ t.column :name, :string
9
10
  end
10
11
  create_table :blogs, :force => true do |t|
11
12
  t.column :title, :string
@@ -4,11 +4,10 @@ class TestElasticSearchable < Test::Unit::TestCase
4
4
  def setup
5
5
  delete_index
6
6
  end
7
- def teardown
8
- delete_index
9
- end
7
+ ElasticSearchable.debug_output
8
+
10
9
  class Post < ActiveRecord::Base
11
- elastic_searchable :index_options => { "analysis.analyzer.default.tokenizer" => 'standard', "analysis.analyzer.default.filter" => ["standard", "lowercase", 'porterStem'] }
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 'Post class with default elastic_searchable config' do
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 'ElasticSearchable.request with invalid url' do
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 'Post.create_index' do
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 'Post.create' do
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 'Post.reindex' do
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 :mapping => {:properties => {:name => {:type => :string, :index => :not_analyzed}}}
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=>{}' do
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
- @status = ElasticSearchable.request :get, '/elastic_searchable/users/_mapping'
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: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 5
10
- version: 0.6.5
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-01 00:00:00 -05:00
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.6.2
231
+ rubygems_version: 1.7.2
234
232
  signing_key:
235
233
  specification_version: 3
236
234
  summary: elastic search for activerecord