Skip to content

Commit 8affe4b

Browse files
committed
[STORE] Update README
1 parent 058d810 commit 8affe4b

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

elasticsearch-persistence/README.md

+35-11
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The library provides the Repository pattern for adding persistence to your Ruby
4242

4343
The `Elasticsearch::Persistence::Repository` module provides an implementation of the
4444
[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
4646
mappings and settings for the index. It's an unobtrusive and decoupled way of adding
4747
persistence to your Ruby objects.
4848

@@ -257,9 +257,9 @@ puts repository.find(1).attributes['image']
257257

258258
Each of the following configurations can be set for a repository instance.
259259
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
261261
`#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.
263263

264264
##### Client
265265

@@ -269,6 +269,9 @@ The repository uses the standard Elasticsearch [client](https://github.com/elast
269269
client = Elasticsearch::Client.new(url: 'http://search.server.org')
270270
repository = NoteRepository.new(client: client)
271271
repository.client.transport.logger = Logger.new(STDERR)
272+
repository.client
273+
# => Elasticsearch::Client
274+
272275
```
273276

274277
or with the DSL mixin:
@@ -282,6 +285,8 @@ class NoteRepository
282285
end
283286

284287
repository = NoteRepository.new
288+
repository.client
289+
# => Elasticsearch::Client
285290

286291
```
287292

@@ -292,6 +297,9 @@ is 'repository'.
292297

293298
```ruby
294299
repository = NoteRepository.new(index_name: 'notes_development')
300+
repository.index_name
301+
# => 'notes_development'
302+
295303
```
296304

297305
or with the DSL mixin:
@@ -305,15 +313,20 @@ class NoteRepository
305313
end
306314

307315
repository = NoteRepository.new
316+
repository.index_name
317+
# => 'notes_development'
308318

309319
```
310320

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
312322
'_doc'. Keep in mind that future versions of Elasticsearch will not allow you to set this yourself and will use the type,
313323
'_doc'.
314324

315325
```ruby
316326
repository = NoteRepository.new(document_type: 'note')
327+
repository.document_type
328+
# => 'note'
329+
317330
```
318331

319332
or with the DSL mixin:
@@ -327,6 +340,8 @@ class NoteRepository
327340
end
328341

329342
repository = NoteRepository.new
343+
repository.document_type
344+
# => 'note'
330345

331346
```
332347

@@ -336,6 +351,9 @@ returned instead.
336351

337352
```ruby
338353
repository = NoteRepository.new(klass: Note)
354+
repository.klass
355+
# => Note
356+
339357
```
340358

341359
or with the DSL mixin:
@@ -349,6 +367,8 @@ class NoteRepository
349367
end
350368

351369
repository = NoteRepository.new
370+
repository.klass
371+
# => Note
352372

353373
```
354374

@@ -383,8 +403,10 @@ repository = NoteRepository.new
383403

384404
```
385405

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:
388410

389411
```ruby
390412
repository = NoteRepository.create(index_name: 'notes_development') do
@@ -399,13 +421,15 @@ repository = NoteRepository.create(index_name: 'notes_development') do
399421
end
400422
```
401423

424+
##### Index Management
425+
402426
The convenience methods `create_index!`, `delete_index!` and `refresh_index!` allow you to manage the index lifecycle.
403427
These methods can only be called on repository instances and are not implemented at the class level.
404428

405429
##### Serialization
406430

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:
409433

410434
```ruby
411435
class NoteRepository
@@ -447,7 +471,7 @@ repository.update 1, script: 'if (!ctx._source.tags.contains(t)) { ctx._source.t
447471
```
448472

449473

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):
451475

452476
```ruby
453477
repository.delete(note)
@@ -456,7 +480,7 @@ repository.delete(1)
456480

457481
##### Finding
458482

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:
460484

461485
```ruby
462486
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
479503

480504
##### Search
481505

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:
483507

484508
```ruby
485509
repository.search('fox or dog').to_a

0 commit comments

Comments
 (0)