Class: ActiveSearch::Mongoid::Index
- Inherits:
-
Object
- Object
- ActiveSearch::Mongoid::Index
- Includes:
- Mongoid::Document
- Defined in:
- lib/activesearch/mongoid/index.rb
Class Method Summary collapse
- .deindex(original) ⇒ Object
- .reindex(original, fields, options) ⇒ Object
-
.search(query, conditions = {}, options = {}) ⇒ Object
class methods ##.
Instance Method Summary collapse
-
#original_type ⇒ Object
fields ##.
- #refresh_content(original) ⇒ Object
- #store_fields(original) ⇒ Object
-
#store_language(original) ⇒ Object
methods ##.
-
#text ⇒ Object
indexes ##.
Class Method Details
.deindex(original) ⇒ Object
53 54 55 56 |
# File 'lib/activesearch/mongoid/index.rb', line 53 def self.deindex(original) # delete the records in all the locales self.where(original_type: original.class.to_s, original_id: original.id).destroy end |
.reindex(original, fields, options) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/activesearch/mongoid/index.rb', line 58 def self.reindex(original, fields, ) # re-index only in the current locale (unless another locale has been specified) locale = original.search_locale # find the exact index scoped by the locale or build a new one doc = find_or_initialize_by(original_type: original.class.to_s, original_id: original.id, locale: locale) doc.store_language(original) doc.store_fields(original) doc.refresh_content(original) # save it (create or update it) doc.save end |
.search(query, conditions = {}, options = {}) ⇒ Object
class methods ##
48 49 50 51 |
# File 'lib/activesearch/mongoid/index.rb', line 48 def self.search(query, conditions = {}, = {}) query = FullTextSearchQuery.new(collection.name, query, conditions, ) query.run end |
Instance Method Details
#original_type ⇒ Object
fields ##
8 |
# File 'lib/activesearch/mongoid/index.rb', line 8 field :original_type, type: String |
#refresh_content(original) ⇒ Object
42 43 44 |
# File 'lib/activesearch/mongoid/index.rb', line 42 def refresh_content(original) self.content = original.to_indexable.values.flatten end |
#store_fields(original) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/activesearch/mongoid/index.rb', line 27 def store_fields(original) self.stored = {} fields = (original.search_fields + (original.[:store] || [])).uniq fields.each do |f| content = original.send(f) if content.present? content = content.to_indexable if content.respond_to?(:to_indexable) self.stored[f] = ActiveSearch.(content) end end end |
#store_language(original) ⇒ Object
methods ##
22 23 24 25 |
# File 'lib/activesearch/mongoid/index.rb', line 22 def store_language(original) self.locale = original.search_locale self.language = FullTextSearchQuery.locale_to_language(self.locale) end |
#text ⇒ Object
indexes ##
17 |
# File 'lib/activesearch/mongoid/index.rb', line 17 index({ content: 'text', locale: 1 }) |