mini-max-pkg 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/elasticsearch-rails-8.0.1/CHANGELOG.md +44 -0
- data/elasticsearch-rails-8.0.1/Gemfile +38 -0
- data/elasticsearch-rails-8.0.1/LICENSE.txt +202 -0
- data/elasticsearch-rails-8.0.1/README.md +149 -0
- data/elasticsearch-rails-8.0.1/Rakefile +67 -0
- data/elasticsearch-rails-8.0.1/elasticsearch-rails.gemspec +67 -0
- data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/controller_runtime.rb +58 -0
- data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/log_subscriber.rb +67 -0
- data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/publishers.rb +53 -0
- data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/railtie.rb +44 -0
- data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation.rb +53 -0
- data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/lograge.rb +57 -0
- data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/tasks/import.rb +128 -0
- data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/version.rb +22 -0
- data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails.rb +24 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/01-basic.rb +364 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/02-pretty.rb +348 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/03-expert.rb +358 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/04-dsl.rb +146 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/05-settings-files.rb +88 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/articles.yml.gz +0 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/articles_settings.json +1 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/index.html.dsl.erb +178 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/index.html.erb +178 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/indexer.rb +44 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/search.css +76 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/search_controller_test.dsl.rb +148 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/search_controller_test.rb +148 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/searchable.dsl.rb +234 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/searchable.rb +224 -0
- data/elasticsearch-rails-8.0.1/lib/rails/templates/seeds.rb +75 -0
- data/elasticsearch-rails-8.0.1/spec/instrumentation/log_subscriber_spec.rb +57 -0
- data/elasticsearch-rails-8.0.1/spec/instrumentation_spec.rb +103 -0
- data/elasticsearch-rails-8.0.1/spec/lograge_spec.rb +52 -0
- data/elasticsearch-rails-8.0.1/spec/spec_helper.rb +65 -0
- data/mini-max-pkg.gemspec +12 -0
- metadata +77 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
18
|
+
# =====================================================================================================
|
|
19
|
+
# Template for generating a no-frills Rails application with support for Elasticsearch full-text search
|
|
20
|
+
# =====================================================================================================
|
|
21
|
+
#
|
|
22
|
+
# This file creates a basic, fully working Rails application with support for Elasticsearch full-text
|
|
23
|
+
# search via the `elasticsearch-rails` gem; https://github.com/elasticsearch/elasticsearch-rails.
|
|
24
|
+
#
|
|
25
|
+
# Requirements:
|
|
26
|
+
# -------------
|
|
27
|
+
#
|
|
28
|
+
# * Git
|
|
29
|
+
# * Ruby >= 1.9.3
|
|
30
|
+
# * Rails >= 5
|
|
31
|
+
#
|
|
32
|
+
# Usage:
|
|
33
|
+
# ------
|
|
34
|
+
#
|
|
35
|
+
# $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/01-basic.rb
|
|
36
|
+
#
|
|
37
|
+
# =====================================================================================================
|
|
38
|
+
|
|
39
|
+
require 'uri'
|
|
40
|
+
require 'net/http'
|
|
41
|
+
require 'json'
|
|
42
|
+
|
|
43
|
+
$elasticsearch_url = ENV.fetch('ELASTICSEARCH_URL', 'http://localhost:9200')
|
|
44
|
+
|
|
45
|
+
# ----- Check for Elasticsearch -------------------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
required_elasticsearch_version = '7'
|
|
48
|
+
|
|
49
|
+
docker_command =<<-CMD.gsub(/\s{1,}/, ' ').strip
|
|
50
|
+
docker run \
|
|
51
|
+
--name elasticsearch-rails-searchapp \
|
|
52
|
+
--publish 9200:9200 \
|
|
53
|
+
--env "discovery.type=single-node" \
|
|
54
|
+
--env "cluster.name=elasticsearch-rails" \
|
|
55
|
+
--env "cluster.routing.allocation.disk.threshold_enabled=false" \
|
|
56
|
+
--rm \
|
|
57
|
+
docker.elastic.co/elasticsearch/elasticsearch-oss:7.6.0
|
|
58
|
+
CMD
|
|
59
|
+
|
|
60
|
+
begin
|
|
61
|
+
cluster_info = Net::HTTP.get(URI.parse($elasticsearch_url))
|
|
62
|
+
rescue Errno::ECONNREFUSED => e
|
|
63
|
+
say_status "ERROR", "Cannot connect to Elasticsearch on <#{$elasticsearch_url}>\n\n", :red
|
|
64
|
+
say_status "", "The application requires an Elasticsearch cluster running, " +
|
|
65
|
+
"but no cluster has been found on <#{$elasticsearch_url}>."
|
|
66
|
+
say_status "", "The easiest way of launching Elasticsearch is by running it with Docker (https://www.docker.com/get-docker):\n\n"
|
|
67
|
+
say_status "", docker_command + "\n"
|
|
68
|
+
exit(1)
|
|
69
|
+
rescue StandardError => e
|
|
70
|
+
say_status "ERROR", "#{e.class}: #{e.message}", :red
|
|
71
|
+
exit(1)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
cluster_info = JSON.parse(cluster_info)
|
|
75
|
+
|
|
76
|
+
unless cluster_info['version']
|
|
77
|
+
say_status "ERROR", "Cannot determine Elasticsearch version from <#{$elasticsearch_url}>", :red
|
|
78
|
+
say_status "", JSON.dump(cluster_info), :red
|
|
79
|
+
exit(1)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
if cluster_info['version']['number'] < required_elasticsearch_version
|
|
83
|
+
say_status "ERROR",
|
|
84
|
+
"The application requires Elasticsearch version #{required_elasticsearch_version} or higher, found version #{cluster_info['version']['number']}.\n\n", :red
|
|
85
|
+
say_status "", "The easiest way of launching Elasticsearch is by running it with Docker (https://www.docker.com/get-docker):\n\n"
|
|
86
|
+
say_status "", docker_command + "\n"
|
|
87
|
+
exit(1)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# ----- Application skeleton ----------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
run "touch tmp/.gitignore"
|
|
93
|
+
|
|
94
|
+
append_to_file ".gitignore", "vendor/elasticsearch-5.2.1/\n"
|
|
95
|
+
|
|
96
|
+
git :init
|
|
97
|
+
git add: "."
|
|
98
|
+
git commit: "-m 'Initial commit: Clean application'"
|
|
99
|
+
|
|
100
|
+
# ----- Add README --------------------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
puts
|
|
103
|
+
say_status "README", "Adding Readme...\n", :yellow
|
|
104
|
+
puts '-'*80, ''; sleep 0.25
|
|
105
|
+
|
|
106
|
+
remove_file 'README.md'
|
|
107
|
+
|
|
108
|
+
create_file 'README.md', <<-README
|
|
109
|
+
# Ruby on Rails and Elasticsearch: Example application
|
|
110
|
+
|
|
111
|
+
This application is an example of integrating the {Elasticsearch}[https://www.elastic.co]
|
|
112
|
+
search engine with the {Ruby On Rails}[http://rubyonrails.org] web framework.
|
|
113
|
+
|
|
114
|
+
It has been generated by application templates available at
|
|
115
|
+
https://github.com/elasticsearch/elasticsearch-rails/tree/main/elasticsearch-rails/lib/rails/templates.
|
|
116
|
+
|
|
117
|
+
## [1] Basic
|
|
118
|
+
|
|
119
|
+
The `basic` version provides a simple integration for a simple Rails model, `Article`, showing how
|
|
120
|
+
to include the search engine support in your model, automatically index changes to records,
|
|
121
|
+
and use a form to perform simple search require 'requests.'
|
|
122
|
+
|
|
123
|
+
README
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
git add: "."
|
|
127
|
+
git commit: "-m '[01] Added README for the application'"
|
|
128
|
+
|
|
129
|
+
# ----- Use Thin ----------------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
begin
|
|
132
|
+
require 'thin'
|
|
133
|
+
puts
|
|
134
|
+
say_status "Rubygems", "Adding Thin into Gemfile...\n", :yellow
|
|
135
|
+
puts '-'*80, '';
|
|
136
|
+
|
|
137
|
+
gem 'thin'
|
|
138
|
+
rescue LoadError
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# ----- Auxiliary gems ----------------------------------------------------------------------------
|
|
142
|
+
|
|
143
|
+
gem 'mocha', group: 'test'
|
|
144
|
+
gem 'rails-controller-testing', group: 'test'
|
|
145
|
+
|
|
146
|
+
# ----- Remove CoffeeScript, Sass and "all that jazz" ---------------------------------------------
|
|
147
|
+
|
|
148
|
+
comment_lines 'Gemfile', /gem 'coffee/
|
|
149
|
+
comment_lines 'Gemfile', /gem 'sass/
|
|
150
|
+
comment_lines 'Gemfile', /gem 'uglifier/
|
|
151
|
+
uncomment_lines 'Gemfile', /gem 'therubyracer/
|
|
152
|
+
|
|
153
|
+
# ----- Add gems into Gemfile ---------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
puts
|
|
156
|
+
say_status "Rubygems", "Adding Elasticsearch libraries into Gemfile...\n", :yellow
|
|
157
|
+
puts '-'*80, ''; sleep 0.75
|
|
158
|
+
|
|
159
|
+
gem 'elasticsearch'
|
|
160
|
+
gem 'elasticsearch-model', git: 'https://github.com/elasticsearch/elasticsearch-rails.git', branch: 'main'
|
|
161
|
+
gem 'elasticsearch-rails', git: 'https://github.com/elasticsearch/elasticsearch-rails.git', branch: 'main'
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
git add: "Gemfile*"
|
|
165
|
+
git commit: "-m 'Added libraries into Gemfile'"
|
|
166
|
+
|
|
167
|
+
# ----- Disable asset logging in development ------------------------------------------------------
|
|
168
|
+
|
|
169
|
+
puts
|
|
170
|
+
say_status "Application", "Disabling asset logging in development...\n", :yellow
|
|
171
|
+
puts '-'*80, ''; sleep 0.25
|
|
172
|
+
|
|
173
|
+
environment 'config.assets.logger = false', env: 'development'
|
|
174
|
+
environment 'config.assets.quiet = true', env: 'development'
|
|
175
|
+
|
|
176
|
+
git add: "config/"
|
|
177
|
+
git commit: "-m 'Disabled asset logging in development'"
|
|
178
|
+
|
|
179
|
+
# ----- Install gems ------------------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
puts
|
|
182
|
+
say_status "Rubygems", "Installing Rubygems...", :yellow
|
|
183
|
+
puts '-'*80, ''
|
|
184
|
+
|
|
185
|
+
run "bundle install"
|
|
186
|
+
|
|
187
|
+
# ----- Generate Article resource -----------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
puts
|
|
190
|
+
say_status "Model", "Generating the Article resource...", :yellow
|
|
191
|
+
puts '-'*80, ''; sleep 0.75
|
|
192
|
+
|
|
193
|
+
generate :scaffold, "Article title:string content:text published_on:date"
|
|
194
|
+
route "root to: 'articles#index'"
|
|
195
|
+
rake "db:migrate"
|
|
196
|
+
|
|
197
|
+
git add: "."
|
|
198
|
+
git commit: "-m 'Added the generated Article resource'"
|
|
199
|
+
|
|
200
|
+
# ----- Add Elasticsearch integration into the model ----------------------------------------------
|
|
201
|
+
|
|
202
|
+
puts
|
|
203
|
+
say_status "Model", "Adding search support into the Article model...", :yellow
|
|
204
|
+
puts '-'*80, ''; sleep 0.25
|
|
205
|
+
|
|
206
|
+
run "rm -f app/models/article.rb"
|
|
207
|
+
file 'app/models/article.rb', <<-CODE
|
|
208
|
+
class Article < ActiveRecord::Base
|
|
209
|
+
include Elasticsearch::Model
|
|
210
|
+
include Elasticsearch::Model::Callbacks
|
|
211
|
+
#{'attr_accessible :title, :content, :published_on' if Rails::VERSION::STRING < '4'}
|
|
212
|
+
end
|
|
213
|
+
CODE
|
|
214
|
+
|
|
215
|
+
git commit: "-a -m 'Added Elasticsearch support into the Article model'"
|
|
216
|
+
|
|
217
|
+
# ----- Add Elasticsearch integration into the interface ------------------------------------------
|
|
218
|
+
|
|
219
|
+
puts
|
|
220
|
+
say_status "Controller", "Adding controller action, route, and HTML for searching...", :yellow
|
|
221
|
+
puts '-'*80, ''; sleep 0.25
|
|
222
|
+
|
|
223
|
+
inject_into_file 'app/controllers/articles_controller.rb', before: %r|^\s*# GET /articles/1$| do
|
|
224
|
+
<<-CODE
|
|
225
|
+
|
|
226
|
+
# GET /articles/search
|
|
227
|
+
def search
|
|
228
|
+
@articles = Article.search(params[:q]).records
|
|
229
|
+
|
|
230
|
+
render action: "index"
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
CODE
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
inject_into_file 'app/views/articles/index.html.erb', after: %r{<h1>.*Articles</h1>}i do
|
|
237
|
+
<<-CODE
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
<hr>
|
|
241
|
+
|
|
242
|
+
<%= form_tag search_articles_path, method: 'get' do %>
|
|
243
|
+
<%= label_tag :query %>
|
|
244
|
+
<%= text_field_tag :q, params[:q] %>
|
|
245
|
+
<%= submit_tag :search %>
|
|
246
|
+
<% end %>
|
|
247
|
+
|
|
248
|
+
<hr>
|
|
249
|
+
CODE
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
inject_into_file 'app/views/articles/index.html.erb', after: %r{<%= link_to 'New Article', new_article_path %>} do
|
|
253
|
+
<<-CODE
|
|
254
|
+
<%= link_to 'All Articles', articles_path if params[:q] %>
|
|
255
|
+
CODE
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
gsub_file 'config/routes.rb', %r{resources :articles$}, <<-CODE
|
|
259
|
+
resources :articles do
|
|
260
|
+
collection { get :search }
|
|
261
|
+
end
|
|
262
|
+
CODE
|
|
263
|
+
|
|
264
|
+
gsub_file "test/controllers/articles_controller_test.rb", %r{setup do.*?end}m, <<-CODE
|
|
265
|
+
setup do
|
|
266
|
+
@article = articles(:one)
|
|
267
|
+
|
|
268
|
+
Article.__elasticsearch__.import force: true
|
|
269
|
+
Article.__elasticsearch__.refresh_index!
|
|
270
|
+
end
|
|
271
|
+
CODE
|
|
272
|
+
|
|
273
|
+
inject_into_file "test/controllers/articles_controller_test.rb", after: %r{test "should get index" do.*?end}m do
|
|
274
|
+
<<-CODE
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
test "should get search results" do
|
|
278
|
+
#{ Rails::VERSION::STRING > '5' ? 'get search_articles_url(q: "mystring")' : 'get :search, q: "mystring"' }
|
|
279
|
+
assert_response :success
|
|
280
|
+
assert_not_nil assigns(:articles)
|
|
281
|
+
assert_equal 2, assigns(:articles).size
|
|
282
|
+
end
|
|
283
|
+
CODE
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
git commit: "-a -m 'Added search form and controller action'"
|
|
287
|
+
|
|
288
|
+
# ----- Seed the database -------------------------------------------------------------------------
|
|
289
|
+
|
|
290
|
+
puts
|
|
291
|
+
say_status "Database", "Seeding the database with data...", :yellow
|
|
292
|
+
puts '-'*80, ''; sleep 0.25
|
|
293
|
+
|
|
294
|
+
remove_file "db/seeds.rb"
|
|
295
|
+
create_file 'db/seeds.rb', %q{
|
|
296
|
+
contents = [
|
|
297
|
+
'Lorem ipsum dolor sit amet.',
|
|
298
|
+
'Consectetur adipisicing elit, sed do eiusmod tempor incididunt.',
|
|
299
|
+
'Labore et dolore magna aliqua.',
|
|
300
|
+
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.',
|
|
301
|
+
'Excepteur sint occaecat cupidatat non proident.'
|
|
302
|
+
]
|
|
303
|
+
|
|
304
|
+
puts "Deleting all articles..."
|
|
305
|
+
Article.delete_all
|
|
306
|
+
|
|
307
|
+
unless ENV['COUNT']
|
|
308
|
+
|
|
309
|
+
puts "Creating articles..."
|
|
310
|
+
%w[ One Two Three Four Five ].each_with_index do |title, i|
|
|
311
|
+
Article.create title: title, content: contents[i], published_on: i.days.ago.utc
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
else
|
|
315
|
+
|
|
316
|
+
print "Generating articles..."
|
|
317
|
+
(1..ENV['COUNT'].to_i).each_with_index do |title, i|
|
|
318
|
+
Article.create title: "Title #{title}", content: 'Lorem ipsum dolor', published_on: i.days.ago.utc
|
|
319
|
+
print '.' if i % ENV['COUNT'].to_i/10 == 0
|
|
320
|
+
end
|
|
321
|
+
puts "\n"
|
|
322
|
+
|
|
323
|
+
end
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
run "rails runner 'Article.__elasticsearch__.create_index! force: true'"
|
|
327
|
+
rake "db:seed"
|
|
328
|
+
|
|
329
|
+
git add: "db/seeds.rb"
|
|
330
|
+
git commit: "-m 'Added the database seeding script'"
|
|
331
|
+
|
|
332
|
+
# ----- Print Git log -----------------------------------------------------------------------------
|
|
333
|
+
|
|
334
|
+
puts
|
|
335
|
+
say_status "Git", "Details about the application:", :yellow
|
|
336
|
+
puts '-'*80, ''
|
|
337
|
+
|
|
338
|
+
git tag: "basic"
|
|
339
|
+
git log: "--reverse --oneline"
|
|
340
|
+
|
|
341
|
+
# ----- Install Webpacker -------------------------------------------------------------------------
|
|
342
|
+
|
|
343
|
+
run 'rails webpacker:install'
|
|
344
|
+
|
|
345
|
+
# ----- Start the application ---------------------------------------------------------------------
|
|
346
|
+
|
|
347
|
+
unless ENV['RAILS_NO_SERVER_START']
|
|
348
|
+
require 'net/http'
|
|
349
|
+
if (begin; Net::HTTP.get(URI('http://localhost:3000')); rescue Errno::ECONNREFUSED; false; rescue Exception; true; end)
|
|
350
|
+
puts "\n"
|
|
351
|
+
say_status "ERROR", "Some other application is running on port 3000!\n", :red
|
|
352
|
+
puts '-'*80
|
|
353
|
+
|
|
354
|
+
port = ask("Please provide free port:", :bold)
|
|
355
|
+
else
|
|
356
|
+
port = '3000'
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
puts "", "="*80
|
|
360
|
+
say_status "DONE", "\e[1mStarting the application.\e[0m", :yellow
|
|
361
|
+
puts "="*80, ""
|
|
362
|
+
|
|
363
|
+
run "rails server --port=#{port}"
|
|
364
|
+
end
|