Skip to content

Commit

Permalink
Assign default when title is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Nov 26, 2024
1 parent 2fb2e09 commit f28c8ca
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule DpulCollections.IndexingPipeline.Figgy.HydrationCacheEntry do

%{
id: id,
title_txtm: get_in(metadata, ["title"]),
title_txtm: extract_title(metadata),
description_txtm: get_in(metadata, ["description"]),
years_is: extract_years(data),
display_date_s: format_date(metadata),
Expand All @@ -49,6 +49,8 @@ defmodule DpulCollections.IndexingPipeline.Figgy.HydrationCacheEntry do
extract_service_url(member_data[id])
end

defp extract_service_url(_id, _), do: nil

# Find the derivative FileMetadata
defp extract_service_url(%{
"internal_resource" => "FileSet",
Expand Down Expand Up @@ -82,7 +84,11 @@ defmodule DpulCollections.IndexingPipeline.Figgy.HydrationCacheEntry do

defp extract_service_url(nil), do: nil

defp extract_service_url(_id, _), do: nil
def extract_title(%{"title" => []}) do
["[Missing Title]"]
end

def extract_title(%{"title" => title}), do: title

defp is_derivative(%{
"mime_type" => ["image/tiff"],
Expand Down
8 changes: 7 additions & 1 deletion lib/dpul_collections/solr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ defmodule DpulCollections.Solr do
end

@spec add(list(map()), String.t()) :: {:ok, Req.Response.t()} | {:error, Exception.t()}
def add(docs, collection \\ read_collection()) when length(docs) > 1 do
def add(docs, collection \\ read_collection())

def add(docs, collection) when length(docs) > 1 do
response =
Req.post!(
update_url(collection),
Expand All @@ -108,6 +110,8 @@ defmodule DpulCollections.Solr do
if response.status != 200 do
Enum.each(docs, fn doc -> add([doc]) end)
end

response
end

def add(docs, collection) when length(docs) when length(docs) == 1 do
Expand All @@ -121,6 +125,8 @@ defmodule DpulCollections.Solr do
doc = docs |> Enum.at(0)
Logger.warning("error indexing solr document with id: #{doc["id"]} #{response.body}")
end

response
end

@spec commit(String.t()) :: {:ok, Req.Response.t()} | {:error, Exception.t()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,24 @@ defmodule DpulCollections.IndexingPipeline.Figgy.HydrationCacheEntryTest do
assert capture_log(fn -> HydrationCacheEntry.to_solr_document(entry) end) =~
"couldn't parse date"
end

test "an empty solr document is returned with a empty title field" 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" => %{
"title" => [],
"date_created" => ["2022"]
}
}
})

assert %{title_txtm: ["[Missing Title]"]} = HydrationCacheEntry.to_solr_document(entry)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ defmodule DpulCollections.IndexingPipeline.Figgy.IndexingIntegrationTest do
indexer |> Broadway.stop(:normal)
end

test "when cache entry has an empty document, solr doesn't index it or return an error" do
IndexingPipeline.write_transformation_cache_entry(%{
cache_version: 0,
record_id: "17276197-e223-471c-99d7-405c5f6c5285",
source_cache_order: ~U[1999-03-09 20:19:34.486004Z],
data: %{}
})

indexer = start_indexing_producer()
MockFiggyIndexingProducer.process(1)
assert_receive {:ack_done}, 500
Solr.commit(active_collection())
assert Solr.document_count() == 0
indexer |> Broadway.stop(:normal)
end

test "solr collection creation" do
cache_version = 0
new_collection = "new_index1"
Expand Down
2 changes: 0 additions & 2 deletions test/dpul_collections/solr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ defmodule DpulCollections.SolrTest do
"id" => "3cb7627b-defc-401b-9959-42ebc4488f74"
}

# Solr.commit(active_collection())

assert capture_log(fn -> Solr.add([doc], active_collection()) end) =~
"error indexing solr document"
end
Expand Down

0 comments on commit f28c8ca

Please sign in to comment.