Skip to content

Commit

Permalink
Merge pull request #68 from alphagov/attachments-extra
Browse files Browse the repository at this point in the history
Extract attachment fields into additional searchable text
  • Loading branch information
csutter authored Oct 26, 2023
2 parents 2d29d08 + 87dddff commit f2de0a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/document_sync_worker/document/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Publish < Base
$.details.metadata.hidden_indexable_content
$.details.metadata.project_code
$.details.acronym
$.details.attachments[*].title
$.details.attachments[*]['title','isbn','unique_reference','command_paper_number','hoc_paper_number']
].map { JsonPath.new(_1) }.freeze
ADDITIONAL_SEARCHABLE_TEXT_VALUES_SEPARATOR = "\n".freeze

Expand Down Expand Up @@ -88,7 +88,10 @@ def url

def additional_searchable_text
values = ADDITIONAL_SEARCHABLE_TEXT_VALUES_JSON_PATHS.map { _1.on(document_hash) }
values.flatten.join(ADDITIONAL_SEARCHABLE_TEXT_VALUES_SEPARATOR)
values
.flatten
.compact_blank
.join(ADDITIONAL_SEARCHABLE_TEXT_VALUES_SEPARATOR)
end

def public_timestamp
Expand Down
16 changes: 13 additions & 3 deletions spec/lib/document_sync_worker/document/publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,24 @@
{
"details" => {
"attachments" => [
{ "title" => "A report" },
{ "title" => "Another report" },
{
"title" => "A report",
"isbn" => "1234567890123",
"unique_reference" => "ABCDEF",
"command_paper_number" => "",
},
{
"title" => "Another report",
"isbn" => "",
"command_paper_number" => "CPN1234",
"hoc_paper_number" => "ADHOC",
},
],
},
}
end

it { is_expected.to eq("A report\nAnother report") }
it { is_expected.to eq("A report\n1234567890123\nABCDEF\nAnother report\nCPN1234\nADHOC") }
end
end

Expand Down

0 comments on commit f2de0a6

Please sign in to comment.