estella 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf61c93e5566773e32ae933239e245236cce24e3
4
- data.tar.gz: c3d455dacea867bd1e53d325120991ff59cc0979
3
+ metadata.gz: bfebaabb0c030f132e17e046fcfea05c28d2fa9d
4
+ data.tar.gz: 9dbe818723ccfa698c3ad7e6f2775aaef20ec26e
5
5
  SHA512:
6
- metadata.gz: 56bb154fc881a5670a089247dbb4d83134cbbb9303707835a3138ae987d13385e3598c2b7841ce912e635d5177885cda1441e321db7854cfcc0df87765ee90ea
7
- data.tar.gz: 4b6ad124cba5f0a4bfd777de3afcf81c6d17af16796ff160825b190a26359942450e1b657ef9024206e3e5c4831c378100355f0a3cfe5e0c2425d8816d1442f0
6
+ metadata.gz: 3ddf9ea6b35d7e9e3a7a9b2f35c908a3ff3d02b65410fd4a7fad89adbf376946c99930126c78e8a6884c67793cca77018d22b7a9e59742ad80600de576ef4ebd
7
+ data.tar.gz: 5ff181eaed10c332c34fa21aafc78e415269515c5d0eaf7dfec77eecfe15079d6c0463ae9627f5253443b783abad53170c07be3fe8e888aaac70f71f05b76c34
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  Gemfile.lock
2
+ pkg
3
+ coverage
data/.rubocop_todo.yml CHANGED
@@ -1,25 +1,25 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-01-24 13:49:04 -0500 using RuboCop version 0.47.1.
3
+ # on 2017-01-25 11:50:14 -0500 using RuboCop version 0.47.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 3
9
+ # Offense count: 2
10
10
  Metrics/AbcSize:
11
11
  Max: 24
12
12
 
13
13
  # Offense count: 3
14
14
  # Configuration parameters: CountComments, ExcludedMethods.
15
15
  Metrics/BlockLength:
16
- Max: 94
16
+ Max: 117
17
17
 
18
- # Offense count: 26
18
+ # Offense count: 28
19
19
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
20
20
  # URISchemes: http, https
21
21
  Metrics/LineLength:
22
- Max: 131
22
+ Max: 135
23
23
 
24
24
  # Offense count: 1
25
25
  # Configuration parameters: CountComments.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.2.2 (Next)
