@@ -42,7 +42,7 @@ The library provides the Repository pattern for adding persistence to your Ruby
42
42
43
43
The ` Elasticsearch::Persistence::Repository ` module provides an implementation of the
44
44
[ repository pattern] ( http://martinfowler.com/eaaCatalog/repository.html ) and allows
45
- to save, delete, find and search objects stored in Elasticsearch, as well as configure
45
+ you to save, delete, find and search objects stored in Elasticsearch, as well as configure
46
46
mappings and settings for the index. It's an unobtrusive and decoupled way of adding
47
47
persistence to your Ruby objects.
48
48
@@ -257,9 +257,9 @@ puts repository.find(1).attributes['image']
257
257
258
258
Each of the following configurations can be set for a repository instance.
259
259
If you have included the ` Elasticsearch::Persistence::Repository::DSL ` mixin, then you can use the class-level DSL
260
- methods to set each configuration . You can override the configuration for any instance by passing options to the
260
+ methods to set each value . You can still override the configuration for any instance by passing options to the
261
261
` #initialize ` method.
262
- If you don't use the DSL mixin, you can set also the instance configuration with options passed the ` #initialize ` method.
262
+ Even if you don't use the DSL mixin, you can set the instance configuration with options passed the ` #initialize ` method.
263
263
264
264
##### Client
265
265
@@ -269,6 +269,9 @@ The repository uses the standard Elasticsearch [client](https://github.com/elast
269
269
client = Elasticsearch ::Client .new (url: ' http://search.server.org' )
270
270
repository = NoteRepository .new (client: client)
271
271
repository.client.transport.logger = Logger .new (STDERR )
272
+ repository.client
273
+ # => Elasticsearch::Client
274
+
272
275
```
273
276
274
277
or with the DSL mixin:
@@ -282,6 +285,8 @@ class NoteRepository
282
285
end
283
286
284
287
repository = NoteRepository .new
288
+ repository.client
289
+ # => Elasticsearch::Client
285
290
286
291
```
287
292
@@ -292,6 +297,9 @@ is 'repository'.
292
297
293
298
``` ruby
294
299
repository = NoteRepository .new (index_name: ' notes_development' )
300
+ repository.index_name
301
+ # => 'notes_development'
302
+
295
303
```
296
304
297
305
or with the DSL mixin:
@@ -305,15 +313,20 @@ class NoteRepository
305
313
end
306
314
307
315
repository = NoteRepository .new
316
+ repository.index_name
317
+ # => 'notes_development'
308
318
309
319
```
310
320
311
- The ` type ` method specifies the Elasticsearch document type to use for storage, lookup and search. The default value is
321
+ The ` document_type ` method specifies the Elasticsearch document type to use for storage, lookup and search. The default value is
312
322
'_ doc'. Keep in mind that future versions of Elasticsearch will not allow you to set this yourself and will use the type,
313
323
'_ doc'.
314
324
315
325
``` ruby
316
326
repository = NoteRepository .new (document_type: ' note' )
327
+ repository.document_type
328
+ # => 'note'
329
+
317
330
```
318
331
319
332
or with the DSL mixin:
@@ -327,6 +340,8 @@ class NoteRepository
327
340
end
328
341
329
342
repository = NoteRepository .new
343
+ repository.document_type
344
+ # => 'note'
330
345
331
346
```
332
347
@@ -336,6 +351,9 @@ returned instead.
336
351
337
352
``` ruby
338
353
repository = NoteRepository .new (klass: Note )
354
+ repository.klass
355
+ # => Note
356
+
339
357
```
340
358
341
359
or with the DSL mixin:
@@ -349,6 +367,8 @@ class NoteRepository
349
367
end
350
368
351
369
repository = NoteRepository .new
370
+ repository.klass
371
+ # => Note
352
372
353
373
```
354
374
@@ -383,8 +403,10 @@ repository = NoteRepository.new
383
403
384
404
```
385
405
386
- You can also use the ` #create ` method defined on the repository class to create and set the mappings and settings
387
- on an instance with a block in one call:
406
+ ##### Create a Repository and set its configuration with a block
407
+
408
+ You can also use the ` #create ` method to instantiate and set the mappings and settings on an instance
409
+ with a block in one call:
388
410
389
411
``` ruby
390
412
repository = NoteRepository .create(index_name: ' notes_development' ) do
@@ -399,13 +421,15 @@ repository = NoteRepository.create(index_name: 'notes_development') do
399
421
end
400
422
```
401
423
424
+ ##### Index Management
425
+
402
426
The convenience methods ` create_index! ` , ` delete_index! ` and ` refresh_index! ` allow you to manage the index lifecycle.
403
427
These methods can only be called on repository instances and are not implemented at the class level.
404
428
405
429
##### Serialization
406
430
407
- The ` serialize ` and ` deserialize ` methods allow you to customize the serialization of the document when passing it
408
- to the storage , and the initialization procedure when loading it from the storage:
431
+ The ` serialize ` and ` deserialize ` methods allow you to customize the serialization of the document when it
432
+ is persisted to Elasticsearch , and define the initialization procedure when loading it from the storage:
409
433
410
434
``` ruby
411
435
class NoteRepository
@@ -447,7 +471,7 @@ repository.update 1, script: 'if (!ctx._source.tags.contains(t)) { ctx._source.t
447
471
```
448
472
449
473
450
- The ` delete ` method allows to remove objects from the repository (pass either the object itself or its ID):
474
+ The ` delete ` method allows you to remove objects from the repository (pass either the object itself or its ID):
451
475
452
476
``` ruby
453
477
repository.delete(note)
@@ -456,7 +480,7 @@ repository.delete(1)
456
480
457
481
##### Finding
458
482
459
- The ` find ` method allows to find one or many documents in the storage and returns them as deserialized Ruby objects:
483
+ The ` find ` method allows you to find one or many documents in the storage and returns them as deserialized Ruby objects:
460
484
461
485
``` ruby
462
486
repository.save Note .new (id: 2 , title: ' Fast White Dog' )
@@ -479,7 +503,7 @@ Handle the missing objects in the application code, or call `compact` on the res
479
503
480
504
##### Search
481
505
482
- The ` search ` method to retrieve objects from the repository by a query string or definition in the Elasticsearch DSL:
506
+ The ` search ` method is used to retrieve objects from the repository by a query string or definition in the Elasticsearch DSL:
483
507
484
508
``` ruby
485
509
repository.search(' fox or dog' ).to_a
0 commit comments