Module: TkhSearch::TkhSearchable
- Defined in:
- lib/tkh_search/tkh_searchable.rb
Defined Under Namespace
Modules: LocalInstanceMethods
Instance Method Summary collapse
- #index_individual_record(record) ⇒ Object
- #reverse_indexing ⇒ Object
-
#tkh_searchable ⇒ Object
Class methods.
Instance Method Details
#index_individual_record(record) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tkh_search/tkh_searchable.rb', line 27 def index_individual_record(record) words = {} # Loop through each indexable field self.tkh_search_indexable_fields.each do |field_name, strength| # Remove html tags, transform to lowercase and split words # Splitting only with spaces because we want to preserve devanagari characters Sanitize.fragment(record.send(field_name)).downcase.split.each do |word| word = clean_up(word) if words[word] # add strength to existing word rating words[word] += strength else # new word words[word] = strength # create a new word pair end end end populate_index_tables( words, record ) end |
#reverse_indexing ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tkh_search/tkh_searchable.rb', line 14 def reverse_indexing # Any model must have a self.tkh_search_indexable_fields class method returning # a hash of "field_name: :strength" pairs to be indexed if defined? self.tkh_search_indexable_fields # Index all records of the given model self.all.each do |record| index_individual_record(record) end else # no fields have been set in the model "The model '#{self.name}' has no fields marked for indexing." end end |
#tkh_searchable ⇒ Object
Class methods
9 10 11 12 |
# File 'lib/tkh_search/tkh_searchable.rb', line 9 def tkh_searchable include TkhSearch::TkhSearchable::LocalInstanceMethods after_save :index_record end |