Class: ArticleFaq
- Inherits:
-
Article
- Object
- ActiveRecord::Base
- ApplicationRecord
- Article
- ArticleFaq
- Defined in:
- app/models/article_faq.rb
Overview
== Schema Information
Table name: articles
Database name: primary
id :integer not null, primary key
applies_to_product_category_ids :integer default([]), is an Array
applies_to_product_line_ids :integer default([]), is an Array
archived_at :datetime
auto_sanitize_html :boolean default(TRUE), not null
auto_sanitize_urls :boolean default(TRUE), not null
breadcrumbs :string default([]), not null, is an Array
department :string
description :text
has_toc :boolean default(FALSE), not null
inline_js :text
link_audit_result :jsonb
meta_description :string
meta_keywords :string
objective :text
problem_code :string(255)
publish_on :datetime
published_at :datetime
reading_time_minutes :integer
requires_seo_check :boolean default(FALSE), not null
revised_at :datetime
sales :boolean default(TRUE), not null
schema_extracted_at :datetime
schema_markup :jsonb
search_text :text
search_text_tsv :tsvector
seo_report :jsonb
serial_number_high_range :integer
serial_number_low_range :integer
short_url :string
short_url_with_ref :string
slug :string
slug_custom :string
solution :text
sort_booster :integer default(0), not null
state :string(20) default("draft")
subject :string(255) not null
support :boolean default(FALSE), not null
time_required :integer
title :string
toc_selector :string
type :string
version :integer
warranty_labor :boolean
warranty_parts :boolean
word_count :integer
created_at :datetime
updated_at :datetime
active_revision_id :bigint
brafton_id :integer
creator_id :integer
draft_revision_id :bigint
original_author_id :integer
precursor_id :integer
preview_image_id :string
related_article_1_id :integer
related_article_2_id :integer
related_article_3_id :integer
related_article_4_id :integer
source_id :integer
successor_article_id :integer
updater_id :integer
user_id :integer
Indexes
idx_articles_type_state_id (type,state,id)
idx_source_id_type (source_id,type)
idx_state_type_publish_on (state,type,publish_on)
index_articles_on_active_revision_id (active_revision_id)
index_articles_on_draft_revision_id (draft_revision_id)
index_articles_on_published_at (published_at) USING brin
index_articles_on_revised_at (revised_at)
index_articles_on_search_text_tsv (search_text_tsv) USING gin
index_articles_on_successor_article_id (successor_article_id)
index_articles_on_type_and_slug_unique (type,slug) UNIQUE
Foreign Keys
fk_rails_... (id => articles.id)
fk_rails_... (related_article_1_id => articles.id) ON DELETE => nullify
fk_rails_... (related_article_2_id => articles.id) ON DELETE => nullify
fk_rails_... (related_article_3_id => articles.id) ON DELETE => nullify
fk_rails_... (related_article_4_id => articles.id)
fk_rails_... (source_id => sources.id)
fk_rails_... (successor_article_id => articles.id)
Constant Summary collapse
- FAQ_MAX_WORDS =
150- FAQ_TARGET_WORDS =
(40..60).freeze
- FAQ_WARN_WORDS =
100- FAQ_WORD_COUNT_SQL =
"array_length(regexp_split_to_array(trim(regexp_replace(COALESCE(articles.solution,''), '<[^>]*>', ' ', 'g')), '\\s+'), 1)"
Constants inherited from Article
Constants included from Models::Embeddable
Models::Embeddable::DEFAULT_MODEL, Models::Embeddable::MAX_CONTENT_LENGTH
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary
Attributes inherited from Article
#schema_markup, #serial_number_high_range, #serial_number_low_range, #subject
Class Method Summary collapse
-
.embedded_in_posts ⇒ ActiveRecord::Relation<ArticleFaq>
A relation of ArticleFaqs that are embedded in posts.
-
.orphan_faqs ⇒ ActiveRecord::Relation<ArticleFaq>
A relation of ArticleFaqs that are orphan faqs.
-
.over_word_limit ⇒ ActiveRecord::Relation<ArticleFaq>
A relation of ArticleFaqs that are over word limit.
Instance Method Summary collapse
Methods inherited from Article
#active_revision, all_product_lines, #applicable_product_category_urls, #applicable_product_line_urls, archived, #article_pages, #author, available_schema_types, #breadcrumbs_hash, #content_for_embedding, drafts, due_for_publishing, #effective_published_date, #effective_revised_date, #email_url, embeddable_content_types, #embedded_assets, #embedding_type_name, #events_for_select, faqs, #file_name, for_item_sku, for_product_category_url_without_order, for_product_line_url, for_product_line_url_with_ancestors, for_product_line_url_with_descendants, for_product_line_url_without_order, for_product_line_urls_with_descendants, for_sales_portal, for_support_portal, #full_localized_solution, #generate_pdf, #get_img_src_urls, has_comments, has_schema, has_video, #item_product_lines, #items, #latest_revision, #link_checks, #liquid_variable_context, #localize_price, #localized_solution, #localized_solution_html_doc, most_recent_first, no_schema, #normalize_friendly_id, not_for_public, #ok_to_delete?, options_for_select, #original_author, #page_title, #possible_events, #possible_events_for_select, #post_comments, #precursor, press_industry_reports, press_releases, #preview_image, #primary_site_map, #procedure?, procedure_types, #process_product_embeds, #product_categories, #product_lines, publish_posts_due_for_publishing, published, #purge_edge_cache, ransackable_scopes, #reading_time_in_minutes, reading_time_options, #related_articles_for_display, #related_articles_for_select, #restore_revision!, #revisions, #rma_reason_code, #sanitize_urls, #schema_dot_org_images, #schema_dot_org_structure_faq, schema_types_in, #send_creation_email, #send_update_email, #seo_clicks, #seo_keywords_count, #seo_last_synced_at, #seo_metrics_synced?, #seo_top_keyword, #seo_top_position, #seo_traffic, #seo_traffic_value, #should_generate_new_friendly_id?, #site_maps, #slug_candidates, slug_find, #snapshot_revision!, #solution_text, sorted_by_most_recent_first, sorted_with_booster, states_for_select, #subject_with_type, #successor_article, #successors, #to_json_ld, #to_json_raw, #topics, types_options, types_options_for_search, #uploads, #user, #uses_revisions?, #visit_count_30d, #votes, waiting_to_publish, with_votes
Methods included from Models::CrossLinkable
#content_links_count, #inbound_content_links, #linked_content, #linked_posts, #linked_publications, #linked_showcases, #linked_videos, #outbound_content_links
Methods included from Models::Taggable
#add_tag, all_tags, #has_tag?, normalize_tag_names, not_tagged_with, #remove_tag, #tag_list, #tag_list=, #tag_records, #taggable_type_for_tagging, tagged_with, #taggings, #tags, #tags=, tags_cloud, tags_exclude, tags_include, with_all_tags, with_any_tags, without_all_tags, without_any_tags
Methods included from Models::Embeddable
#content_embeddings, #content_for_embedding, embeddable_content_types, #embeddable_locales, #embedding_content_hash, embedding_partition_class, #embedding_stale?, #embedding_type_name, #embedding_vector, #find_content_embedding, #find_similar, #generate_all_embeddings!, #generate_chunked_embeddings!, #generate_embedding!, #has_embedding?, #locale_for_embedding, #needs_chunking?, regenerate_all_embeddings, semantic_search
Methods included from Models::SchemaMarkup
#add_schema, #clear_schema_markup, #consolidated_faq_page_schema, #content_has_embedded_faq_schema?, #embedded_faq_ids_from_content, #has_schema_type?, #render_schema_markup, #schema_count, #schema_types, #schemas_by_type
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #creator, #should_not_save_version, #stamp_record, #updater
Methods included from Models::Lineage
#ancestors, #ancestors_ids, #children_and_roots, #descendants, #descendants_ids, #ensure_non_recursive_lineage, #family_members, #generate_full_name, #generate_full_name_array, #lineage, #lineage_array, #lineage_simple, #root, #root_id, #self_ancestors_and_descendants, #self_ancestors_and_descendants_ids, #self_and_ancestors, #self_and_ancestors_ids, #self_and_children, #self_and_descendants, #self_and_descendants_ids, #self_and_siblings, #self_and_siblings_ids, #siblings, #siblings_ids
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Class Method Details
.embedded_in_posts ⇒ ActiveRecord::Relation<ArticleFaq>
A relation of ArticleFaqs that are embedded in posts. Active Record Scope
118 119 120 121 122 123 124 125 126 |
# File 'app/models/article_faq.rb', line 118 scope :embedded_in_posts, ->(value = 'true') { case value when 'true' where("EXISTS (SELECT 1 FROM embedded_assets ea WHERE ea.asset_id = articles.id AND ea.asset_type = 'Article' AND ea.type = 'EmbeddedFaqAsset')") when 'false' where("NOT EXISTS (SELECT 1 FROM embedded_assets ea WHERE ea.asset_id = articles.id AND ea.asset_type = 'Article' AND ea.type = 'EmbeddedFaqAsset')") else all end } |
.orphan_faqs ⇒ ActiveRecord::Relation<ArticleFaq>
A relation of ArticleFaqs that are orphan faqs. Active Record Scope
108 109 110 111 112 113 114 115 116 |
# File 'app/models/article_faq.rb', line 108 scope :orphan_faqs, ->(value = 'true') { return all unless value == 'true' where(sales: false, support: false) .where_not_exists(:product_lines) .where_not_exists(:items) .where("NOT EXISTS (SELECT 1 FROM taggings t WHERE t.taggable_id = articles.id AND t.taggable_type = '#{name}')") .where("NOT EXISTS (SELECT 1 FROM embedded_assets ea WHERE ea.asset_id = articles.id AND ea.asset_type = 'Article' AND ea.type = 'EmbeddedFaqAsset')") } |
.over_word_limit ⇒ ActiveRecord::Relation<ArticleFaq>
A relation of ArticleFaqs that are over word limit. Active Record Scope
100 101 102 103 104 105 106 |
# File 'app/models/article_faq.rb', line 100 scope :over_word_limit, ->(value = 'true') { case value when 'true' then where("#{FAQ_WORD_COUNT_SQL} > #{FAQ_MAX_WORDS}") when 'false' then where("#{FAQ_WORD_COUNT_SQL} <= #{FAQ_MAX_WORDS} OR articles.solution IS NULL") else all end } |
Instance Method Details
#article_type_human ⇒ Object
146 147 148 |
# File 'app/models/article_faq.rb', line 146 def article_type_human 'Faq' end |
#faq_word_count ⇒ Object
128 129 130 |
# File 'app/models/article_faq.rb', line 128 def faq_word_count word_count || ActionController::Base.helpers.(solution.to_s).split.size end |
#schema_dot_org_structure ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/models/article_faq.rb', line 132 def schema_dot_org_structure = &.schema_dot_org_structure SchemaDotOrg::Question.new.tap do |s| s.name = subject s.text = subject s.dateCreated = created_at s. = s.answerCount = 1 answer_text = localized_solution.to_s.presence s.acceptedAnswer = SchemaDotOrg::Answer.new(text: answer_text, dateCreated: created_at, author: ) if answer_text end end |