Skip to content

Commit

Permalink
Validate that solr doc has title
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Nov 25, 2024
1 parent 2fb2e09 commit 32ac1bb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ defmodule DpulCollections.IndexingPipeline.Figgy.HydrationCacheEntry do
page_count_i: page_count(metadata),
image_service_urls_ss: image_service_urls(metadata, related_data)
}
|> validate_solr_document()
end

defp validate_solr_document(%{id: id, title_txtm: nil}) do
Logger.warning("Solr document is missing title: #{id}")
nil
end

defp validate_solr_document(doc), do: doc

defp image_service_urls(%{"member_ids" => member_ids}, related_data) do
member_ids
|> Enum.map(&extract_service_url(&1, related_data))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,43 @@ defmodule DpulCollections.IndexingPipeline.Figgy.HydrationCacheEntryTest do
assert capture_log(fn -> HydrationCacheEntry.to_solr_document(entry) end) =~
"couldn't parse date"
end

@tag capture_log: true
test "a nil value is returned when a solr document is missing a title" do
{:ok, entry} =
IndexingPipeline.write_hydration_cache_entry(%{
cache_version: 0,
record_id: "f134f41f-63c5-4fdf-b801-0774e3bc3b2d",
source_cache_order: ~U[2018-03-09 20:19:36.465203Z],
data: %{
"id" => "f134f41f-63c5-4fdf-b801-0774e3bc3b2d",
"internal_resource" => "EphemeraFolder",
"metadata" => %{
"date_created" => ["2022"]
}
}
})

assert HydrationCacheEntry.to_solr_document(entry) == nil
end

test "a message is logged when a solr document is missing a title" do
{:ok, entry} =
IndexingPipeline.write_hydration_cache_entry(%{
cache_version: 0,
record_id: "f134f41f-63c5-4fdf-b801-0774e3bc3b2d",
source_cache_order: ~U[2018-03-09 20:19:36.465203Z],
data: %{
"id" => "f134f41f-63c5-4fdf-b801-0774e3bc3b2d",
"internal_resource" => "EphemeraFolder",
"metadata" => %{
"date_created" => ["2022"]
}
}
})

assert capture_log(fn -> HydrationCacheEntry.to_solr_document(entry) end) =~
"missing title: f134f41f-63c5-4fdf-b801-0774e3bc3b2d"
end
end
end

0 comments on commit 32ac1bb

Please sign in to comment.