Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor index methods to use Tire.index

  • Loading branch information...
commit 3066414f3c9e00001bde7f93e241849fb74d7b84 1 parent 02d6021
@bry4n bry4n authored
Showing with 34 additions and 27 deletions.
  1. +18 −12 app/models/doc_version.rb
  2. +16 −15 app/models/section.rb
View
30 app/models/doc_version.rb
@@ -57,22 +57,28 @@ def self.version_changes(file, size = 20)
end
def index
- if BONSAI
- file = self.doc_file
- doc = self.doc
- data = {
- 'name' => file.name,
- 'blob_sha' => doc.blob_sha,
- 'text' => doc.plain,
- }
- BONSAI.add 'doc', file.name, data
+ file = self.doc_file
+ doc = self.doc
+ data = {
+ 'id' => file.name,
+ 'type' => 'doc',
+ 'name' => file.name,
+ 'blob_sha' => doc.blob_sha,
+ 'text' => doc.plain,
+ }
+ begin
+ Tire.index ELASTIC_SEARCH_INDEX do
+ store data
+ end
+ rescue Exception => e
+ nil
end
end
private
- def self.for_doc(doc_name)
- includes(:doc).joins(:doc_file).where('doc_files.name=?', doc_name)
- end
+ def self.for_doc(doc_name)
+ includes(:doc).joins(:doc_file).where('doc_files.name=?', doc_name)
+ end
end
View
31 app/models/section.rb
@@ -70,22 +70,23 @@ def cs_number
end
def index
- if defined?(BONSAI)
- code = self.chapter.book.code
- data = {
- 'chapter' => self.chapter.title,
- 'section' => self.title,
- 'number' => self.cs_number,
- 'lang' => code,
- 'html' => self.html,
- }
- id = "#{code}---#{self.slug}"
- BONSAI.add 'book', id, data
+ code = self.book.code
+ data = {
+ 'id' => "#{code}---#{self.slug}",
+ 'type' => "book",
+ 'chapter' => self.chapter.title,
+ 'section' => self.title,
+ 'number' => self.cs_number,
+ 'lang' => code,
+ 'html' => self.html,
+ }
+ begin
+ Tire.index ELASTIC_SEARCH_INDEX do
+ store data
+ end
+ rescue Exception => e
+ nil
end
- rescue Object => e
- require 'pp'
- pp e
- nil # this is busted in production for some reason, which is really an issue
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.