indexes 4.0.0.2 → 4.0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +11 -198
- data/MIT-LICENSE +0 -20
- data/README.md +0 -265
- data/Rakefile +0 -19
- data/lib/generators/index/index_generator.rb +0 -15
- data/lib/generators/index/templates/index.rb +0 -12
- data/lib/generators/indexes/install/install_generator.rb +0 -15
- data/lib/generators/indexes/install/templates/initializer.rb +0 -10
- data/lib/indexes.rb +0 -85
- data/lib/indexes/collection.rb +0 -186
- data/lib/indexes/concern.rb +0 -23
- data/lib/indexes/configuration.rb +0 -39
- data/lib/indexes/definitions.rb +0 -24
- data/lib/indexes/dsl/api.rb +0 -90
- data/lib/indexes/dsl/mappings.rb +0 -14
- data/lib/indexes/dsl/search.rb +0 -27
- data/lib/indexes/dsl/serialization.rb +0 -17
- data/lib/indexes/index.rb +0 -147
- data/lib/indexes/pagination.rb +0 -33
- data/lib/indexes/proxy.rb +0 -17
- data/lib/indexes/railtie.rb +0 -15
- data/lib/indexes/version.rb +0 -5
- data/lib/tasks/indexes.rake +0 -11
- data/test/dsl_test.rb +0 -128
- data/test/dummy/Rakefile +0 -5
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/indexes/products_index.rb +0 -51
- data/test/dummy/app/indexes/shops_index.rb +0 -28
- data/test/dummy/app/models/product.rb +0 -5
- data/test/dummy/app/models/shop.rb +0 -5
- data/test/dummy/app/views/layouts/application.html.erb +0 -12
- data/test/dummy/bin/bundle +0 -4
- data/test/dummy/bin/rails +0 -5
- data/test/dummy/bin/rake +0 -5
- data/test/dummy/bin/setup +0 -30
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -25
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.yml +0 -7
- data/test/dummy/config/database.yml.travis +0 -3
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -41
- data/test/dummy/config/environments/production.rb +0 -79
- data/test/dummy/config/environments/test.rb +0 -42
- data/test/dummy/config/initializers/assets.rb +0 -11
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/indexes.rb +0 -67
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/routes.rb +0 -56
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/db/migrate/20161104164148_create_products.rb +0 -14
- data/test/dummy/db/migrate/20161104182219_create_shops.rb +0 -9
- data/test/dummy/db/schema.rb +0 -36
- data/test/dummy/log/development.log +0 -38
- data/test/dummy/log/test.log +0 -3643
- data/test/dummy/public/404.html +0 -61
- data/test/dummy/public/422.html +0 -61
- data/test/dummy/public/500.html +0 -60
- data/test/dummy/public/favicon.ico +0 -0
- data/test/generator_test.rb +0 -25
- data/test/index_test.rb +0 -46
- data/test/record_test.rb +0 -25
- data/test/search_test.rb +0 -164
- data/test/task_test.rb +0 -25
- data/test/test_helper.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 819b1fab2aba09d1ff780f3d7c962abd5361e2d2
|
4
|
+
data.tar.gz: c9fc1c4e480ad468c794f57cb1a2ae3cff72372d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eafe3ce2bba5dfc8d505b61ed5c6015feccc6d50a7a1e7da8fd10f005958b21cc60097fed7ac8b070832d910b4cf555f15f594e90cc1d8e8fc4696f1370bf97
|
7
|
+
data.tar.gz: c5eac6ce6434e4857fca028f9d350cd12474b9710eeff726b2c8c5a3d1d9566285d7d2894e4064e222d18a12984fe90ca91e72e1838652991fe144a9021feaf9
|
metadata
CHANGED
@@ -1,162 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: indexes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mmontossi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: rails
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 4.2.0
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 4.3.0
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 4.2.0
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 4.3.0
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: elasticsearch
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 2.0.0
|
40
|
-
type: :runtime
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 2.0.0
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: pg
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0.18'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0.18'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: mocha
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '1.1'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '1.1'
|
75
|
-
description: Model search indexes with elasticsearch in rails.
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 'THIS GEM HAS BEEN RENAMED TO: indexers'
|
76
14
|
email:
|
77
15
|
- mmontossi@gmail.com
|
78
16
|
executables: []
|
79
17
|
extensions: []
|
80
18
|
extra_rdoc_files: []
|
81
|
-
files:
|
82
|
-
|
83
|
-
- README.md
|
84
|
-
- Rakefile
|
85
|
-
- lib/generators/index/index_generator.rb
|
86
|
-
- lib/generators/index/templates/index.rb
|
87
|
-
- lib/generators/indexes/install/install_generator.rb
|
88
|
-
- lib/generators/indexes/install/templates/initializer.rb
|
89
|
-
- lib/indexes.rb
|
90
|
-
- lib/indexes/collection.rb
|
91
|
-
- lib/indexes/concern.rb
|
92
|
-
- lib/indexes/configuration.rb
|
93
|
-
- lib/indexes/definitions.rb
|
94
|
-
- lib/indexes/dsl/api.rb
|
95
|
-
- lib/indexes/dsl/mappings.rb
|
96
|
-
- lib/indexes/dsl/search.rb
|
97
|
-
- lib/indexes/dsl/serialization.rb
|
98
|
-
- lib/indexes/index.rb
|
99
|
-
- lib/indexes/pagination.rb
|
100
|
-
- lib/indexes/proxy.rb
|
101
|
-
- lib/indexes/railtie.rb
|
102
|
-
- lib/indexes/version.rb
|
103
|
-
- lib/tasks/indexes.rake
|
104
|
-
- test/dsl_test.rb
|
105
|
-
- test/dummy/Rakefile
|
106
|
-
- test/dummy/app/assets/javascripts/application.js
|
107
|
-
- test/dummy/app/assets/stylesheets/application.css
|
108
|
-
- test/dummy/app/controllers/application_controller.rb
|
109
|
-
- test/dummy/app/helpers/application_helper.rb
|
110
|
-
- test/dummy/app/indexes/products_index.rb
|
111
|
-
- test/dummy/app/indexes/shops_index.rb
|
112
|
-
- test/dummy/app/models/product.rb
|
113
|
-
- test/dummy/app/models/shop.rb
|
114
|
-
- test/dummy/app/views/layouts/application.html.erb
|
115
|
-
- test/dummy/bin/bundle
|
116
|
-
- test/dummy/bin/rails
|
117
|
-
- test/dummy/bin/rake
|
118
|
-
- test/dummy/bin/setup
|
119
|
-
- test/dummy/config.ru
|
120
|
-
- test/dummy/config/application.rb
|
121
|
-
- test/dummy/config/boot.rb
|
122
|
-
- test/dummy/config/database.yml
|
123
|
-
- test/dummy/config/database.yml.travis
|
124
|
-
- test/dummy/config/environment.rb
|
125
|
-
- test/dummy/config/environments/development.rb
|
126
|
-
- test/dummy/config/environments/production.rb
|
127
|
-
- test/dummy/config/environments/test.rb
|
128
|
-
- test/dummy/config/initializers/assets.rb
|
129
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
130
|
-
- test/dummy/config/initializers/cookies_serializer.rb
|
131
|
-
- test/dummy/config/initializers/filter_parameter_logging.rb
|
132
|
-
- test/dummy/config/initializers/indexes.rb
|
133
|
-
- test/dummy/config/initializers/inflections.rb
|
134
|
-
- test/dummy/config/initializers/mime_types.rb
|
135
|
-
- test/dummy/config/initializers/session_store.rb
|
136
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
137
|
-
- test/dummy/config/locales/en.yml
|
138
|
-
- test/dummy/config/routes.rb
|
139
|
-
- test/dummy/config/secrets.yml
|
140
|
-
- test/dummy/db/migrate/20161104164148_create_products.rb
|
141
|
-
- test/dummy/db/migrate/20161104182219_create_shops.rb
|
142
|
-
- test/dummy/db/schema.rb
|
143
|
-
- test/dummy/log/development.log
|
144
|
-
- test/dummy/log/test.log
|
145
|
-
- test/dummy/public/404.html
|
146
|
-
- test/dummy/public/422.html
|
147
|
-
- test/dummy/public/500.html
|
148
|
-
- test/dummy/public/favicon.ico
|
149
|
-
- test/generator_test.rb
|
150
|
-
- test/index_test.rb
|
151
|
-
- test/record_test.rb
|
152
|
-
- test/search_test.rb
|
153
|
-
- test/task_test.rb
|
154
|
-
- test/test_helper.rb
|
155
|
-
homepage: https://github.com/mmontossi/indexes
|
19
|
+
files: []
|
20
|
+
homepage: https://github.com/mmontossi/indexers
|
156
21
|
licenses:
|
157
22
|
- MIT
|
158
23
|
metadata: {}
|
159
|
-
post_install_message:
|
24
|
+
post_install_message: 'THIS GEM HAS BEEN RENAMED TO: indexers'
|
160
25
|
rdoc_options: []
|
161
26
|
require_paths:
|
162
27
|
- lib
|
@@ -164,68 +29,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
29
|
requirements:
|
165
30
|
- - ">="
|
166
31
|
- !ruby/object:Gem::Version
|
167
|
-
version:
|
32
|
+
version: '0'
|
168
33
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
34
|
requirements:
|
170
35
|
- - ">="
|
171
36
|
- !ruby/object:Gem::Version
|
172
37
|
version: '0'
|
173
|
-
requirements:
|
174
|
-
- Elasticsearch
|
38
|
+
requirements: []
|
175
39
|
rubyforge_project:
|
176
40
|
rubygems_version: 2.5.1
|
177
41
|
signing_key:
|
178
42
|
specification_version: 4
|
179
|
-
summary:
|
180
|
-
test_files:
|
181
|
-
- test/dsl_test.rb
|
182
|
-
- test/dummy/app/assets/javascripts/application.js
|
183
|
-
- test/dummy/app/assets/stylesheets/application.css
|
184
|
-
- test/dummy/app/controllers/application_controller.rb
|
185
|
-
- test/dummy/app/helpers/application_helper.rb
|
186
|
-
- test/dummy/app/indexes/products_index.rb
|
187
|
-
- test/dummy/app/indexes/shops_index.rb
|
188
|
-
- test/dummy/app/models/product.rb
|
189
|
-
- test/dummy/app/models/shop.rb
|
190
|
-
- test/dummy/app/views/layouts/application.html.erb
|
191
|
-
- test/dummy/bin/bundle
|
192
|
-
- test/dummy/bin/rails
|
193
|
-
- test/dummy/bin/rake
|
194
|
-
- test/dummy/bin/setup
|
195
|
-
- test/dummy/config/application.rb
|
196
|
-
- test/dummy/config/boot.rb
|
197
|
-
- test/dummy/config/database.yml
|
198
|
-
- test/dummy/config/database.yml.travis
|
199
|
-
- test/dummy/config/environment.rb
|
200
|
-
- test/dummy/config/environments/development.rb
|
201
|
-
- test/dummy/config/environments/production.rb
|
202
|
-
- test/dummy/config/environments/test.rb
|
203
|
-
- test/dummy/config/initializers/assets.rb
|
204
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
205
|
-
- test/dummy/config/initializers/cookies_serializer.rb
|
206
|
-
- test/dummy/config/initializers/filter_parameter_logging.rb
|
207
|
-
- test/dummy/config/initializers/indexes.rb
|
208
|
-
- test/dummy/config/initializers/inflections.rb
|
209
|
-
- test/dummy/config/initializers/mime_types.rb
|
210
|
-
- test/dummy/config/initializers/session_store.rb
|
211
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
212
|
-
- test/dummy/config/locales/en.yml
|
213
|
-
- test/dummy/config/routes.rb
|
214
|
-
- test/dummy/config/secrets.yml
|
215
|
-
- test/dummy/config.ru
|
216
|
-
- test/dummy/db/migrate/20161104164148_create_products.rb
|
217
|
-
- test/dummy/db/migrate/20161104182219_create_shops.rb
|
218
|
-
- test/dummy/db/schema.rb
|
219
|
-
- test/dummy/log/development.log
|
220
|
-
- test/dummy/log/test.log
|
221
|
-
- test/dummy/public/404.html
|
222
|
-
- test/dummy/public/422.html
|
223
|
-
- test/dummy/public/500.html
|
224
|
-
- test/dummy/public/favicon.ico
|
225
|
-
- test/dummy/Rakefile
|
226
|
-
- test/generator_test.rb
|
227
|
-
- test/index_test.rb
|
228
|
-
- test/record_test.rb
|
229
|
-
- test/search_test.rb
|
230
|
-
- test/task_test.rb
|
231
|
-
- test/test_helper.rb
|
43
|
+
summary: 'THIS GEM HAS BEEN RENAMED TO: indexers'
|
44
|
+
test_files: []
|
data/MIT-LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright 2016 Mathías Montossi
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,265 +0,0 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/indexes.svg)](http://badge.fury.io/rb/indexes)
|
2
|
-
[![Code Climate](https://codeclimate.com/github/mmontossi/indexes/badges/gpa.svg)](https://codeclimate.com/github/mmontossi/indexes)
|
3
|
-
[![Build Status](https://travis-ci.org/mmontossi/indexes.svg)](https://travis-ci.org/mmontossi/indexes)
|
4
|
-
[![Dependency Status](https://gemnasium.com/mmontossi/indexes.svg)](https://gemnasium.com/mmontossi/indexes)
|
5
|
-
|
6
|
-
# Indexes
|
7
|
-
|
8
|
-
Model search indexes with elasticsearch in rails.
|
9
|
-
|
10
|
-
## Why
|
11
|
-
|
12
|
-
I did this gem to:
|
13
|
-
|
14
|
-
- Gain control of the queries without losing simplicity.
|
15
|
-
- Have out of the box integration with activerecord and pagers.
|
16
|
-
- Deal with the just in time nature of elasticsearch.
|
17
|
-
- Integrate activerecord includes on it.
|
18
|
-
- Have a convention of how to use suggestions.
|
19
|
-
|
20
|
-
## Install
|
21
|
-
|
22
|
-
Put this line in your Gemfile:
|
23
|
-
```ruby
|
24
|
-
gem 'indexes'
|
25
|
-
```
|
26
|
-
|
27
|
-
Then bundle:
|
28
|
-
```
|
29
|
-
$ bundle
|
30
|
-
```
|
31
|
-
|
32
|
-
To install Redis you can use homebrew:
|
33
|
-
```
|
34
|
-
$ brew install elasticsearch24
|
35
|
-
```
|
36
|
-
|
37
|
-
NOTE: This gem is tested agains version 2.4.
|
38
|
-
|
39
|
-
## Configuration
|
40
|
-
|
41
|
-
Generate the configuration file:
|
42
|
-
```
|
43
|
-
$ bundle exec rails g indexes:install
|
44
|
-
```
|
45
|
-
|
46
|
-
Set the global settings:
|
47
|
-
```ruby
|
48
|
-
Indexes.configure do |config|
|
49
|
-
|
50
|
-
config.hosts = %w(localhost:9200)
|
51
|
-
config.log = false
|
52
|
-
config.trace = false
|
53
|
-
|
54
|
-
config.mappings do
|
55
|
-
name do
|
56
|
-
type 'string'
|
57
|
-
fields do
|
58
|
-
raw do
|
59
|
-
type 'string'
|
60
|
-
index 'not_analyzed'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
category type: 'string'
|
65
|
-
price type: 'long'
|
66
|
-
currency type: 'string'
|
67
|
-
product_suggestions do
|
68
|
-
type 'completion'
|
69
|
-
analyzer 'simple'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
```
|
75
|
-
|
76
|
-
### Definitions
|
77
|
-
|
78
|
-
Generate an index:
|
79
|
-
```
|
80
|
-
$ bundle exec rails g index products
|
81
|
-
```
|
82
|
-
|
83
|
-
Define the mappings, serialization and search in the index:
|
84
|
-
```ruby
|
85
|
-
Indexes.define :products do
|
86
|
-
|
87
|
-
mappings do
|
88
|
-
properties :name, :category, :price, :product_suggestions
|
89
|
-
end
|
90
|
-
|
91
|
-
serialization do |record|
|
92
|
-
extract record, :name, :category, :price
|
93
|
-
product_suggestions do
|
94
|
-
input [record.name, transliterate(record.name)].uniq
|
95
|
-
output record.name
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
search do |*args|
|
100
|
-
options = args.extract_options!
|
101
|
-
term = args.first
|
102
|
-
query do
|
103
|
-
if term.present?
|
104
|
-
multi_match do
|
105
|
-
query term
|
106
|
-
type 'phrase_prefix'
|
107
|
-
fields %w(name category)
|
108
|
-
end
|
109
|
-
else
|
110
|
-
match_all
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
```
|
117
|
-
|
118
|
-
If you need to personalize the analysis, you have to add it to the configuration:
|
119
|
-
|
120
|
-
```ruby
|
121
|
-
Indexes.configure do |config|
|
122
|
-
|
123
|
-
config.analysis do
|
124
|
-
filter do
|
125
|
-
ngram do
|
126
|
-
type 'nGram'
|
127
|
-
min_gram 2
|
128
|
-
max_gram 20
|
129
|
-
end
|
130
|
-
end
|
131
|
-
analyzer do
|
132
|
-
ngram do
|
133
|
-
type 'custom'
|
134
|
-
tokenizer 'standard'
|
135
|
-
filter %w(lowercase ngram)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
```
|
142
|
-
|
143
|
-
### Indexing
|
144
|
-
|
145
|
-
The index will be updated every time a record is created, updated or destroyed:
|
146
|
-
```ruby
|
147
|
-
product = Product.create(name: 'Les Paul', category: 'Gibson')
|
148
|
-
```
|
149
|
-
|
150
|
-
You can force this actions manually with:
|
151
|
-
```ruby
|
152
|
-
product.index
|
153
|
-
product.reindex
|
154
|
-
product.unindex
|
155
|
-
```
|
156
|
-
|
157
|
-
### Rake tasks
|
158
|
-
|
159
|
-
At any time you can build/rebuild your indexes using:
|
160
|
-
```
|
161
|
-
$ bundle exec rake indexes:build
|
162
|
-
$ bundle exec rake indexes:rebuild
|
163
|
-
```
|
164
|
-
|
165
|
-
### Search
|
166
|
-
|
167
|
-
Use the included search method in the model:
|
168
|
-
```ruby
|
169
|
-
products = Product.search('Les Paul')
|
170
|
-
```
|
171
|
-
|
172
|
-
The result can be used as a collection in views:
|
173
|
-
```erb
|
174
|
-
<%= render products %>
|
175
|
-
```
|
176
|
-
|
177
|
-
### Includes
|
178
|
-
|
179
|
-
Similar to using activerecod:
|
180
|
-
```ruby
|
181
|
-
Product.search.includes(:shop)
|
182
|
-
```
|
183
|
-
|
184
|
-
### With / Without
|
185
|
-
|
186
|
-
You can force a record to be part of the results by id:
|
187
|
-
```ruby
|
188
|
-
Products.search.with(4)
|
189
|
-
```
|
190
|
-
|
191
|
-
Or the opposite:
|
192
|
-
```ruby
|
193
|
-
Products.search.without(4)
|
194
|
-
```
|
195
|
-
|
196
|
-
### Pagination
|
197
|
-
|
198
|
-
Works the same as [pagers gem](https://github.com/mmontossi/pagers):
|
199
|
-
```ruby
|
200
|
-
Products.search.page(1, padding: 4, length: 30)
|
201
|
-
```
|
202
|
-
|
203
|
-
And you can send the collection directly to the view helper:
|
204
|
-
```erb
|
205
|
-
<%= paginate products %>
|
206
|
-
```
|
207
|
-
|
208
|
-
### Order
|
209
|
-
|
210
|
-
Same as using activerecord:
|
211
|
-
```ruby
|
212
|
-
Product.search.order(name: :asc)
|
213
|
-
```
|
214
|
-
|
215
|
-
You can use a computed sort by declare it in the configuration:
|
216
|
-
```ruby
|
217
|
-
Indexes.configure do |config|
|
218
|
-
|
219
|
-
config.computed_sort :price do |direction|
|
220
|
-
_script do
|
221
|
-
type 'number'
|
222
|
-
script do
|
223
|
-
inline "if (_source.currency == 'UYU') { doc['price'].value * 30 }"
|
224
|
-
end
|
225
|
-
order direction
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
```
|
231
|
-
|
232
|
-
### Suggestions
|
233
|
-
|
234
|
-
You need to first define the logic in the configuration:
|
235
|
-
```ruby
|
236
|
-
Indexes.configure do |config|
|
237
|
-
|
238
|
-
config.suggestions do |name, term, options={}|
|
239
|
-
type = name.to_s.singularize
|
240
|
-
text (term || '')
|
241
|
-
completion do
|
242
|
-
field "#{type}_suggestions"
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
end
|
247
|
-
```
|
248
|
-
|
249
|
-
Then you can get suggestions using the suggest method:
|
250
|
-
```ruby
|
251
|
-
Indexes.suggest :products, 'gibson'
|
252
|
-
```
|
253
|
-
|
254
|
-
The result is an array of hashes with a text property:
|
255
|
-
```ruby
|
256
|
-
[{ text: 'Les Paul' }, ...]
|
257
|
-
```
|
258
|
-
|
259
|
-
## Credits
|
260
|
-
|
261
|
-
This gem is maintained and funded by [mmontossi](https://github.com/mmontossi).
|
262
|
-
|
263
|
-
## License
|
264
|
-
|
265
|
-
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|