cocina-models 0.101.0 → 0.101.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cocina/models/builders/title_builder.rb +22 -11
- data/lib/cocina/models/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020bb1af47ff01f6e95a8d126cabaae16a19a1cd92ae8bdade1e18f97f519af6
|
4
|
+
data.tar.gz: e05e3b0a0a6122a1297fe3d12e3b9737b618ed03ae246d8b4b24e0740254ad9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd8a640dfe907eaebfc3f0b6b72f044b8b149718601d8845b315d529f861634fc0ce194f684236802e2799378a5a01920d8facf7f3669a95ac9e6d1ede066ce5
|
7
|
+
data.tar.gz: eb7d1fc6c14ebadb308e7c7b53f00640d20de07ca337523e33cc77e7b039b00d737fa94079282e29254c8f46b6dffb654ae5c3c5dbfb7fe5cc7cabc592e1fa93
|
data/Gemfile.lock
CHANGED
@@ -8,26 +8,28 @@ module Cocina
|
|
8
8
|
# TitleBuilder selects the prefered title from the cocina object for solr indexing
|
9
9
|
class TitleBuilder # rubocop:disable Metrics/ClassLength
|
10
10
|
extend Deprecation
|
11
|
-
# @param [
|
11
|
+
# @param [Array<Cocina::Models::Title,Cocina::Models::DescriptiveValue>] titles the titles to consider
|
12
|
+
# @param [Array<Cocina::Models::FolioCatalogLink>] catalog_links the folio catalog links to check for digital serials part labels
|
12
13
|
# @param [Symbol] strategy ":first" is the strategy for selection when primary or display
|
13
14
|
# title are missing
|
14
15
|
# @param [Boolean] add_punctuation determines if the title should be formmated with punctuation
|
15
16
|
# @return [String, Array] the title value for Solr - for :first strategy, a string; for :all strategy, an array
|
16
17
|
# (e.g. title displayed in blacklight search results vs boosting values for search result rankings)
|
17
|
-
def self.build(titles, strategy: :first, add_punctuation: true)
|
18
|
+
def self.build(titles, catalog_links: [], strategy: :first, add_punctuation: true)
|
19
|
+
part_label = catalog_links.find { |link| link.catalog == 'folio' }&.partLabel
|
18
20
|
if titles.respond_to?(:description)
|
19
21
|
Deprecation.warn(self,
|
20
22
|
"Calling TitleBuilder.build with a #{titles.class} is deprecated. " \
|
21
23
|
'It must be called with an array of titles')
|
22
24
|
titles = titles.description.title
|
23
25
|
end
|
24
|
-
new(strategy: strategy, add_punctuation: add_punctuation).build(titles)
|
26
|
+
new(strategy: strategy, add_punctuation: add_punctuation, part_label: part_label).build(titles)
|
25
27
|
end
|
26
28
|
|
27
29
|
# the "main title" is the title withOUT subtitle, part name, etc. We want to index it separately so
|
28
30
|
# we can boost matches on it in search results (boost matching this string higher than matching full title string)
|
29
31
|
# e.g. "The Hobbit" (main_title) vs "The Hobbit, or, There and Back Again (full_title)
|
30
|
-
# @param [
|
32
|
+
# @param [Array<Cocina::Models::Title,Cocina::Models::DescriptiveValue>] titles the titles to consider
|
31
33
|
# @return [Array<String>] the main title value(s) for Solr - array due to possible parallelValue
|
32
34
|
def self.main_title(titles)
|
33
35
|
new(strategy: :first, add_punctuation: false).main_title(titles)
|
@@ -35,7 +37,7 @@ module Cocina
|
|
35
37
|
|
36
38
|
# the "full title" is the title WITH subtitle, part name, etc. We want to able able to index it separately so
|
37
39
|
# we can boost matches on it in search results (boost matching this string higher than other titles present)
|
38
|
-
# @param [
|
40
|
+
# @param [Array<Cocina::Models::Title,Cocina::Models::DescriptiveValue>] titles the titles to consider
|
39
41
|
# @return [Array<String>] the full title value(s) for Solr - array due to possible parallelValue
|
40
42
|
def self.full_title(titles)
|
41
43
|
[new(strategy: :first, add_punctuation: false, only_one_parallel_value: false).build(titles)].flatten.compact
|
@@ -43,7 +45,7 @@ module Cocina
|
|
43
45
|
|
44
46
|
# "additional titles" are all title data except for full_title. We want to able able to index it separately so
|
45
47
|
# we can boost matches on it in search results (boost matching these strings lower than other titles present)
|
46
|
-
# @param [
|
48
|
+
# @param [Array<Cocina::Models::Title,Cocina::Models::DescriptiveValue>] titles the titles to consider
|
47
49
|
# @return [Array<String>] the values for Solr
|
48
50
|
def self.additional_titles(titles)
|
49
51
|
[new(strategy: :all, add_punctuation: false).build(titles)].flatten - full_title(titles)
|
@@ -57,13 +59,16 @@ module Cocina
|
|
57
59
|
# of primary, untyped, first occurrence. When false, return an array containing all the parallel values.
|
58
60
|
# Why? Think of e.g. title displayed in blacklight search results vs boosting values for ranking of search
|
59
61
|
# results
|
60
|
-
|
62
|
+
# @param part_label [String] the partLabel to add for digital serials display
|
63
|
+
def initialize(strategy:, add_punctuation:, only_one_parallel_value: true, part_label: nil)
|
61
64
|
@strategy = strategy
|
62
65
|
@add_punctuation = add_punctuation
|
63
66
|
@only_one_parallel_value = only_one_parallel_value
|
67
|
+
@part_label = part_label
|
64
68
|
end
|
65
69
|
|
66
|
-
# @param [
|
70
|
+
# @param [Array<Cocina::Models::Title>] cocina_titles the titles to consider
|
71
|
+
# @param [String, nil] part_label the partLabel to add to the title for digital serials
|
67
72
|
# @return [String, Array] the title value for Solr - for :first strategy, a string; for :all strategy, an array
|
68
73
|
# (e.g. title displayed in blacklight search results vs boosting values for search result rankings)
|
69
74
|
#
|
@@ -71,9 +76,9 @@ module Cocina
|
|
71
76
|
def build(cocina_titles)
|
72
77
|
cocina_title = primary_title(cocina_titles) || untyped_title(cocina_titles)
|
73
78
|
cocina_title = other_title(cocina_titles) if cocina_title.blank?
|
74
|
-
|
75
79
|
if strategy == :first
|
76
|
-
extract_title(cocina_title)
|
80
|
+
result = extract_title(cocina_title)
|
81
|
+
add_part_label(result)
|
77
82
|
else
|
78
83
|
result = cocina_titles.map { |ctitle| extract_title(ctitle) }.flatten
|
79
84
|
if only_one_parallel_value? && result.length == 1
|
@@ -97,7 +102,13 @@ module Cocina
|
|
97
102
|
|
98
103
|
private
|
99
104
|
|
100
|
-
attr_reader :strategy
|
105
|
+
attr_reader :strategy, :part_label
|
106
|
+
|
107
|
+
def add_part_label(title)
|
108
|
+
# when a digital serial
|
109
|
+
title = "#{title.sub(/[ .,]*$/, '')}, #{part_label}" if part_label.present?
|
110
|
+
title
|
111
|
+
end
|
101
112
|
|
102
113
|
def extract_title(cocina_title)
|
103
114
|
title_values = if cocina_title.value
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocina-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.101.
|
4
|
+
version: 0.101.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-18 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|