4
+
5
+ * [#15](https://github.com/artsy/estella/pull/15): Removed undocumented `set_index_alias!` - [@dblock](https://github.com/dblock).
6
+ * [#15](https://github.com/artsy/estella/pull/15): Added `delete_index!` and `create_index!` - [@dblock](https://github.com/dblock).
7
+ * [#14](https://github.com/artsy/estella/pull/14): Fix: destroying documents fails to remove them from the index - [@dblock](https://github.com/dblock).
8
+ * [#13](https://github.com/artsy/estella/pull/13): Added code coverage w/ Coveralls - [@dblock](https://github.com/dblock).
9
+ * Your contribution here.
10
+
3
11
  ### 0.2.1 (1/24/2017)
4
12
 
5
13
  * Initial public release as the `estella` gem - [@cavia](https://github.com/cavvia), [@mzikherman](https://github.com/mzikherman).
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ group :development, :test do
6
+ gem 'coveralls', '~> 0.8.17', require: false
7
+ end
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/estella.svg)](https://badge.fury.io/rb/estella)
4
4
  [![Build Status](https://travis-ci.org/artsy/estella.svg?branch=master)](https://travis-ci.org/artsy/estella)
5
5
  [![License Status](https://git.legal/projects/3493/badge.svg)](https://git.legal/projects/3493)
6
+ [![Coverage Status](https://coveralls.io/repos/github/artsy/estella/badge.svg?branch=master)](https://coveralls.io/github/artsy/estella?branch=master)
6
7
 
7
8
  Builds on [elasticsearch-model](https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model) to make your Ruby objects searchable with Elasticsearch. Provides fine-grained control of fields, analysis, filters, weightings and boosts.
8
9
 
@@ -87,6 +88,28 @@ class Artist < ActiveRecord::Base
87
88
  end
88
89
  ```
89
90
 
91
+ A number of class methods are available for indexing.
92
+
93
+ ```
94
+ # returns true if the index exists
95
+ Artist.index_exists?
96
+
97
+ # creates the index
98
+ Artist.create_index!
99
+
100
+ # delete and re-create the index without reindexing data
101
+ Artist.reload_index!
102
+
103
+ # recreate the index and reindex all data
104
+ Artist.recreate_index!
105
+
106
+ # deletes the index
107
+ Artist.delete_index!
108
+
109
+ # commit any outstanding writes
110
+ Artist.refresh_index!
111
+ ```
112
+
90
113
  ## Custom Analysis
91
114
 
92
115
  Estella defines `standard`, `snowball`, `ngram` and `shingle` analysers by default. These cover most search contexts, including auto-suggest. In order to enable full-text search for a field, use:
@@ -28,7 +28,7 @@ module Estella
28
28
  end
29
29
 
30
30
  def es_delete
31
- es_delete_document id
31
+ self.class.es_delete_document(id)
32
32
  end
33
33
 
34
34
  def es_transform
@@ -38,13 +38,13 @@ module Estella
38
38
  module ClassMethods
39
39
  ## Searching
40
40
 
41
- def stella_raw_search(params = {})
41
+ def estella_raw_search(params = {})
42
42
  __elasticsearch__.search(estella_query(params))
43
43
  end
44
44
 
45
45
  # @return an array of database records mapped using an adapter
46
46
  def estella_search(params = {})
47
- rsp = stella_raw_search(params)
47
+ rsp = estella_raw_search(params)
48
48
  params[:raw] ? rsp.response : rsp.records.to_a
49
49
  end
50
50
 
@@ -60,18 +60,28 @@ module Estella
60
60
  end
61
61
 
62
62
  def bulk_index(batch_of_ids)
63
+ create_index! unless index_exists?
63
64
  __elasticsearch__.client.bulk index: index_name, type: model_name.element, body: batch_to_bulk(batch_of_ids)
64
65
  end
65
66
 
67
+ # @return true if the index exists
66
68
  def index_exists?
67
69
  __elasticsearch__.client.indices.exists index: index_name
68
70
  end
69
71
 
70
- def reload_index!
71
- __elasticsearch__.client.indices.delete index: index_name if index_exists?
72
+ def delete_index!
73
+ __elasticsearch__.client.indices.delete index: index_name
74
+ end
75
+
76
+ def create_index!
72
77
  __elasticsearch__.client.indices.create index: index_name, body: { settings: settings.to_hash, mappings: mappings.to_hash }
73
78
  end
74
79
 
80
+ def reload_index!
81
+ delete_index! if index_exists?
82
+ create_index!
83
+ end
84
+
75
85
  def recreate_index!
76
86
  reload_index!
77
87
  import
@@ -82,10 +92,6 @@ module Estella
82
92
  __elasticsearch__.refresh_index!
83
93
  end
84
94
 
85
- def set_index_alias!(name)
86
- __elasticsearch__.client.indices.put_alias index: index_name, name: name
87
- end
88
-
89
95
  def es_delete_document(id)
90
96
  __elasticsearch__.client.delete type: document_type, id: id, index: index_name
91
97
  end
data/lib/estella/query.rb CHANGED
@@ -109,17 +109,5 @@ module Estella
109
109
  end
110
110
  end
111
111
  end
112
-
113
- def bool_filter(field, param)
114
- if param
115
- { term: { field => true } }
116
- elsif !param.nil?
117
- { term: { field => false } }
118
- end
119
- end
120
-
121
- def add_bool_filter(field, param)
122
- must bool_filter(field, param) if bool_filter(field, param)
123
- end
124
112
  end
125
113
  end
@@ -56,7 +56,7 @@ module Estella
56
56
 
57
57
  module ClassMethods
58
58
  # support for mongoid::slug
59
- # indexes slug attribue by default
59
+ # indexes slug attribute by default
60
60
  def index_slug
61
61
  if defined? slug
62
62
  indexed_fields.merge!(slug: { type: :string, index: :not_analyzed })
@@ -1,3 +1,3 @@
1
1
  module Estella
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -40,10 +40,11 @@ describe Estella::Searchable, type: :model do
40
40
  SearchableModel.reload_index!
41
41
  @jez = SearchableModel.create(title: 'jeremy corbyn', keywords: ['jez'])
42
42
  @tez = SearchableModel.create(title: 'theresa may', keywords: ['tez'])
43
+ @fab = SearchableModel.create(title: 'david faber', keywords: ['fab'])
43
44
  SearchableModel.refresh_index!
44
45
  end
45
46
  it 'returns relevant results' do
46
- expect(SearchableModel.all.size).to eq(2)
47
+ expect(SearchableModel.all.size).to eq(3)
47
48
  expect(SearchableModel.estella_search(term: 'jeremy')).to eq([@jez])
48
49
  expect(SearchableModel.estella_search(term: 'theresa')).to eq([@tez])
49
50
  end
@@ -74,14 +75,36 @@ describe Estella::Searchable, type: :model do
74
75
  expect(SearchableModel.mappings.to_hash[:searchable_model][:properties].keys.include?(:slug)).to eq true
75
76
  end
76
77
  it 'supports boolean filters' do
77
- @liapunov = SearchableModel.create(title: 'liapunov', published: true)
78
+ liapunov = SearchableModel.create(title: 'liapunov', published: true)
78
79
  SearchableModel.create(title: 'liapunov unpublished')
79
80
  SearchableModel.refresh_index!
80
- expect(SearchableModel.estella_search(published: true)).to eq [@liapunov]
81
+ expect(SearchableModel.estella_search(published: true)).to eq [liapunov]
81
82
  end
82
83
  it 'does not override field method on class' do
83
84
  expect(SearchableModel.methods.include?(:field)).to eq(false)
84
85
  end
86
+ it 'removes a document from the index after deletion' do
87
+ @jez.destroy
88
+ expect(SearchableModel.estella_search(term: 'jeremy')).to eq([])
89
+ expect(SearchableModel.estella_search(term: 'theresa')).to eq([@tez])
90
+ end
91
+ context 'with a deleted index' do
92
+ before do
93
+ SearchableModel.delete_index!
94
+ end
95
+ it 'recreates an index' do
96
+ expect { SearchableModel.estella_search(term: 'theresa') }.to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
97
+ SearchableModel.recreate_index!
98
+ expect(SearchableModel.estella_search(term: 'theresa')).to eq([@tez])
99
+ end
100
+ it 'indexes a bulk set of documents' do
101
+ SearchableModel.bulk_index([@fab.id, @tez.id])
102
+ SearchableModel.refresh_index!
103
+ expect(SearchableModel.estella_search(term: 'jeremy')).to eq([]) # not indexes
104
+ expect(SearchableModel.estella_search(term: 'theresa')).to eq([@tez])
105
+ expect(SearchableModel.estella_search(term: 'david')).to eq([@fab])
106
+ end
107
+ end
85
108
  end
86
109
 
87
110
  describe 'configuration errors' do
data/spec/spec_helper.rb CHANGED
@@ -2,17 +2,12 @@ require 'active_support'
2
2
  require 'active_model'
3
3
  require 'rspec'
4
4
 
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+
5
8
  require File.expand_path('../../lib/estella.rb', __FILE__)
6
9
 
7
10
  RSpec.configure do |config|
8
- config.mock_with :rspec do |c|
9
- c.syntax = :expect
10
- end
11
-
12
- config.expect_with :rspec do |c|
13
- c.syntax = :expect
14
- end
15
-
16
11
  config.raise_errors_for_deprecations!
17
12
 
18
13
  config.before(:context, elasticsearch: true) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: estella
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anil Bawa-Cavia
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-24 00:00:00.000000000 Z
12
+ date: 2017-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: elasticsearch-model
@@ -144,6 +144,7 @@ executables: []
144
144
  extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
+ - ".coveralls.yml"
147
148
  - ".gitignore"
148
149
  - ".rspec"
149
150
  - ".rubocop.yml"
@@ -185,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
186
  version: '0'
186
187
  requirements: []
187
188
  rubyforge_project:
188
- rubygems_version: 2.4.8
189
+ rubygems_version: 2.4.6
189
190
  signing_key:
190
191
  specification_version: 4
191
192
  summary: Make your Ruby objects searchable with Elasticsearch.