Module: Search::Modules::Ferret::FerretNodeExtension::InstanceMethods
- Defined in:
- app/models/search/modules/ferret/ferret_node_extension.rb
Instance Method Summary (collapse)
- - (Object) ancestry_to_index
-
- (Object) calculate_dynamic_boost_date_factor
Calculates a negative boost factor based on whether the "content date" of the item is "past", "current" or "future".
- - (Object) categories_to_index
-
- (Object) content_title_to_index
Returns the latest approved content title for indexing.
-
- (Object) content_tokens_to_index
Returns the latest approved content tokens for indexing.
-
- (Object) dynamic_boost
Determines the boost factor for indexing based on the node type.
- - (Object) is_hidden_to_index
-
- (Object) path_to_index
Returns the path with ids for this node for indexing.
-
- (Object) publication_end_date_to_index
Returns the publication end date for indexing.
-
- (Object) publication_start_date_to_index
Returns the publication date for indexing.
- - (Object) updated_at_to_index
- - (Object) zipcodes_to_index
Instance Method Details
- (Object) ancestry_to_index
35 36 37 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 35 def ancestry_to_index "XX#{self.ancestry.gsub(/\//, 'X')}X" end |
- (Object) calculate_dynamic_boost_date_factor
Calculates a negative boost factor based on whether the "content date" of the item is "past", "current" or "future".
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 114 def calculate_dynamic_boost_date_factor # Date only matters when the content is a NewsItem, NewsletterEdition, CalendarItem or Meeting instance. unless [ NewsItem, NewsletterEdition, CalendarItem, Meeting ].any? { |type| content.is_a?(type) } boost_factor = 1 else today = Date.today content_date = determine_content_date(today) # If it's a future or past item, we apply different (negative) boost factors. if content_date > today boost_factor = (1 / (1 + Math.log((0.1 * (content_date - today).to_i) + 1))) elsif content_date < today boost_factor = (1 / (1 + Math.log((0.15 * (today - content_date).to_i) + 1))) # If the item is current, we do not apply a negative boost factor. else boost_factor = 1 end end boost_factor end |
- (Object) categories_to_index
54 55 56 57 58 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 54 def categories_to_index cats = self.categories.collect(&:id) cats + self.categories.collect { |cat| cat.parent }.compact.uniq "XX#{cats.uniq.join("X")}XX" end |
- (Object) content_title_to_index
Returns the latest approved content title for indexing.
50 51 52 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 50 def content_title_to_index approved_content.content_title end |
- (Object) content_tokens_to_index
Returns the latest approved content tokens for indexing.
71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 71 def content_tokens_to_index begin result = help.(approved_content.content_tokens) # Strip any HTML and JavaScript and replace whitespace characters (including newlines) with a single space. result = help.sanitize(result.gsub(/[[:space:]]/, ' ').gsub(/[[:space:]]{2,}/, ' ')) return result.strip rescue return '' end end |
- (Object) dynamic_boost
Determines the boost factor for indexing based on the node type.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 93 def dynamic_boost boost = 1.0 # default boost case content_class when Image # is less important than its parent, which may share the same name boost -= 0.5 end # Content that has a nil body but a matching title will be ranked very high # because the hits/size ratio is high. Normally however nil body content # isn't all that interesting, so decrease its boost a bit. if self.content_tokens_to_index.length == 0 boost -= 0.2 end boost = boost * calculate_dynamic_boost_date_factor boost >= 0.1 ? boost : 0.1 end |
- (Object) is_hidden_to_index
39 40 41 42 43 44 45 46 47 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 39 def is_hidden_to_index hidden_from_index = false Settler[:ferret_exclude_node_ids].split(",").each do |nid| hidden_from_index = hidden_from_index || self.path_ids.include?(nid.to_i) end if Settler[:ferret_exclude_node_ids].present? self.is_hidden? || hidden_from_index ? 'true' : 'false' end |
- (Object) path_to_index
Returns the path with ids for this node for indexing.
31 32 33 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 31 def path_to_index "/#{self.self_and_ancestors.collect(&:id).join("/")}/" end |
- (Object) publication_end_date_to_index
Returns the publication end date for indexing
88 89 90 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 88 def publication_end_date_to_index self.publication_end_date.nil? ? 'none' : self.publication_end_date.strftime(Node::INDEX_DATETIME_FORMAT) end |
- (Object) publication_start_date_to_index
Returns the publication date for indexing.
83 84 85 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 83 def publication_start_date_to_index self.publication_start_date.strftime(Node::INDEX_DATETIME_FORMAT) end |
- (Object) updated_at_to_index
66 67 68 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 66 def updated_at_to_index self.updated_at.strftime(Node::INDEX_DATETIME_FORMAT) end |
- (Object) zipcodes_to_index
60 61 62 63 64 |
# File 'app/models/search/modules/ferret/ferret_node_extension.rb', line 60 def zipcodes_to_index if self.content_type == "Permit" self.content.addresses.collect { |address| address.postal_code } end end |