Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure all body content can have multiple types #124

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/models/concerns/publishing_api/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ module Content

# Extracts a single string of indexable unstructured content from the document.
def content
values_from_json_paths = INDEXABLE_CONTENT_VALUES_JSON_PATHS.map { _1.on(document_hash) }
values_from_parts = document_hash.dig(:details, :parts)&.map do
values_from_json_paths = INDEXABLE_CONTENT_VALUES_JSON_PATHS.map do |item|
item.on(document_hash).map { |body| BodyContent.new(body).html_content }
end
values_from_parts = document_hash.dig(:details, :parts)&.map do |part|
# Add the part title as a heading to help the search model better understand the structure
# of the content
["<h1>#{_1[:title]}</h1>", BodyContent.new(_1[:body]).html_content]
["<h1>#{part[:title]}</h1>", BodyContent.new(part[:body]).html_content]
end

[*values_from_json_paths, *values_from_parts]
.flatten
.compact
.join(INDEXABLE_CONTENT_SEPARATOR)
.truncate_bytes(INDEXABLE_CONTENT_MAX_BYTE_SIZE)
end
Expand Down
Loading