elasticsearch-rails 2.0.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elasticsearch/rails/version.rb +1 -1
- data/lib/rails/templates/01-basic.rb +55 -26
- data/lib/rails/templates/02-pretty.rb +6 -6
- data/lib/rails/templates/03-expert.rb +12 -32
- data/lib/rails/templates/04-dsl.rb +9 -11
- data/lib/rails/templates/05-settings-files.rb +3 -9
- data/lib/rails/templates/index.html.dsl.erb +9 -9
- data/lib/rails/templates/index.html.erb +12 -12
- data/lib/rails/templates/search_controller_test.dsl.rb +12 -11
- data/lib/rails/templates/search_controller_test.rb +11 -11
- data/lib/rails/templates/searchable.dsl.rb +9 -9
- data/lib/rails/templates/searchable.rb +11 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea114ac0dd56a8531dc05565db0638efe2e6d74c
|
4
|
+
data.tar.gz: d1f820554717d039b37d88274cf9f2a7bb1271c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5866628fe6b02c7e1c58dd72e334ddd1efb2f5fc1d12d4df245e4081c974cf449545b2e3ae418da449ea40ba12f33dfd4dfd7f3f102db06fbdaf7f65d6eacf35
|
7
|
+
data.tar.gz: 841670e97ba0da3f8f3f63906b90420177bb146793b83effa176476715320ad44c55984c467c35feed23de43096fb8a97a0253b0c92d00c428d94277d9d8198f
|
@@ -10,8 +10,8 @@
|
|
10
10
|
#
|
11
11
|
# * Git
|
12
12
|
# * Ruby >= 1.9.3
|
13
|
-
# * Rails >=
|
14
|
-
# * Java >=
|
13
|
+
# * Rails >= 5
|
14
|
+
# * Java >= 8 (for Elasticsearch)
|
15
15
|
#
|
16
16
|
# Usage:
|
17
17
|
# ------
|
@@ -31,29 +31,32 @@ at_exit do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
$elasticsearch_url = ENV.fetch('ELASTICSEARCH_URL', 'http://localhost:9200')
|
35
35
|
|
36
|
-
|
36
|
+
# ----- Check & download Elasticsearch ------------------------------------------------------------
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
git commit: "-m 'Initial commit: Clean application'"
|
38
|
+
cluster_info = Net::HTTP.get(URI.parse($elasticsearch_url)) rescue nil
|
39
|
+
cluster_info = JSON.parse(cluster_info) if cluster_info
|
41
40
|
|
42
|
-
|
41
|
+
if cluster_info.nil? || cluster_info['version']['number'] < '5'
|
42
|
+
# Change the port when incompatible Elasticsearch version is running on localhost:9200
|
43
|
+
if $elasticsearch_url == 'http://localhost:9200' && cluster_info && cluster_info['version']['number'] < '5'
|
44
|
+
$change_port = '9280'
|
45
|
+
$elasticsearch_url = "http://localhost:#{$change_port}"
|
46
|
+
end
|
43
47
|
|
44
|
-
unless (Net::HTTP.get(URI.parse('http://localhost:9200')) rescue false)
|
45
48
|
COMMAND = <<-COMMAND.gsub(/^ /, '')
|
46
|
-
curl -# -O "
|
47
|
-
tar -zxf elasticsearch-
|
48
|
-
rm -f elasticsearch-
|
49
|
-
./elasticsearch-
|
49
|
+
curl -# -O "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.1.tar.gz"
|
50
|
+
tar -zxf elasticsearch-5.2.1.tar.gz
|
51
|
+
rm -f elasticsearch-5.2.1.tar.gz
|
52
|
+
./elasticsearch-5.2.1/bin/elasticsearch -d -p #{destination_root}/tmp/pids/elasticsearch.pid #{$change_port.nil? ? '' : "-E http.port=#{$change_port}" }
|
50
53
|
COMMAND
|
51
54
|
|
52
55
|
puts "\n"
|
53
56
|
say_status "ERROR", "Elasticsearch not running!\n", :red
|
54
57
|
puts '-'*80
|
55
|
-
say_status '', "It appears that Elasticsearch is not running on this machine."
|
56
|
-
say_status '', "Is it installed? Do you want me to install it for you with this command?\n\n"
|
58
|
+
say_status '', "It appears that Elasticsearch 5 is not running on this machine."
|
59
|
+
say_status '', "Is it installed? Do you want me to install and run it for you with this command?\n\n"
|
57
60
|
COMMAND.each_line { |l| say_status '', "$ #{l}" }
|
58
61
|
puts
|
59
62
|
say_status '', "(To uninstall, just remove the generated application directory.)"
|
@@ -63,25 +66,51 @@ unless (Net::HTTP.get(URI.parse('http://localhost:9200')) rescue false)
|
|
63
66
|
puts
|
64
67
|
say_status "Install", "Elasticsearch", :yellow
|
65
68
|
|
69
|
+
java_info = `java -version 2>&1`
|
70
|
+
|
71
|
+
unless java_info.match /1\.[8-9]/
|
72
|
+
puts
|
73
|
+
say_status "ERROR", "Required Java version (1.8) not found, exiting...", :red
|
74
|
+
exit(1)
|
75
|
+
end
|
76
|
+
|
66
77
|
commands = COMMAND.split("\n")
|
67
78
|
exec = commands.pop
|
68
79
|
inside("vendor") do
|
69
80
|
commands.each { |command| run command }
|
70
81
|
run "(#{exec})" # Launch Elasticsearch in subshell
|
71
82
|
end
|
83
|
+
|
84
|
+
# Wait for Elasticsearch to be up...
|
85
|
+
#
|
86
|
+
system <<-COMMAND
|
87
|
+
until $(curl --silent --head --fail #{$elasticsearch_url} > /dev/null 2>&1); do
|
88
|
+
printf '.'; sleep 1
|
89
|
+
done
|
90
|
+
COMMAND
|
72
91
|
end
|
73
92
|
end unless ENV['RAILS_NO_ES_INSTALL']
|
74
93
|
|
94
|
+
# ----- Application skeleton ----------------------------------------------------------------------
|
95
|
+
|
96
|
+
run "touch tmp/.gitignore"
|
97
|
+
|
98
|
+
append_to_file ".gitignore", "vendor/elasticsearch-5.2.1/\n"
|
99
|
+
|
100
|
+
git :init
|
101
|
+
git add: "."
|
102
|
+
git commit: "-m 'Initial commit: Clean application'"
|
103
|
+
|
75
104
|
# ----- Add README --------------------------------------------------------------------------------
|
76
105
|
|
77
106
|
puts
|
78
107
|
say_status "README", "Adding Readme...\n", :yellow
|
79
108
|
puts '-'*80, ''; sleep 0.25
|
80
109
|
|
81
|
-
remove_file 'README.
|
110
|
+
remove_file 'README.md'
|
82
111
|
|
83
|
-
create_file 'README.
|
84
|
-
|
112
|
+
create_file 'README.md', <<-README
|
113
|
+
# Ruby on Rails and Elasticsearch: Example application
|
85
114
|
|
86
115
|
This application is an example of integrating the {Elasticsearch}[http://www.elasticsearch.org]
|
87
116
|
search engine with the {Ruby On Rails}[http://rubyonrails.org] web framework.
|
@@ -89,7 +118,7 @@ search engine with the {Ruby On Rails}[http://rubyonrails.org] web framework.
|
|
89
118
|
It has been generated by application templates available at
|
90
119
|
https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-rails/lib/rails/templates.
|
91
120
|
|
92
|
-
|
121
|
+
## [1] Basic
|
93
122
|
|
94
123
|
The `basic` version provides a simple integration for a simple Rails model, `Article`, showing how
|
95
124
|
to include the search engine support in your model, automatically index changes to records,
|
@@ -116,6 +145,7 @@ end
|
|
116
145
|
# ----- Auxiliary gems ----------------------------------------------------------------------------
|
117
146
|
|
118
147
|
gem 'mocha', group: 'test', require: 'mocha/api'
|
148
|
+
gem 'rails-controller-testing', group: 'test'
|
119
149
|
|
120
150
|
# ----- Remove CoffeeScript, Sass and "all that jazz" ---------------------------------------------
|
121
151
|
|
@@ -145,9 +175,8 @@ say_status "Application", "Disabling asset logging in development...\n", :yello
|
|
145
175
|
puts '-'*80, ''; sleep 0.25
|
146
176
|
|
147
177
|
environment 'config.assets.logger = false', env: 'development'
|
148
|
-
|
178
|
+
environment 'config.assets.quiet = true', env: 'development'
|
149
179
|
|
150
|
-
git add: "Gemfile*"
|
151
180
|
git add: "config/"
|
152
181
|
git commit: "-m 'Disabled asset logging in development'"
|
153
182
|
|
@@ -208,7 +237,7 @@ inject_into_file 'app/controllers/articles_controller.rb', before: %r|^\s*# GET
|
|
208
237
|
CODE
|
209
238
|
end
|
210
239
|
|
211
|
-
inject_into_file 'app/views/articles/index.html.erb', after: %r{<h1
|
240
|
+
inject_into_file 'app/views/articles/index.html.erb', after: %r{<h1>.*Articles</h1>}i do
|
212
241
|
<<-CODE
|
213
242
|
|
214
243
|
|
@@ -236,21 +265,21 @@ resources :articles do
|
|
236
265
|
end
|
237
266
|
CODE
|
238
267
|
|
239
|
-
gsub_file "
|
268
|
+
gsub_file "test/controllers/articles_controller_test.rb", %r{setup do.*?end}m, <<-CODE
|
240
269
|
setup do
|
241
270
|
@article = articles(:one)
|
242
271
|
|
243
|
-
Article.__elasticsearch__.import
|
272
|
+
Article.__elasticsearch__.import force: true
|
244
273
|
Article.__elasticsearch__.refresh_index!
|
245
274
|
end
|
246
275
|
CODE
|
247
276
|
|
248
|
-
inject_into_file "
|
277
|
+
inject_into_file "test/controllers/articles_controller_test.rb", after: %r{test "should get index" do.*?end}m do
|
249
278
|
<<-CODE
|
250
279
|
|
251
280
|
|
252
281
|
test "should get search results" do
|
253
|
-
get :search, q:
|
282
|
+
#{ Rails::VERSION::STRING > '5' ? 'get search_articles_url(q: "mystring")' : 'get :search, q: "mystring"' }
|
254
283
|
assert_response :success
|
255
284
|
assert_not_nil assigns(:articles)
|
256
285
|
assert_equal 2, assigns(:articles).size
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb
|
2
2
|
|
3
|
-
unless File.read('README.
|
3
|
+
unless File.read('README.md').include? '## [1] Basic'
|
4
4
|
say_status "ERROR", "You have to run the 01-basic.rb template first.", :red
|
5
5
|
exit(1)
|
6
6
|
end
|
@@ -9,9 +9,9 @@ puts
|
|
9
9
|
say_status "README", "Updating Readme...\n", :yellow
|
10
10
|
puts '-'*80, ''; sleep 0.25
|
11
11
|
|
12
|
-
append_to_file 'README.
|
12
|
+
append_to_file 'README.md', <<-README
|
13
13
|
|
14
|
-
|
14
|
+
## [2] Pretty
|
15
15
|
|
16
16
|
The `pretty` template builds on the `basic` version and brings couple of improvements:
|
17
17
|
|
@@ -22,7 +22,7 @@ The `pretty` template builds on the `basic` version and brings couple of improve
|
|
22
22
|
|
23
23
|
README
|
24
24
|
|
25
|
-
git add: "README.
|
25
|
+
git add: "README.md"
|
26
26
|
git commit: "-m '[02] Updated the application README'"
|
27
27
|
|
28
28
|
# ----- Update application.rb ---------------------------------------------------------------------
|
@@ -154,8 +154,8 @@ end
|
|
154
154
|
|
155
155
|
# ----- Customize the header -----------------------------------------------------------------
|
156
156
|
|
157
|
-
gsub_file 'app/views/articles/index.html.erb', %r{<h1
|
158
|
-
"<h1><%= controller.action_name == 'search' ? '
|
157
|
+
gsub_file 'app/views/articles/index.html.erb', %r{<h1>.*Articles</h1>} do |match|
|
158
|
+
"<h1><%= controller.action_name == 'search' ? 'Search results' : 'Articles' %></h1>"
|
159
159
|
end
|
160
160
|
|
161
161
|
# ----- Customize the results listing -------------------------------------------------------------
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/03-expert.rb
|
2
2
|
|
3
|
-
unless File.read('README.
|
3
|
+
unless File.read('README.md').include? '## [2] Pretty'
|
4
4
|
say_status "ERROR", "You have to run the 01-basic.rb and 02-pretty.rb templates first.", :red
|
5
5
|
exit(1)
|
6
6
|
end
|
@@ -21,9 +21,9 @@ rescue Redis::CannotConnectError
|
|
21
21
|
exit(1)
|
22
22
|
end
|
23
23
|
|
24
|
-
append_to_file 'README.
|
24
|
+
append_to_file 'README.md', <<-README
|
25
25
|
|
26
|
-
|
26
|
+
## [3] Expert
|
27
27
|
|
28
28
|
The `expert` template changes to a complex database schema with model relationships: article belongs
|
29
29
|
to a category, has many authors and comments.
|
@@ -39,7 +39,7 @@ to a category, has many authors and comments.
|
|
39
39
|
|
40
40
|
README
|
41
41
|
|
42
|
-
git add: "README.
|
42
|
+
git add: "README.md"
|
43
43
|
git commit: "-m '[03] Updated the application README'"
|
44
44
|
|
45
45
|
# ----- Add gems into Gemfile ---------------------------------------------------------------------
|
@@ -77,19 +77,6 @@ git add: "Gemfile*"
|
|
77
77
|
git add: "config/"
|
78
78
|
git commit: "-m 'Added Pry as the console for development'"
|
79
79
|
|
80
|
-
# ----- Disable asset logging in development ------------------------------------------------------
|
81
|
-
|
82
|
-
puts
|
83
|
-
say_status "Application", "Disabling asset logging in development...\n", :yellow
|
84
|
-
puts '-'*80, ''; sleep 0.25
|
85
|
-
|
86
|
-
environment 'config.assets.logger = false', env: 'development'
|
87
|
-
gem 'quiet_assets', group: "development"
|
88
|
-
|
89
|
-
git add: "Gemfile*"
|
90
|
-
git add: "config/"
|
91
|
-
git commit: "-m 'Disabled asset logging in development'"
|
92
|
-
|
93
80
|
# ----- Run bundle install ------------------------------------------------------------------------
|
94
81
|
|
95
82
|
run "bundle install"
|
@@ -173,11 +160,10 @@ class Article < ActiveRecord::Base
|
|
173
160
|
end
|
174
161
|
CODE
|
175
162
|
|
176
|
-
gsub_file "
|
163
|
+
gsub_file "test/models/article_test.rb", %r{assert_equal 'foo', definition\[:query\]\[:multi_match\]\[:query\]}, "assert_equal 'foo', definition.to_hash[:query][:bool][:should][0][:multi_match][:query]"
|
177
164
|
|
178
165
|
# copy_file File.expand_path('../searchable.rb', __FILE__), 'app/models/concerns/searchable.rb'
|
179
|
-
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/searchable.rb',
|
180
|
-
'app/models/concerns/searchable.rb'
|
166
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/searchable.rb', 'app/models/concerns/searchable.rb'
|
181
167
|
|
182
168
|
insert_into_file "app/models/article.rb", after: "ActiveRecord::Base" do
|
183
169
|
<<-CODE
|
@@ -205,8 +191,7 @@ gem "sidekiq"
|
|
205
191
|
run "bundle install"
|
206
192
|
|
207
193
|
# copy_file File.expand_path('../indexer.rb', __FILE__), 'app/workers/indexer.rb'
|
208
|
-
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/indexer.rb',
|
209
|
-
'app/workers/indexer.rb'
|
194
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/indexer.rb', 'app/workers/indexer.rb'
|
210
195
|
|
211
196
|
insert_into_file "test/test_helper.rb",
|
212
197
|
"require 'sidekiq/testing'\n\n",
|
@@ -241,19 +226,16 @@ create_file 'app/controllers/search_controller.rb' do
|
|
241
226
|
end
|
242
227
|
|
243
228
|
# copy_file File.expand_path('../search_controller_test.rb', __FILE__), 'test/controllers/search_controller_test.rb'
|
244
|
-
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/search_controller_test.rb',
|
245
|
-
'test/controllers/search_controller_test.rb'
|
229
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/search_controller_test.rb', 'test/controllers/search_controller_test.rb'
|
246
230
|
|
247
231
|
route "get '/search', to: 'search#index', as: 'search'"
|
248
232
|
gsub_file 'config/routes.rb', %r{root to: 'articles#index'$}, "root to: 'search#index'"
|
249
233
|
|
250
234
|
# copy_file File.expand_path('../index.html.erb', __FILE__), 'app/views/search/index.html.erb'
|
251
|
-
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/index.html.erb',
|
252
|
-
'app/views/search/index.html.erb'
|
235
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/index.html.erb', 'app/views/search/index.html.erb'
|
253
236
|
|
254
237
|
# copy_file File.expand_path('../search.css', __FILE__), 'app/assets/stylesheets/search.css'
|
255
|
-
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/search.css',
|
256
|
-
'app/assets/stylesheets/search.css'
|
238
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/search.css', 'app/assets/stylesheets/search.css'
|
257
239
|
|
258
240
|
git add: "app/controllers/ test/controllers/ config/routes.rb"
|
259
241
|
git add: "app/views/search/ app/assets/stylesheets/search.css"
|
@@ -304,13 +286,11 @@ say_status "Database", "Re-creating the database with data and importing into E
|
|
304
286
|
puts '-'*80, ''; sleep 0.25
|
305
287
|
|
306
288
|
# copy_file File.expand_path('../articles.yml.gz', __FILE__), 'db/articles.yml.gz'
|
307
|
-
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/articles.yml.gz',
|
308
|
-
'db/articles.yml.gz'
|
289
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/articles.yml.gz', 'db/articles.yml.gz'
|
309
290
|
|
310
291
|
remove_file 'db/seeds.rb'
|
311
292
|
# copy_file File.expand_path('../seeds.rb', __FILE__), 'db/seeds.rb'
|
312
|
-
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/seeds.rb',
|
313
|
-
'db/seeds.rb'
|
293
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/seeds.rb', 'db/seeds.rb'
|
314
294
|
|
315
295
|
rake "db:reset"
|
316
296
|
rake "environment elasticsearch:import:model CLASS='Article' BATCH=100 FORCE=y"
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# $ rails new searchapp --skip --skip-bundle --template https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/04-dsl.rb
|
2
2
|
|
3
|
-
unless File.read('README.
|
3
|
+
unless File.read('README.md').include? '## [3] Expert'
|
4
4
|
say_status "ERROR", "You have to run the 01-basic.rb, 02-pretty.rb and 03-expert.rb templates first.", :red
|
5
5
|
exit(1)
|
6
6
|
end
|
7
7
|
|
8
|
-
append_to_file 'README.
|
8
|
+
append_to_file 'README.md', <<-README
|
9
9
|
|
10
|
-
|
10
|
+
## [4] DSL
|
11
11
|
|
12
12
|
The `dsl` template refactors the search definition in SearchController#index
|
13
13
|
to use the [`elasticsearch-dsl`](https://github.com/elastic/elasticsearch-ruby/tree/dsl/elasticsearch-dsl)
|
@@ -15,7 +15,7 @@ Rubygem for better expresivity and readability of the code.
|
|
15
15
|
|
16
16
|
README
|
17
17
|
|
18
|
-
git add: "README.
|
18
|
+
git add: "README.md"
|
19
19
|
git commit: "-m '[03] Updated the application README'"
|
20
20
|
|
21
21
|
run 'rm -f app/assets/stylesheets/*.scss'
|
@@ -39,16 +39,14 @@ run "bundle install"
|
|
39
39
|
# ----- Change the search definition implementation and associated views and tests ----------------
|
40
40
|
|
41
41
|
# copy_file File.expand_path('../searchable.dsl.rb', __FILE__), 'app/models/concerns/searchable.rb', force: true
|
42
|
-
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/searchable.dsl.rb',
|
43
|
-
'app/models/concerns/searchable.rb', force: true
|
42
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/searchable.dsl.rb', 'app/models/concerns/searchable.rb', force: true
|
44
43
|
|
45
44
|
# copy_file File.expand_path('../index.html.dsl.erb', __FILE__), 'app/views/search/index.html.erb', force: true
|
46
|
-
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/index.html.dsl.erb',
|
47
|
-
'app/views/search/index.html.erb', force: true
|
45
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/index.html.dsl.erb', 'app/views/search/index.html.erb', force: true
|
48
46
|
|
49
47
|
gsub_file "test/controllers/search_controller_test.rb", %r{test "should return facets" do.*?end}m, <<-CODE
|
50
48
|
test "should return aggregations" do
|
51
|
-
get :index, q: 'one'
|
49
|
+
get :index, params: { q: 'one' }
|
52
50
|
assert_response :success
|
53
51
|
|
54
52
|
aggregations = assigns(:articles).response.response['aggregations']
|
@@ -65,7 +63,7 @@ CODE
|
|
65
63
|
|
66
64
|
gsub_file "test/controllers/search_controller_test.rb", %r{test "should filter search results and the author and published date facets when user selects a category" do.*?end}m, <<-CODE
|
67
65
|
test "should filter search results and the author and published date facets when user selects a category" do
|
68
|
-
get :index, q: 'one', c: 'One'
|
66
|
+
get :index, params: { q: 'one', c: 'One' }
|
69
67
|
assert_response :success
|
70
68
|
|
71
69
|
assert_equal 2, assigns(:articles).size
|
@@ -82,7 +80,7 @@ CODE
|
|
82
80
|
|
83
81
|
gsub_file "test/controllers/search_controller_test.rb", %r{test "should filter search results and the category and published date facets when user selects a category" do.*?end}m, <<-CODE
|
84
82
|
test "should filter search results and the category and published date facets when user selects a category" do
|
85
|
-
get :index, q: 'one', a: 'Mary Smith'
|
83
|
+
get :index, params: { q: 'one', a: 'Mary Smith' }
|
86
84
|
assert_response :success
|
87
85
|
|
88
86
|
assert_equal 1, assigns(:articles).size
|
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
# (See: 01-basic.rb, 02-pretty.rb, 03-expert.rb, 04-dsl.rb)
|
4
4
|
|
5
|
-
append_to_file 'README.
|
5
|
+
append_to_file 'README.md', <<-README
|
6
6
|
|
7
|
-
|
7
|
+
## [5] Settings Files
|
8
8
|
|
9
9
|
The `settings-files` template refactors the `Searchable` module to load the index settings
|
10
10
|
from an external file.
|
11
11
|
|
12
12
|
README
|
13
13
|
|
14
|
-
git add: "README.
|
14
|
+
git add: "README.md"
|
15
15
|
git commit: "-m '[05] Updated the application README'"
|
16
16
|
|
17
17
|
# ----- Setup the Searchable module to load settings from config/elasticsearch/articles_settings.json
|
@@ -32,12 +32,6 @@ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasti
|
|
32
32
|
git add: "config/elasticsearch/articles_settings.json"
|
33
33
|
git commit: "-m 'Create the articles settings file'"
|
34
34
|
|
35
|
-
# ----- Temporarily set local repo for testing ----------------------------------------------------
|
36
|
-
|
37
|
-
gsub_file "Gemfile",
|
38
|
-
%r{gem 'elasticsearch-model', git: 'git://github.com/elasticsearch/elasticsearch-rails.git'},
|
39
|
-
"gem 'elasticsearch-model', path: File.expand_path('../../../../../../elasticsearch-model', __FILE__)"
|
40
|
-
|
41
35
|
# ----- Run bundle install ------------------------------------------------------------------------
|
42
36
|
|
43
37
|
run "bundle install"
|
@@ -37,8 +37,8 @@
|
|
37
37
|
sorted by <%= sort.humanize.downcase %> <span class="caret"></span>
|
38
38
|
</button>
|
39
39
|
<ul class="dropdown-menu" role="menu">
|
40
|
-
<li><%= link_to "Sort by published on", search_path(params.
|
41
|
-
<li><%= link_to "Sort by relevancy", search_path(params.
|
40
|
+
<li><%= link_to "Sort by published on", search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(s: 'published_on')), class: 'btn-xs' %></li>
|
41
|
+
<li><%= link_to "Sort by relevancy", search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(s: nil)), class: 'btn-xs' %></li>
|
42
42
|
</ul>
|
43
43
|
</div>
|
44
44
|
</div>
|
@@ -54,7 +54,7 @@
|
|
54
54
|
<% if @articles.response.suggestions.terms.present? %>
|
55
55
|
Maybe you mean
|
56
56
|
<%= @articles.response.suggestions.terms.map do |term|
|
57
|
-
link_to term, search_path(params.
|
57
|
+
link_to term, search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge q: term)
|
58
58
|
end.to_sentence(last_word_connector: ' or ').html_safe %>?
|
59
59
|
<% end %>
|
60
60
|
</p>
|
@@ -65,12 +65,12 @@
|
|
65
65
|
<% unless @articles.size < 1 %>
|
66
66
|
|
67
67
|
<div class="categories panel panel-default">
|
68
|
-
<p class="panel-heading"><%= link_to 'All Sections →'.html_safe, search_path(params.
|
68
|
+
<p class="panel-heading"><%= link_to 'All Sections →'.html_safe, search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(c: nil))%></p>
|
69
69
|
|
70
70
|
<div class="list-group">
|
71
71
|
<% @articles.response.response['aggregations']['categories']['categories']['buckets'].each do |c| %>
|
72
72
|
<%=
|
73
|
-
link_to search_path(params.
|
73
|
+
link_to search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(c: c['key'])),
|
74
74
|
class: "list-group-item#{' active' if params[:c] == c['key']}" do
|
75
75
|
c['key'].titleize.html_safe + content_tag(:small, c['doc_count'], class: 'badge').html_safe
|
76
76
|
end
|
@@ -80,12 +80,12 @@
|
|
80
80
|
</div>
|
81
81
|
|
82
82
|
<div class="authors panel panel-default">
|
83
|
-
<p class="panel-heading"><%= link_to 'All Authors →'.html_safe, search_path(params.
|
83
|
+
<p class="panel-heading"><%= link_to 'All Authors →'.html_safe, search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(a: nil))%></p>
|
84
84
|
|
85
85
|
<div class="list-group">
|
86
86
|
<% @articles.response.response['aggregations']['authors']['authors']['buckets'].each do |a| %>
|
87
87
|
<%=
|
88
|
-
link_to search_path(params.
|
88
|
+
link_to search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(a: a['key'])),
|
89
89
|
class: "list-group-item#{' active' if params[:a] == a['key']}" do
|
90
90
|
a['key'].titleize.html_safe + content_tag(:small, a['doc_count'], class: 'badge').html_safe
|
91
91
|
end
|
@@ -95,7 +95,7 @@
|
|
95
95
|
</div>
|
96
96
|
|
97
97
|
<div class="authors panel panel-default">
|
98
|
-
<p class="panel-heading"><%= link_to 'Any Date →'.html_safe, search_path(params.
|
98
|
+
<p class="panel-heading"><%= link_to 'Any Date →'.html_safe, search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(w: nil))%></p>
|
99
99
|
|
100
100
|
<div class="list-group">
|
101
101
|
<% @articles.response.response['aggregations']['published']['published']['buckets'].each do |w| %>
|
@@ -104,7 +104,7 @@
|
|
104
104
|
__end = __start.end_of_week
|
105
105
|
__date = __start.to_date.to_s(:iso)
|
106
106
|
|
107
|
-
link_to search_path(params.
|
107
|
+
link_to search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(w: __date)),
|
108
108
|
class: "list-group-item#{' active' if params[:w] == __date}" do
|
109
109
|
"#{__start.to_date.to_s(:short)} — #{__end.to_date.to_s(:short)}".html_safe + \
|
110
110
|
content_tag(:small, w['doc_count'], class: 'badge').html_safe
|
@@ -37,8 +37,8 @@
|
|
37
37
|
sorted by <%= sort.humanize.downcase %> <span class="caret"></span>
|
38
38
|
</button>
|
39
39
|
<ul class="dropdown-menu" role="menu">
|
40
|
-
<li><%= link_to "Sort by published on", search_path(params.
|
41
|
-
<li><%= link_to "Sort by relevancy", search_path(params.
|
40
|
+
<li><%= link_to "Sort by published on", search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(s: 'published_on')), class: 'btn-xs' %></li>
|
41
|
+
<li><%= link_to "Sort by relevancy", search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(s: nil)), class: 'btn-xs' %></li>
|
42
42
|
</ul>
|
43
43
|
</div>
|
44
44
|
</div>
|
@@ -47,14 +47,14 @@
|
|
47
47
|
<hr>
|
48
48
|
</div>
|
49
49
|
|
50
|
-
<% if @articles.size < 1 && @articles.response.
|
50
|
+
<% if @articles.size < 1 && @articles.response.suggestions.present? %>
|
51
51
|
<div class="col-md-12">
|
52
52
|
<p class="alert alert-warning">
|
53
53
|
No documents have been found.
|
54
|
-
<% if @articles.response.
|
54
|
+
<% if @articles.response.suggestions['suggest_title'].present? || @articles.response.suggestions['suggest_body'].present? %>
|
55
55
|
Maybe you mean
|
56
|
-
<%= @articles.response.
|
57
|
-
link_to term, search_path(params.
|
56
|
+
<%= @articles.response.suggestions.map { |k,v| v.first['options'] }.flatten.map {|v| v['text']}.uniq.map do |term|
|
57
|
+
link_to term, search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge q: term)
|
58
58
|
end.to_sentence(last_word_connector: ' or ').html_safe %>?
|
59
59
|
<% end %>
|
60
60
|
</p>
|
@@ -65,12 +65,12 @@
|
|
65
65
|
<% unless @articles.size < 1 %>
|
66
66
|
|
67
67
|
<div class="categories panel panel-default">
|
68
|
-
<p class="panel-heading"><%= link_to 'All Sections →'.html_safe, search_path(params.
|
68
|
+
<p class="panel-heading"><%= link_to 'All Sections →'.html_safe, search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(c: nil))%></p>
|
69
69
|
|
70
70
|
<div class="list-group">
|
71
71
|
<% @articles.response.response['aggregations']['categories']['categories']['buckets'].each do |c| %>
|
72
72
|
<%=
|
73
|
-
link_to search_path(params.
|
73
|
+
link_to search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(c: c['key'])),
|
74
74
|
class: "list-group-item#{' active' if params[:c] == c['key']}" do
|
75
75
|
c['key'].titleize.html_safe + content_tag(:small, c['doc_count'], class: 'badge').html_safe
|
76
76
|
end
|
@@ -80,12 +80,12 @@
|
|
80
80
|
</div>
|
81
81
|
|
82
82
|
<div class="authors panel panel-default">
|
83
|
-
<p class="panel-heading"><%= link_to 'All Authors →'.html_safe, search_path(params.
|
83
|
+
<p class="panel-heading"><%= link_to 'All Authors →'.html_safe, search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(a: nil))%></p>
|
84
84
|
|
85
85
|
<div class="list-group">
|
86
86
|
<% @articles.response.response['aggregations']['authors']['authors']['buckets'].each do |a| %>
|
87
87
|
<%=
|
88
|
-
link_to search_path(params.
|
88
|
+
link_to search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(a: a['key'])),
|
89
89
|
class: "list-group-item#{' active' if params[:a] == a['key']}" do
|
90
90
|
a['key'].titleize.html_safe + content_tag(:small, a['doc_count'], class: 'badge').html_safe
|
91
91
|
end
|
@@ -95,7 +95,7 @@
|
|
95
95
|
</div>
|
96
96
|
|
97
97
|
<div class="authors panel panel-default">
|
98
|
-
<p class="panel-heading"><%= link_to 'Any Date →'.html_safe, search_path(params.
|
98
|
+
<p class="panel-heading"><%= link_to 'Any Date →'.html_safe, search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(w: nil))%></p>
|
99
99
|
|
100
100
|
<div class="list-group">
|
101
101
|
<% @articles.response.response['aggregations']['published']['published']['buckets'].each do |w| %>
|
@@ -104,7 +104,7 @@
|
|
104
104
|
__end = __start.end_of_week
|
105
105
|
__date = __start.to_date.to_s(:iso)
|
106
106
|
|
107
|
-
link_to search_path(params.
|
107
|
+
link_to search_path(params.permit(:q, :a, :c, :s, :w, :comments).merge(w: __date)),
|
108
108
|
class: "list-group-item#{' active' if params[:w] == __date}" do
|
109
109
|
"#{__start.to_date.to_s(:short)} — #{__end.to_date.to_s(:short)}".html_safe + \
|
110
110
|
content_tag(:small, w['doc_count'], class: 'badge').html_safe
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'sidekiq/api'
|
2
3
|
|
3
4
|
class SearchControllerTest < ActionController::TestCase
|
4
5
|
setup do
|
5
|
-
Time.stubs(:now).returns(Time.
|
6
|
+
Time.stubs(:now).returns(Time.new(2015, 03, 16, 10, 00, 00, 0))
|
6
7
|
|
7
8
|
Article.delete_all
|
8
9
|
|
@@ -37,34 +38,34 @@ class SearchControllerTest < ActionController::TestCase
|
|
37
38
|
end
|
38
39
|
|
39
40
|
test "should return search results" do
|
40
|
-
get :index, q: 'one'
|
41
|
+
get :index, params: { q: 'one' }
|
41
42
|
assert_response :success
|
42
43
|
assert_equal 3, assigns(:articles).size
|
43
44
|
end
|
44
45
|
|
45
46
|
test "should return search results in comments" do
|
46
|
-
get :index, q: 'one', comments: 'y'
|
47
|
+
get :index, params: { q: 'one', comments: 'y' }
|
47
48
|
assert_response :success
|
48
49
|
assert_equal 4, assigns(:articles).size
|
49
50
|
end
|
50
51
|
|
51
52
|
test "should return highlighted snippets" do
|
52
|
-
get :index, q: 'one'
|
53
|
+
get :index, params: { q: 'one' }
|
53
54
|
assert_response :success
|
54
55
|
assert_match %r{<em class="label label-highlight">One</em>}, assigns(:articles).first.highlight.title.first
|
55
56
|
end
|
56
57
|
|
57
58
|
test "should return suggestions" do
|
58
|
-
get :index, q: 'one'
|
59
|
+
get :index, params: { q: 'one' }
|
59
60
|
assert_response :success
|
60
61
|
|
61
|
-
suggestions = assigns(:articles).response.
|
62
|
+
suggestions = assigns(:articles).response.suggestions
|
62
63
|
|
63
64
|
assert_equal 'one', suggestions['suggest_title'][0]['text']
|
64
65
|
end
|
65
66
|
|
66
67
|
test "should return aggregations" do
|
67
|
-
get :index, q: 'one'
|
68
|
+
get :index, params: { q: 'one' }
|
68
69
|
assert_response :success
|
69
70
|
|
70
71
|
aggregations = assigns(:articles).response.response['aggregations']
|
@@ -79,7 +80,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
79
80
|
end
|
80
81
|
|
81
82
|
test "should sort on the published date" do
|
82
|
-
get :index, q: 'one', s: 'published_on'
|
83
|
+
get :index, params: { q: 'one', s: 'published_on' }
|
83
84
|
assert_response :success
|
84
85
|
|
85
86
|
assert_equal 3, assigns(:articles).size
|
@@ -89,7 +90,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
89
90
|
end
|
90
91
|
|
91
92
|
test "should sort on the published date when no query is provided" do
|
92
|
-
get :index, q: ''
|
93
|
+
get :index, params: { q: '' }
|
93
94
|
assert_response :success
|
94
95
|
|
95
96
|
assert_equal 5, assigns(:articles).size
|
@@ -99,7 +100,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
99
100
|
end
|
100
101
|
|
101
102
|
test "should filter search results and the author and published date facets when user selects a category" do
|
102
|
-
get :index, q: 'one', c: 'One'
|
103
|
+
get :index, params: { q: 'one', c: 'One' }
|
103
104
|
assert_response :success
|
104
105
|
|
105
106
|
assert_equal 2, assigns(:articles).size
|
@@ -114,7 +115,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
114
115
|
end
|
115
116
|
|
116
117
|
test "should filter search results and the category and published date facets when user selects a category" do
|
117
|
-
get :index, q: 'one', a: 'Mary Smith'
|
118
|
+
get :index, params: { q: 'one', a: 'Mary Smith' }
|
118
119
|
assert_response :success
|
119
120
|
|
120
121
|
assert_equal 1, assigns(:articles).size
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class SearchControllerTest < ActionController::TestCase
|
4
4
|
setup do
|
5
|
-
Time.stubs(:now).returns(Time.
|
5
|
+
Time.stubs(:now).returns(Time.new(2015, 03, 16, 10, 00, 00, 0))
|
6
6
|
|
7
7
|
Article.delete_all
|
8
8
|
|
@@ -37,35 +37,35 @@ class SearchControllerTest < ActionController::TestCase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
test "should return search results" do
|
40
|
-
get :index, q: 'one'
|
40
|
+
get :index, params: { q: 'one' }
|
41
41
|
assert_response :success
|
42
42
|
assert_equal 3, assigns(:articles).size
|
43
43
|
end
|
44
44
|
|
45
45
|
test "should return search results in comments" do
|
46
|
-
get :index, q: 'one', comments: 'y'
|
46
|
+
get :index, params: { q: 'one', comments: 'y' }
|
47
47
|
assert_response :success
|
48
48
|
|
49
49
|
assert_equal 4, assigns(:articles).size
|
50
50
|
end
|
51
51
|
|
52
52
|
test "should return highlighted snippets" do
|
53
|
-
get :index, q: 'one'
|
53
|
+
get :index, params: { q: 'one' }
|
54
54
|
assert_response :success
|
55
55
|
assert_match %r{<em class="label label-highlight">One</em>}, assigns(:articles).first.highlight.title.first
|
56
56
|
end
|
57
57
|
|
58
58
|
test "should return suggestions" do
|
59
|
-
get :index, q: 'one'
|
59
|
+
get :index, params: { q: 'one' }
|
60
60
|
assert_response :success
|
61
61
|
|
62
|
-
suggestions = assigns(:articles).response.
|
62
|
+
suggestions = assigns(:articles).response.suggestions
|
63
63
|
|
64
64
|
assert_equal 'one', suggestions['suggest_title'][0]['text']
|
65
65
|
end
|
66
66
|
|
67
67
|
test "should return facets" do
|
68
|
-
get :index, q: 'one'
|
68
|
+
get :index, params: { q: 'one' }
|
69
69
|
assert_response :success
|
70
70
|
|
71
71
|
aggregations = assigns(:articles).response.response['aggregations']
|
@@ -80,7 +80,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
80
80
|
end
|
81
81
|
|
82
82
|
test "should sort on the published date" do
|
83
|
-
get :index, q: 'one', s: 'published_on'
|
83
|
+
get :index, params: { q: 'one', s: 'published_on' }
|
84
84
|
assert_response :success
|
85
85
|
|
86
86
|
assert_equal 3, assigns(:articles).size
|
@@ -90,7 +90,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
90
90
|
end
|
91
91
|
|
92
92
|
test "should sort on the published date when no query is provided" do
|
93
|
-
get :index, q: ''
|
93
|
+
get :index, params: { q: '' }
|
94
94
|
assert_response :success
|
95
95
|
|
96
96
|
assert_equal 5, assigns(:articles).size
|
@@ -100,7 +100,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
100
100
|
end
|
101
101
|
|
102
102
|
test "should filter search results and the author and published date facets when user selects a category" do
|
103
|
-
get :index, q: 'one', c: 'One'
|
103
|
+
get :index, params: { q: 'one', c: 'One' }
|
104
104
|
assert_response :success
|
105
105
|
|
106
106
|
assert_equal 2, assigns(:articles).size
|
@@ -115,7 +115,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
115
115
|
end
|
116
116
|
|
117
117
|
test "should filter search results and the category and published date facets when user selects a category" do
|
118
|
-
get :index, q: 'one', a: 'Mary Smith'
|
118
|
+
get :index, params: { q: 'one', a: 'Mary Smith' }
|
119
119
|
assert_response :success
|
120
120
|
|
121
121
|
assert_equal 1, assigns(:articles).size
|
@@ -12,12 +12,12 @@ module Searchable
|
|
12
12
|
#
|
13
13
|
settings index: { number_of_shards: 1, number_of_replicas: 0 } do
|
14
14
|
mapping do
|
15
|
-
indexes :title, type: '
|
15
|
+
indexes :title, type: 'text' do
|
16
16
|
indexes :title, analyzer: 'snowball'
|
17
17
|
indexes :tokenized, analyzer: 'simple'
|
18
18
|
end
|
19
19
|
|
20
|
-
indexes :content, type: '
|
20
|
+
indexes :content, type: 'text' do
|
21
21
|
indexes :content, analyzer: 'snowball'
|
22
22
|
indexes :tokenized, analyzer: 'simple'
|
23
23
|
end
|
@@ -25,22 +25,22 @@ module Searchable
|
|
25
25
|
indexes :published_on, type: 'date'
|
26
26
|
|
27
27
|
indexes :authors do
|
28
|
-
indexes :full_name, type: '
|
28
|
+
indexes :full_name, type: 'text' do
|
29
29
|
indexes :full_name
|
30
|
-
indexes :raw,
|
30
|
+
indexes :raw, type: 'keyword'
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
indexes :categories,
|
34
|
+
indexes :categories, type: 'keyword'
|
35
35
|
|
36
36
|
indexes :comments, type: 'nested' do
|
37
37
|
indexes :body, analyzer: 'snowball'
|
38
38
|
indexes :stars
|
39
39
|
indexes :pick
|
40
|
-
indexes :user,
|
41
|
-
indexes :user_location, type: '
|
40
|
+
indexes :user, type: 'keyword'
|
41
|
+
indexes :user_location, type: 'text' do
|
42
42
|
indexes :user_location
|
43
|
-
indexes :raw,
|
43
|
+
indexes :raw, type: 'keyword'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -98,7 +98,7 @@ module Searchable
|
|
98
98
|
query do
|
99
99
|
multi_match do
|
100
100
|
query q
|
101
|
-
fields 'body'
|
101
|
+
fields 'comments.body'
|
102
102
|
operator 'and'
|
103
103
|
end
|
104
104
|
end
|
@@ -12,12 +12,12 @@ module Searchable
|
|
12
12
|
#
|
13
13
|
settings index: { number_of_shards: 1, number_of_replicas: 0 } do
|
14
14
|
mapping do
|
15
|
-
indexes :title, type: '
|
15
|
+
indexes :title, type: 'text' do
|
16
16
|
indexes :title, analyzer: 'snowball'
|
17
17
|
indexes :tokenized, analyzer: 'simple'
|
18
18
|
end
|
19
19
|
|
20
|
-
indexes :content, type: '
|
20
|
+
indexes :content, type: 'text' do
|
21
21
|
indexes :content, analyzer: 'snowball'
|
22
22
|
indexes :tokenized, analyzer: 'simple'
|
23
23
|
end
|
@@ -25,22 +25,22 @@ module Searchable
|
|
25
25
|
indexes :published_on, type: 'date'
|
26
26
|
|
27
27
|
indexes :authors do
|
28
|
-
indexes :full_name, type: '
|
28
|
+
indexes :full_name, type: 'text' do
|
29
29
|
indexes :full_name
|
30
|
-
indexes :raw,
|
30
|
+
indexes :raw, type: 'keyword'
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
indexes :categories,
|
34
|
+
indexes :categories, type: 'keyword'
|
35
35
|
|
36
36
|
indexes :comments, type: 'nested' do
|
37
37
|
indexes :body, analyzer: 'snowball'
|
38
38
|
indexes :stars
|
39
39
|
indexes :pick
|
40
|
-
indexes :user,
|
41
|
-
indexes :user_location, type: '
|
40
|
+
indexes :user, type: 'keyword'
|
41
|
+
indexes :user_location, type: 'text' do
|
42
42
|
indexes :user_location
|
43
|
-
indexes :raw,
|
43
|
+
indexes :raw, type: 'keyword'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -74,8 +74,9 @@ module Searchable
|
|
74
74
|
# Prefill and set the filters (top-level `post_filter` and aggregation `filter` elements)
|
75
75
|
#
|
76
76
|
__set_filters = lambda do |key, f|
|
77
|
-
@search_definition[:post_filter][:
|
78
|
-
@search_definition[:post_filter][:
|
77
|
+
@search_definition[:post_filter][:bool] ||= {}
|
78
|
+
@search_definition[:post_filter][:bool][:must] ||= []
|
79
|
+
@search_definition[:post_filter][:bool][:must] |= [f]
|
79
80
|
|
80
81
|
@search_definition[:aggregations][key.to_sym][:filter][:bool][:must] ||= []
|
81
82
|
@search_definition[:aggregations][key.to_sym][:filter][:bool][:must] |= [f]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|