|
| 1 | +# Elasticsearch |
| 2 | + |
| 3 | +This repository contains ActiveModel, ActiveRecord and Ruby on Rails integrations for |
| 4 | +[Elasticsearch](http://elasticsearch.org): |
| 5 | + |
| 6 | +* ActiveModel integration with adapters for ActiveRecord and Mongoid |
| 7 | +* Enumerable-based wrapper for search results |
| 8 | +* ActiveRecord::Relation-based wrapper for returning search results as records |
| 9 | +* Model methods such as `search`, `mapping`, etc |
| 10 | +* Pagination support |
| 11 | +* Rails application templates |
| 12 | + |
| 13 | +_Many more features, such as automatic hooking into Rails' notifications, Elasticsearch persistence for models, |
| 14 | +etc. are planned and/or being worked on._ |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +Install the `elasticsearch-model` and/or `elasticsearch-rails` package from |
| 19 | +[Rubygems](https://rubygems.org/gems/elasticsearch): |
| 20 | + |
| 21 | + gem install elasticsearch-model elasticsearch-rails |
| 22 | + |
| 23 | +To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://gembundler.com): |
| 24 | + |
| 25 | + gem 'elasticsearch-model', git: 'git://github.com/elasticsearch/elasticsearch-rails.git' |
| 26 | + gem 'elasticsearch-rails', git: 'git://github.com/elasticsearch/elasticsearch-rails.git' |
| 27 | + |
| 28 | +or install it from a source code checkout: |
| 29 | + |
| 30 | + git clone https://github.com/elasticsearch/elasticsearch-rails.git |
| 31 | + cd elasticsearch-model |
| 32 | + bundle install |
| 33 | + rake install |
| 34 | + cd elasticsearch-rails |
| 35 | + bundle install |
| 36 | + rake install |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +This project is split into two separate gems: |
| 41 | + |
| 42 | +* [**`elasticsearch-model`**](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model), |
| 43 | + which contains model-related features such as setting up indices, `search` method, pagination, etc |
| 44 | + |
| 45 | +* [**`elasticsearch-rails`**](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-rails), |
| 46 | + which contains features for Ruby on Rails applications |
| 47 | + |
| 48 | +Example of a basic integration into an ActiveRecord-based model: |
| 49 | + |
| 50 | +```ruby |
| 51 | +require 'elasticsearch/model' |
| 52 | + |
| 53 | +class Article < ActiveRecord::Base |
| 54 | + include Elasticsearch::Model |
| 55 | + include Elasticsearch::Model::Callbacks |
| 56 | +end |
| 57 | + |
| 58 | +Article.import |
| 59 | + |
| 60 | +@articles = Article.search('foobar').records |
| 61 | +``` |
| 62 | + |
| 63 | +You can generate a fully working Ruby on Rails application with a single command: |
| 64 | + |
| 65 | +```bash |
| 66 | +rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/01-basic.rb |
| 67 | +``` |
| 68 | + |
| 69 | +Please refer to each library documentation for detailed information and examples. |
| 70 | + |
| 71 | +### Model |
| 72 | + |
| 73 | +* [[README]](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/README.md) |
| 74 | +* [[Documentation]](http://rubydoc.info/gems/elasticsearch-model/) |
| 75 | +* [[Test Suite]](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/test) |
| 76 | + |
| 77 | +### Rails |
| 78 | + |
| 79 | +* [[README]](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-rails/README.md) |
| 80 | +* [[Documentation]](http://rubydoc.info/gems/elasticsearch-rails) |
| 81 | +* [[Test Suite]](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-rails/test) |
| 82 | + |
| 83 | +## License |
| 84 | + |
| 85 | +This software is licensed under the Apache 2 license, quoted below. |
| 86 | + |
| 87 | + Copyright (c) 2014 Elasticsearch <http://www.elasticsearch.org> |
| 88 | + |
| 89 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 90 | + you may not use this file except in compliance with the License. |
| 91 | + You may obtain a copy of the License at |
| 92 | + |
| 93 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 94 | + |
| 95 | + Unless required by applicable law or agreed to in writing, software |
| 96 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 97 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 98 | + See the License for the specific language governing permissions and |
| 99 | + limitations under the License. |
0 commit comments