Commit 21e189e5dc14a882445a53029a63e2f5d22e0f03
1 parent
eaa52ea7
Exists in
master
and in
21 other branches
Updated readme
Showing
1 changed file
with
25 additions
and
17 deletions
Show diff stats
README.md
... | ... | @@ -14,7 +14,21 @@ Runs on Elasticsearch |
14 | 14 | |
15 | 15 | :tangerine: Battle-tested at [Instacart](https://www.instacart.com) |
16 | 16 | |
17 | -## Usage | |
17 | +## Get Started | |
18 | + | |
19 | +Install Elasticsearch. | |
20 | + | |
21 | +```sh | |
22 | +brew install elasticsearch | |
23 | +``` | |
24 | + | |
25 | +Add this line to your application’s Gemfile: | |
26 | + | |
27 | +```ruby | |
28 | +gem "searchkick" | |
29 | +``` | |
30 | + | |
31 | +Add searchkick to models you want to search. | |
18 | 32 | |
19 | 33 | ```ruby |
20 | 34 | class Product < ActiveRecord::Base |
... | ... | @@ -22,19 +36,27 @@ class Product < ActiveRecord::Base |
22 | 36 | end |
23 | 37 | ``` |
24 | 38 | |
39 | +Add data to the search index. | |
40 | + | |
41 | +```ruby | |
42 | +Product.reindex | |
43 | +``` | |
44 | + | |
25 | 45 | And to query, use: |
26 | 46 | |
27 | 47 | ```ruby |
28 | 48 | Product.search "2% Milk" |
29 | 49 | ``` |
30 | 50 | |
31 | -or only search specific fields: | |
51 | +### Query Like SQL | |
52 | + | |
53 | +Search specific fields | |
32 | 54 | |
33 | 55 | ```ruby |
34 | 56 | Product.search "Butter", fields: [:name, :brand] |
35 | 57 | ``` |
36 | 58 | |
37 | -### Query Like SQL | |
59 | +Filter queries | |
38 | 60 | |
39 | 61 | ```ruby |
40 | 62 | 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 |
199 | 221 | |
200 | 222 | 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}`. |
201 | 223 | |
202 | -## Installation | |
203 | - | |
204 | -Add this line to your application's Gemfile: | |
205 | - | |
206 | -```ruby | |
207 | -gem "searchkick" | |
208 | -``` | |
209 | - | |
210 | -And then execute: | |
211 | - | |
212 | -```sh | |
213 | -bundle | |
214 | -``` | |
215 | - | |
216 | 224 | ## TODO |
217 | 225 | |
218 | 226 | - Autocomplete | ... | ... |