diff --git a/lib/dpul_collections/indexing_pipeline/figgy/hydration_cache_entry.ex b/lib/dpul_collections/indexing_pipeline/figgy/hydration_cache_entry.ex index 8628c88e..db5d6ea4 100644 --- a/lib/dpul_collections/indexing_pipeline/figgy/hydration_cache_entry.ex +++ b/lib/dpul_collections/indexing_pipeline/figgy/hydration_cache_entry.ex @@ -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)) diff --git a/test/dpul_collections/indexing_pipeline/figgy/hydration_cache_entry_test.exs b/test/dpul_collections/indexing_pipeline/figgy/hydration_cache_entry_test.exs index 0d5c0d32..7d346ee2 100644 --- a/test/dpul_collections/indexing_pipeline/figgy/hydration_cache_entry_test.exs +++ b/test/dpul_collections/indexing_pipeline/figgy/hydration_cache_entry_test.exs @@ -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