europeana-blacklight 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/europeana-blacklight.gemspec +1 -1
- data/lib/europeana/blacklight/document.rb +2 -43
- data/lib/europeana/blacklight/document/lang_maps.rb +65 -0
- data/lib/europeana/blacklight/document/more_like_this.rb +6 -2
- data/lib/europeana/blacklight/search_builder.rb +17 -7
- data/lib/europeana/blacklight/search_helper.rb +5 -3
- data/lib/europeana/blacklight/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c009d6e64d47908e4814d19edf92c58764e208e
|
4
|
+
data.tar.gz: dae88754b44e1fabf5ba8dd7731559c4aa3fef18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8795c06e1000dc9af5538daca798639ccf323db798aa08a2f3708ffc81fb77f390ae929cbe7b74f70a9f1ebf6bd9f1a9593090cc2a7c7a7c65d6aabe17e01cbf
|
7
|
+
data.tar.gz: b93869c448d02abb45e6cc847bcf65c630988a62a5c261b9d9006ea9afc77bfe680d50de7d106787e5669e3dd39f181e52d809df0c2a0b8f8cc12c3fd210672b
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = '>= 2.0.0'
|
22
22
|
|
23
23
|
spec.add_dependency 'activesupport', '>= 4.0', '< 5.0'
|
24
|
-
spec.add_dependency 'blacklight', '>= 5.12.0', '<
|
24
|
+
spec.add_dependency 'blacklight', '>= 5.12.0', '< 6.0'
|
25
25
|
spec.add_dependency 'europeana-api', '~> 0.4.1'
|
26
26
|
spec.add_dependency 'iso-639', '~> 0.2.5'
|
27
27
|
spec.add_dependency 'kaminari', '~> 0.16'
|
@@ -7,59 +7,20 @@ module Europeana
|
|
7
7
|
##
|
8
8
|
# A Europeana document
|
9
9
|
class Document
|
10
|
+
autoload :LangMaps, 'europeana/blacklight/document/lang_maps'
|
10
11
|
autoload :MoreLikeThis, 'europeana/blacklight/document/more_like_this'
|
11
12
|
autoload :Relations, 'europeana/blacklight/document/relations'
|
12
13
|
|
13
14
|
include ActiveModel::Conversion
|
14
15
|
include ::Blacklight::Document
|
15
16
|
include ::Blacklight::Document::ActiveModelShim
|
17
|
+
include LangMaps
|
16
18
|
include MoreLikeThis
|
17
19
|
include Relations
|
18
20
|
|
19
21
|
attr_writer :provider_id, :record_id
|
20
22
|
|
21
23
|
class << self
|
22
|
-
# @todo Are three-letter language codes valid in EDM?
|
23
|
-
# @todo Empty key acceptance is a workaround for malformed API data
|
24
|
-
# output; remove when fixed at source
|
25
|
-
def lang_map?(obj)
|
26
|
-
return false unless obj.is_a?(Hash)
|
27
|
-
obj.keys.map(&:to_s).all? { |key| known_lang_map_key?(key) }
|
28
|
-
end
|
29
|
-
|
30
|
-
def known_lang_map_key?(key)
|
31
|
-
key = key.dup.downcase
|
32
|
-
['def', '', 'sh'].include?(key) || (!ISO_639.find(key.split('-').first).nil?)
|
33
|
-
end
|
34
|
-
|
35
|
-
def localize_lang_map(lang_map)
|
36
|
-
if lang_map.is_a?(Array)
|
37
|
-
return lang_map.map { |l| localize_lang_map(l) }
|
38
|
-
end
|
39
|
-
|
40
|
-
return lang_map unless lang_map?(lang_map)
|
41
|
-
|
42
|
-
lang_map_value(lang_map, I18n.locale.to_s) ||
|
43
|
-
lang_map_value(lang_map, I18n.default_locale.to_s) ||
|
44
|
-
lang_map[:def] ||
|
45
|
-
lang_map.values
|
46
|
-
end
|
47
|
-
|
48
|
-
def lang_map_value(lang_map, locale)
|
49
|
-
iso_locale = ISO_639.find(locale)
|
50
|
-
return nil unless lang_map.key?(iso_locale.alpha2) || lang_map.key?(iso_locale.alpha3)
|
51
|
-
|
52
|
-
alpha2 = lang_map[iso_locale.alpha2]
|
53
|
-
alpha3 = lang_map[iso_locale.alpha3]
|
54
|
-
if alpha2 && alpha3
|
55
|
-
[alpha2, alpha3].flatten
|
56
|
-
elsif alpha2
|
57
|
-
alpha2
|
58
|
-
else
|
59
|
-
alpha3
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
24
|
def model_name
|
64
25
|
@_model_name ||= begin
|
65
26
|
ActiveModel::Name.new(self, nil, 'Document')
|
@@ -67,8 +28,6 @@ module Europeana
|
|
67
28
|
end
|
68
29
|
end
|
69
30
|
|
70
|
-
delegate :lang_map?, :localize_lang_map, to: :class
|
71
|
-
|
72
31
|
def initialize(source_doc = {}, response = nil)
|
73
32
|
fields, @relations = extract_relations(source_doc)
|
74
33
|
super(fields, response)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Europeana
|
2
|
+
module Blacklight
|
3
|
+
class Document
|
4
|
+
##
|
5
|
+
# Methods for working with "LangMap" data types in API JSON responses
|
6
|
+
# @see http://labs.europeana.eu/api/getting-started#datatypes
|
7
|
+
module LangMaps
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
# @see https://www.loc.gov/standards/iso639-2/php/code_changes.php
|
11
|
+
DEPRECATED_ISO_LANG_CODES = %w(in iw jaw ji jw mo mol scc scr sh)
|
12
|
+
|
13
|
+
# Special keys API may return in a LangMap, not ISO codes
|
14
|
+
# @todo Empty key acceptance is a workaround for malformed API data
|
15
|
+
# output; remove when fixed at source
|
16
|
+
NON_ISO_LANG_CODES = ['def', '']
|
17
|
+
|
18
|
+
class_methods do
|
19
|
+
# @todo Are three-letter language codes valid in EDM?
|
20
|
+
def lang_map?(obj)
|
21
|
+
return false unless obj.is_a?(Hash)
|
22
|
+
obj.keys.map(&:to_s).all? { |key| known_lang_map_key?(key) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def known_lang_map_key?(key)
|
26
|
+
key = key.dup.downcase
|
27
|
+
DEPRECATED_ISO_LANG_CODES.include?(key) ||
|
28
|
+
NON_ISO_LANG_CODES.include?(key) ||
|
29
|
+
(!ISO_639.find(key.split('-').first).nil?)
|
30
|
+
end
|
31
|
+
|
32
|
+
def localize_lang_map(lang_map)
|
33
|
+
if lang_map.is_a?(Array)
|
34
|
+
return lang_map.map { |l| localize_lang_map(l) }
|
35
|
+
end
|
36
|
+
|
37
|
+
return lang_map unless lang_map?(lang_map)
|
38
|
+
|
39
|
+
lang_map_value(lang_map, I18n.locale.to_s) ||
|
40
|
+
lang_map_value(lang_map, I18n.default_locale.to_s) ||
|
41
|
+
lang_map[:def] ||
|
42
|
+
lang_map.values
|
43
|
+
end
|
44
|
+
|
45
|
+
def lang_map_value(lang_map, locale)
|
46
|
+
iso_locale = ISO_639.find(locale)
|
47
|
+
return nil unless lang_map.key?(iso_locale.alpha2) || lang_map.key?(iso_locale.alpha3)
|
48
|
+
|
49
|
+
alpha2 = lang_map[iso_locale.alpha2]
|
50
|
+
alpha3 = lang_map[iso_locale.alpha3]
|
51
|
+
if alpha2 && alpha3
|
52
|
+
[alpha2, alpha3].flatten
|
53
|
+
elsif alpha2
|
54
|
+
alpha2
|
55
|
+
else
|
56
|
+
alpha3
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
delegate :lang_map?, :localize_lang_map, to: :class
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -26,7 +26,7 @@ module Europeana
|
|
26
26
|
|
27
27
|
def more_like_this_field_terms(*fields)
|
28
28
|
fields.flatten.map do |field|
|
29
|
-
fetch(field, []).compact
|
29
|
+
fetch(field, []).compact[0..9]
|
30
30
|
end.flatten
|
31
31
|
end
|
32
32
|
|
@@ -42,7 +42,11 @@ module Europeana
|
|
42
42
|
|
43
43
|
def more_like_this_param_query(param, terms, boost)
|
44
44
|
return nil unless terms.present?
|
45
|
-
|
45
|
+
|
46
|
+
string_terms = terms.select { |t| t.is_a?(String) }
|
47
|
+
return nil unless string_terms.present?
|
48
|
+
|
49
|
+
or_terms = string_terms.map do |v|
|
46
50
|
'"' + Europeana::API::Search.escape(v) + '"'
|
47
51
|
end.join(' OR ')
|
48
52
|
"#{param}: (#{or_terms})^#{boost}"
|
@@ -99,15 +99,16 @@ module Europeana
|
|
99
99
|
salient_facets.each_pair do |facet_field, value_list|
|
100
100
|
Array(value_list).reject(&:blank?).each do |value|
|
101
101
|
api_parameters[:qf] ||= []
|
102
|
-
|
103
|
-
api_parameters[:qf] << "#{facet_field}:#{value}"
|
104
|
-
else
|
105
|
-
api_parameters[:qf] << "#{facet_field}:\"#{value}\""
|
106
|
-
end
|
102
|
+
api_parameters[:qf] << "#{facet_field}:" + quote_facet_value(facet_field, value)
|
107
103
|
end
|
108
104
|
end
|
109
105
|
end
|
110
106
|
|
107
|
+
def quote_facet_value(facet_field, value)
|
108
|
+
return value if Europeana::API::Search::Fields::MEDIA.include?(facet_field)
|
109
|
+
'"' + value.gsub('"', '\"') + '"'
|
110
|
+
end
|
111
|
+
|
111
112
|
##
|
112
113
|
# Filter results by a query facet
|
113
114
|
def add_query_facet_to_api(_api_parameters)
|
@@ -173,8 +174,17 @@ module Europeana
|
|
173
174
|
##
|
174
175
|
# Europeana API start param counts from 1
|
175
176
|
def start(start = nil)
|
176
|
-
|
177
|
-
|
177
|
+
if start
|
178
|
+
params_will_change!
|
179
|
+
@start = start.to_i
|
180
|
+
self
|
181
|
+
else
|
182
|
+
@start ||= (page - 1) * (rows || 10) + 1
|
183
|
+
|
184
|
+
val = @start || 1
|
185
|
+
val = 1 if @start < 1
|
186
|
+
val
|
187
|
+
end
|
178
188
|
end
|
179
189
|
|
180
190
|
protected
|
@@ -3,14 +3,16 @@ module Europeana
|
|
3
3
|
##
|
4
4
|
# Local overrides for {Blacklight::SearchHelper}
|
5
5
|
module SearchHelper
|
6
|
+
# index arg counts from 0; API start param counts from 1
|
6
7
|
def previous_and_next_document_params(index, window = 1)
|
8
|
+
start = index + 1
|
7
9
|
api_params = {}
|
8
10
|
|
9
|
-
if
|
10
|
-
api_params[:start] =
|
11
|
+
if start > 1
|
12
|
+
api_params[:start] = start - window # get one before
|
11
13
|
api_params[:rows] = 2 * window + 1 # and one after
|
12
14
|
else
|
13
|
-
api_params[:start] =
|
15
|
+
api_params[:start] = start # there is no previous doc
|
14
16
|
api_params[:rows] = 2 * window # but there should be one after
|
15
17
|
end
|
16
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: europeana-blacklight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Doe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: 5.12.0
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: '6.0'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: 5.12.0
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: '6.0'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: europeana-api
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/europeana/blacklight.rb
|
188
188
|
- lib/europeana/blacklight/api_repository.rb
|
189
189
|
- lib/europeana/blacklight/document.rb
|
190
|
+
- lib/europeana/blacklight/document/lang_maps.rb
|
190
191
|
- lib/europeana/blacklight/document/more_like_this.rb
|
191
192
|
- lib/europeana/blacklight/document/relations.rb
|
192
193
|
- lib/europeana/blacklight/document_presenter.rb
|