diff --git a/README.md b/README.md index a53c5e5..ad966da 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,21 @@ Runs on Elasticsearch :tangerine: Battle-tested at [Instacart](https://www.instacart.com) -## Usage +## Get Started + +Install Elasticsearch. + +```sh +brew install elasticsearch +``` + +Add this line to your application’s Gemfile: + +```ruby +gem "searchkick" +``` + +Add searchkick to models you want to search. ```ruby class Product < ActiveRecord::Base @@ -22,19 +36,27 @@ class Product < ActiveRecord::Base end ``` +Add data to the search index. + +```ruby +Product.reindex +``` + And to query, use: ```ruby Product.search "2% Milk" ``` -or only search specific fields: +### Query Like SQL + +Search specific fields ```ruby Product.search "Butter", fields: [:name, :brand] ``` -### Query Like SQL +Filter queries ```ruby Product.search "2% Milk", where: {in_stock: true}, limit: 10, offset: 50 @@ -199,20 +221,6 @@ Item.search "fresh honey", partial: true # matches organic honey Due to the distributed nature of Elasticsearch, you can get incorrect results when the number of documents in the index is low. You can [read more about it here](http://www.elasticsearch.org/blog/understanding-query-then-fetch-vs-dfs-query-then-fetch/). To fix this, set the search type to `dfs_query_and_fetch`. Alternatively, you can just use one shard with `settings: {number_of_shards: 1}`. -## Installation - -Add this line to your application's Gemfile: - -```ruby -gem "searchkick" -``` - -And then execute: - -```sh -bundle -``` - ## TODO - Autocomplete -- libgit2 0.21.0