elasticsearch-rails 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.md +15 -13
- data/elasticsearch-rails.gemspec +1 -0
- data/lib/elasticsearch/rails/tasks/import.rb +6 -4
- data/lib/elasticsearch/rails/version.rb +1 -1
- data/lib/rails/templates/01-basic.rb +45 -27
- data/lib/rails/templates/02-pretty.rb +30 -15
- data/lib/rails/templates/03-expert.rb +240 -825
- data/lib/rails/templates/articles.yml.gz +0 -0
- data/lib/rails/templates/index.html.erb +157 -0
- data/lib/rails/templates/indexer.rb +27 -0
- data/lib/rails/templates/search.css +72 -0
- data/lib/rails/templates/searchable.rb +212 -0
- data/lib/rails/templates/seeds.rb +56 -0
- metadata +25 -2
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
Zlib::GzipReader.open(File.expand_path('../articles.yml.gz', __FILE__)) do |gzip|
|
5
|
+
puts "Reading articles from gzipped YAML..."
|
6
|
+
@documents = YAML.load_documents(gzip.read)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Truncate the default ActiveRecord logger output
|
10
|
+
ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDERR)
|
11
|
+
ActiveRecord::Base.logger.instance_eval do
|
12
|
+
@formatter = lambda do |s, d, p, message|
|
13
|
+
message
|
14
|
+
.gsub(/\[("content", ".*?")\]/m) { |match| match[0..100] + '..."]' }
|
15
|
+
.gsub(/\[("body", ".*?")\]/m ) { |match| match[0..100] + '..."]' }
|
16
|
+
.strip
|
17
|
+
.concat("\n")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Reduce verbosity and truncate the request body of Elasticsearch logger
|
22
|
+
Article.__elasticsearch__.client.transport.tracer.level = Logger::INFO
|
23
|
+
Article.__elasticsearch__.client.transport.tracer.formatter = lambda do |s, d, p, message|
|
24
|
+
"\n\n" + (message.size > 105 ? message[0..105].concat("...}'") : message) + "\n\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Skip model callbacks
|
28
|
+
%w| _touch_callbacks
|
29
|
+
_commit_callbacks
|
30
|
+
after_add_for_categories
|
31
|
+
after_add_for_authorships
|
32
|
+
after_add_for_authors
|
33
|
+
after_add_for_comments |.each do |c|
|
34
|
+
Article.class.__send__ :define_method, c do; []; end
|
35
|
+
end
|
36
|
+
|
37
|
+
@documents.each do |document|
|
38
|
+
article = Article.create! document.slice(:title, :abstract, :content, :url, :shares, :published_on)
|
39
|
+
|
40
|
+
article.categories = document[:categories].map do |d|
|
41
|
+
Category.find_or_create_by! title: d
|
42
|
+
end
|
43
|
+
|
44
|
+
article.authors = document[:authors].map do |d|
|
45
|
+
first_name, last_name = d.split(' ').compact.map(&:strip)
|
46
|
+
Author.find_or_create_by! first_name: first_name, last_name: last_name
|
47
|
+
end
|
48
|
+
|
49
|
+
document[:comments].each { |d| article.comments.create! d }
|
50
|
+
|
51
|
+
article.save!
|
52
|
+
end
|
53
|
+
|
54
|
+
# Remove any jobs from the "elasticsearch" Sidekiq queue
|
55
|
+
#
|
56
|
+
Sidekiq::Queue.new("elasticsearch").clear
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: minitest
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '4.0'
|
110
126
|
- !ruby/object:Gem::Dependency
|
111
127
|
name: shoulda-context
|
112
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -277,6 +293,7 @@ extra_rdoc_files:
|
|
277
293
|
- LICENSE.txt
|
278
294
|
files:
|
279
295
|
- .gitignore
|
296
|
+
- CHANGELOG.md
|
280
297
|
- Gemfile
|
281
298
|
- LICENSE.txt
|
282
299
|
- README.md
|
@@ -294,6 +311,12 @@ files:
|
|
294
311
|
- lib/rails/templates/01-basic.rb
|
295
312
|
- lib/rails/templates/02-pretty.rb
|
296
313
|
- lib/rails/templates/03-expert.rb
|
314
|
+
- lib/rails/templates/articles.yml.gz
|
315
|
+
- lib/rails/templates/index.html.erb
|
316
|
+
- lib/rails/templates/indexer.rb
|
317
|
+
- lib/rails/templates/search.css
|
318
|
+
- lib/rails/templates/searchable.rb
|
319
|
+
- lib/rails/templates/seeds.rb
|
297
320
|
- test/test_helper.rb
|
298
321
|
- test/unit/instrumentation/instrumentation_test.rb
|
299
322
|
- test/unit/instrumentation/lograge_test.rb
|