Skip to content

Commit

Permalink
Merge pull request #658 from sul-dlss/additional_titles
Browse files Browse the repository at this point in the history
titleBuilder: additional_titles passes tests, a few more tweaks to .build method
  • Loading branch information
aaron-collier authored Dec 20, 2023
2 parents 59e838f + ef84950 commit 6359e2d
Show file tree
Hide file tree
Showing 2 changed files with 287 additions and 26 deletions.
13 changes: 11 additions & 2 deletions lib/cocina/models/builders/title_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def self.full_title(titles)
new(strategy: :first, add_punctuation: false).build(titles)
end

# "additional titles" are all title data except for full_title. We want to able able to index it separately so
# we can boost matches on it in search results (boost matching these strings lower than other titles present)
# @param [[Array<Cocina::Models::Title,Cocina::Models::DescriptiveValue>] titles the titles to consider
# @return [Array<String>] the values for Solr
def self.additional_titles(titles)
new(strategy: :all, add_punctuation: false).build(titles) - [full_title(titles)]
end

def initialize(strategy:, add_punctuation:)
@strategy = strategy
@add_punctuation = add_punctuation
Expand All @@ -54,7 +62,7 @@ def build(cocina_titles)
if strategy == :first
extract_title(cocina_title)
else
cocina_titles.map { |one| extract_title(one) }
cocina_titles.map { |ctitle| extract_title(ctitle) }.flatten
end
end

Expand Down Expand Up @@ -127,7 +135,8 @@ def untyped_title_for(titles)
end
end

# This handles 'main title', 'uniform' or 'translated'
# This is called when there is no primary title and no untyped title
# @return [Cocina::Models::Title, Array<Cocina::Models::Title>] first title or all titles
def other_title(titles)
if strategy == :first
titles.first
Expand Down
Loading

0 comments on commit 6359e2d

Please sign in to comment.