mongoid-elasticsearch 0.3.9 → 0.4.0

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: 1b17ce3ea177fb613d714d573fc83a015970df61
4
- data.tar.gz: 2cfef5f383d8b64631d068f8bc2f40823957eeb6
3
+ metadata.gz: 58ac499ba39b4b840bbf99df12f67d7e87008acb
4
+ data.tar.gz: 9ae20ac236948c7b2124239fb159e5b860d8e2a8
5
5
  SHA512:
6
- metadata.gz: ca428b09d8d6821360b3bd47f506fa09f52988d64231a86c2d925a6b2702d3da42ede2862bc78d6f3b2df550a2fe28f72db1e7f3f293241ee10e1966f3cb117c
7
- data.tar.gz: 26f366aef339cd4a7d55823beb6090128c25d86f9028758400c85251121a3eea5442b486d3e7f490dcc44b2095913dfb314892d37efb4a7720cf827c37dd117b
6
+ metadata.gz: 424670a23b52bc88031c52743c55a117d812913ac830bc7f5f1ac79709df33d329495f7abec3955849c50a728ae0dcac2feb5f7a09ea5983748c98e3aa4b38be
7
+ data.tar.gz: a11695126ec22930873d678a1fac9053a18e06d30ce5713ab20d4557eb0e2d02bcc5fa9c4cb9f5fdf90ca69a09ac8a72cb8ee8e9a08c146ace2d9faa61233137
data/README.md CHANGED
@@ -149,7 +149,44 @@ index definition options and custom model serialization:
149
149
  end
150
150
 
151
151
  [Mapping definition docs](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html)
152
-
152
+
153
+ ### Pagination
154
+
155
+ ```= paginate @posts``` should work as normal with Kaminari after you do:
156
+
157
+ @posts = Post.es.search(params[:search], page: params[:page])
158
+ # or
159
+ @posts = Post.es.search({
160
+ body: {
161
+ query: {
162
+ query_string: {
163
+ query: params[:search]
164
+ }
165
+ },
166
+ filter: {
167
+ term: {community_id: @community.id.to_s}
168
+ }
169
+ }},
170
+ page: params[:page], wrapper: :load
171
+ )
172
+
173
+ ### Reindexing
174
+
175
+ #### Simple
176
+
177
+ Communities::Thread.es.index.reset
178
+ Communities::Thread.enabled.each do |ingr|
179
+ ingr.es_update
180
+ end
181
+
182
+ #### Bulk with progress bar
183
+
184
+ pb = nil
185
+ Music::Video.es.index_all do |steps, step|
186
+ pb = ProgressBar.create(title: "videos", total: steps, format: '%t: %p%% %a |%b>%i| %E') if pb.nil?
187
+ pb.increment
188
+ end
189
+
153
190
  ### Possible wrappers for results:
154
191
 
155
192
  - :hash - raw hash from ES
@@ -17,6 +17,22 @@ module Mongoid
17
17
  @index ||= Index.new(self)
18
18
  end
19
19
 
20
+ def index_all
21
+ index.reset
22
+ q = klass.order_by(_id: 1)
23
+ steps = (q.count / INDEX_STEP) + 1
24
+ steps.times do |step|
25
+ docs = q.skip(step * INDEX_STEP).limit(INDEX_STEP)
26
+ docs = docs.map do |obj|
27
+ { index: {data: obj.as_indexed_json}.merge(_id: obj.id.to_s) }
28
+ end
29
+ client.bulk({body: docs}.merge(type_options))
30
+ if block_given?
31
+ yield steps, step
32
+ end
33
+ end
34
+ end
35
+
20
36
  def search(query, options = {})
21
37
  if query.is_a?(String)
22
38
  query = {q: Utils.clean(query)}
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Elasticsearch
3
- VERSION = "0.3.9"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -16,6 +16,8 @@ end
16
16
 
17
17
  module Mongoid
18
18
  module Elasticsearch
19
+ INDEX_STEP = 300
20
+
19
21
  mattr_accessor :prefix
20
22
  self.prefix = ''
21
23
 
@@ -346,6 +346,17 @@ describe Namespaced::Model do
346
346
  Namespaced::Model.es.search(body: {query: {query_string: {query: 'test'}}}, size: 50).to_a.length.should eq 20
347
347
  end
348
348
 
349
+ it 'bulk index' do
350
+ Namespaced::Model.es.index.reset
351
+ Namespaced::Model.es.index_all
352
+ Namespaced::Model.es.index.refresh
353
+ Namespaced::Model.es.search('test', per_page: 10, page: 2).to_a.size.should eq 10
354
+ Namespaced::Model.es.search('test', per_page: 30, page: 2).to_a.size.should eq 0
355
+ Namespaced::Model.es.search('test', per_page: 2, page: 2).to_a.size.should eq 2
356
+ Namespaced::Model.es.search(body: {query: {query_string: {query: 'test'}}}, size: 50).to_a.length.should eq 20
357
+ end
358
+
359
+
349
360
  it '#all' do
350
361
  result = Namespaced::Model.es.all(per_page: 7, page: 3)
351
362
  result.num_pages.should eq 4
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebtv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-09 00:00:00.000000000 Z
11
+ date: 2013-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid