Skip to content
Browse files

Default search_index format to underscored class name

This is almost always what we want.
  • Loading branch information...
1 parent d2e46b9 commit a8d0674ba6bae5fd855c48eddbc80a25415c3dc2 @tomstuart tomstuart committed Feb 3, 2012
Showing with 8 additions and 4 deletions.
  1. +1 −1 app/models/document.rb
  2. +1 −1 app/models/organisation.rb
  3. +5 −1 app/models/searchable.rb
  4. +1 −1 app/models/supporting_page.rb
View
2 app/models/document.rb
@@ -38,7 +38,7 @@ def significant_changed_attributes
changed - %w(state updated_at featured carrierwave_featuring_image)
end
- searchable title: :title, link: -> d { d.public_document_path(d) }, content: :body_without_markup, format: -> d { d.type.underscore },
+ searchable title: :title, link: -> d { d.public_document_path(d) }, content: :body_without_markup,
only: :published, index_after: :publish, unindex_after: :archive
def creator
View
2 app/models/organisation.rb
@@ -34,7 +34,7 @@ class Organisation < ActiveRecord::Base
default_scope order(:name)
- searchable title: :name, link: :search_link, content: :description, format: 'organisation'
+ searchable title: :name, link: :search_link, content: :description
extend FriendlyId
friendly_id :name, use: :slugged
View
6 app/models/searchable.rb
@@ -9,7 +9,11 @@ module ClassMethods
def searchable(options)
include Searchable::Mixin
- self.searchable_options = options.reverse_merge(index_after: :save, unindex_after: :destroy, only: :scoped)
+ self.searchable_options = options.reverse_merge \
+ format: -> o { o.class.model_name.element },
+ index_after: :save,
+ unindex_after: :destroy,
+ only: :scoped
[:title, :link, :content, :format, :only].each do |name|
value = searchable_options[name]
View
2 app/models/supporting_page.rb
@@ -14,7 +14,7 @@ class SupportingPage < ActiveRecord::Base
scope :published, joins(:document).merge(Document.published)
- searchable title: :title, link: :search_link, content: :body_without_markup, format: 'supporting_page',
+ searchable title: :title, link: :search_link, content: :body_without_markup,
only: :published, index_after: false, unindex_after: false
extend FriendlyId

0 comments on commit a8d0674

Please sign in to comment.
Something went wrong with that request. Please try again.