Module: Pose::ModelClassAdditions

Extended by:
ActiveSupport::Concern
Defined in:
lib/pose/model_class_additions.rb

Instance Method Summary collapse

Instance Method Details

#delete_pose_indexObject

Removes this objects from the search index.



52
53
54
# File 'lib/pose/model_class_additions.rb', line 52

def delete_pose_index
  self.pose_words.clear if Pose.perform_search?
end

#pose_current_wordsArray<String>

Returns all words in the search index for this instance.

Returns:

  • (Array<String>)


18
19
20
# File 'lib/pose/model_class_additions.rb', line 18

def pose_current_words
  pose_words.map(&:text)
end

#pose_fetch_contentString

Returns the searchable text snippet for this instance. This data is not stored in the search engine. It is recomputes this from data in the database here.

Returns:

  • (String)


26
27
28
# File 'lib/pose/model_class_additions.rb', line 26

def pose_fetch_content
  instance_eval(&(pose_content)).to_s
end

#pose_fresh_words(reload = false) ⇒ Array<String>

Returns:

  • (Array<String>)


31
32
33
34
# File 'lib/pose/model_class_additions.rb', line 31

def pose_fresh_words reload = false
  @pose_fresh_words = nil if reload
  @pose_fresh_words ||= Query.query_words pose_fetch_content
end

#pose_stale_words(reload = false) ⇒ Array<String>

Returns:

  • (Array<String>)


37
38
39
# File 'lib/pose/model_class_additions.rb', line 37

def pose_stale_words reload = false
  pose_current_words - pose_fresh_words(reload)
end

#pose_words_to_add(reload = false) ⇒ Array<String>

Returns:

  • (Array<String>)


42
43
44
# File 'lib/pose/model_class_additions.rb', line 42

def pose_words_to_add reload = false
  pose_fresh_words(reload) - pose_current_words
end

#update_pose_indexObject

Updates the associated words for this object in the database.



47
48
49
# File 'lib/pose/model_class_additions.rb', line 47

def update_pose_index
  update_pose_words if Pose.perform_search?
end

#update_pose_wordsObject

Helper method. Updates the search words with the text returned by search_strings.



58
59
60
61
# File 'lib/pose/model_class_additions.rb', line 58

def update_pose_words
  self.pose_words.delete(Word.factory(pose_stale_words true))
  self.pose_words << Word.factory(pose_words_to_add)
end