1
1
# Elasticsearch
2
2
3
- This repository contains ActiveModel, ActiveRecord and Ruby on Rails integrations for
4
- [ Elasticsearch] ( http://elasticsearch.org ) :
3
+ This repository contains various Ruby and Rails integrations for [ Elasticsearch] ( http://elasticsearch.org ) :
5
4
6
5
* ActiveModel integration with adapters for ActiveRecord and Mongoid
6
+ * _ Repository Pattern_ based persistence layer for Ruby objects
7
7
* Enumerable-based wrapper for search results
8
8
* ActiveRecord::Relation-based wrapper for returning search results as records
9
9
* Convenience model methods such as ` search ` , ` mapping ` , ` import ` , etc
@@ -41,13 +41,16 @@ or install it from a source code checkout:
41
41
42
42
## Usage
43
43
44
- This project is split into two separate gems:
44
+ This project is split into three separate gems:
45
45
46
46
* [ ** ` elasticsearch-model ` ** ] ( https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model ) ,
47
- which contains model-related features such as setting up indices, ` search ` method, pagination, etc
47
+ which contains search integration for Ruby/Rails models such as ActiveRecord::Base and Mongoid,
48
+
49
+ * [ ** ` elasticsearch-persistence ` ** ] ( https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-persistence ) ,
50
+ which provides standalone persistence layer for Ruby/Rails objects and models
48
51
49
52
* [ ** ` elasticsearch-rails ` ** ] ( https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-rails ) ,
50
- which contains features for Ruby on Rails applications
53
+ which contains various features for Ruby on Rails applications
51
54
52
55
Example of a basic integration into an ActiveRecord-based model:
53
56
@@ -64,20 +67,43 @@ Article.import
64
67
@articles = Article .search(' foobar' ).records
65
68
```
66
69
70
+ Example of using Elasticsearch as a repository for a Ruby model:
71
+
72
+ ``` ruby
73
+ require ' virtus'
74
+ class Article
75
+ include Virtus .model
76
+ attribute :title , String
77
+ end
78
+
79
+ require ' elasticsearch/persistence'
80
+ repository = Elasticsearch ::Persistence ::Repository .new
81
+
82
+ repository.save Article .new (title: ' Test' )
83
+ # POST http://localhost:9200/repository/article [status:201, request:0.760s, query:n/a]
84
+ # => {"_index"=>"repository", "_type"=>"article", "_id"=>"Ak75E0U9Q96T5Y999_39NA", ...}
85
+ ```
86
+
67
87
You can generate a fully working Ruby on Rails application with a single command:
68
88
69
89
``` bash
70
90
rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/01-basic.rb
71
91
```
72
92
73
- Please refer to each library documentation for detailed information and examples.
93
+ ** Please refer to each library documentation for detailed information and examples.**
74
94
75
95
### Model
76
96
77
97
* [[ README]] ( https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/README.md )
78
98
* [[ Documentation]] ( http://rubydoc.info/gems/elasticsearch-model/ )
79
99
* [[ Test Suite]] ( https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/test )
80
100
101
+ ### Persistence
102
+
103
+ * [[ README]] ( https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-persistence/README.md )
104
+ * [[ Documentation]] ( http://rubydoc.info/gems/elasticsearch-persistence/ )
105
+ * [[ Test Suite]] ( https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-persistence/test )
106
+
81
107
### Rails
82
108
83
109
* [[ README]] ( https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-rails/README.md )
0 commit comments