dbla 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dbla/abstract_response.rb +4 -0
- data/lib/dbla/document_presenter.rb +2 -1
- data/lib/dbla/repository.rb +10 -1
- data/lib/dbla/response.rb +7 -3
- data/lib/dbla/response/facets.rb +1 -1
- data/lib/dbla/version.rb +1 -1
- data/lib/generators/dbla/catalog_generator.rb +10 -0
- data/lib/generators/dbla/templates/catalog_controller.rb +156 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b511243621c7428086b96e4b807c3900dddd1264
|
4
|
+
data.tar.gz: c46a5e41a85489dd58e189adc67859699bd7adb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54793d19643fd0c7854c1ef8f1e98720ea0c4b46ad1493265ae6bef4527369ff060e7a6d0914c2ea4fcc526ec21337fe21a60e5af72c736fda9edbbfd4f0fcec
|
7
|
+
data.tar.gz: 54a4c98894f0e24f4b1fbeb868b10b1941402bb2b9d1174bf82567a4af5c093672b6dfbe5795b9057119a8ff67c879cbad2893f3193a0b8db08f99a71263f836
|
@@ -67,7 +67,7 @@ module Dbla
|
|
67
67
|
# @param [Hash] opts
|
68
68
|
# @options opts [String] :value
|
69
69
|
def render_index_field_value field, options = {}
|
70
|
-
|
70
|
+
field.to_s.split('.').inject(@document) {|m,v| m[v]}
|
71
71
|
end
|
72
72
|
##
|
73
73
|
# Render the show field value for a document
|
@@ -78,6 +78,7 @@ module Dbla
|
|
78
78
|
# @param [Hash] options
|
79
79
|
# @options opts [String] :value
|
80
80
|
def render_document_show_field_value field, options={}
|
81
|
+
field.to_s.split('.').inject(@document) {|m,v| m[v]}
|
81
82
|
end
|
82
83
|
|
83
84
|
##
|
data/lib/dbla/repository.rb
CHANGED
@@ -12,7 +12,16 @@ module Dbla
|
|
12
12
|
data = nil
|
13
13
|
#TODO Move this into a SearchBuilder, add a generator
|
14
14
|
if params['q']
|
15
|
-
q = "?api_key=#{api_key}&q=#{params['q']}
|
15
|
+
q = "?api_key=#{api_key}&q=#{params['q']}"
|
16
|
+
fq = []
|
17
|
+
blacklight_config.facet_fields.each do |f|
|
18
|
+
# [fiendName, facetConfig]
|
19
|
+
next unless f[0] =~ /^(sourceResource|provider|object|intermediateProvider|dataProvider)/
|
20
|
+
fqv = f[0]
|
21
|
+
fqv = fqv + ':' + f[1].pin if f[1].pin
|
22
|
+
fq << fqv
|
23
|
+
end
|
24
|
+
q << "&facets=#{fq.join(',')}" unless fq.empty?
|
16
25
|
if params.page
|
17
26
|
q << "&page=#{params.page}"
|
18
27
|
end
|
data/lib/dbla/response.rb
CHANGED
@@ -9,10 +9,10 @@ module Dbla
|
|
9
9
|
self.document_model = options[:solr_document_model] || options[:document_model] || Item
|
10
10
|
self.blacklight_config = options[:blacklight_config]
|
11
11
|
if data
|
12
|
-
@total = data
|
12
|
+
@total = data.fetch('count',0)
|
13
13
|
@documents = (data['docs'] || []).map {|d| document_model.new(d,self)}
|
14
|
-
@start = data
|
15
|
-
@limit = data
|
14
|
+
@start = data.fetch('start',0)
|
15
|
+
@limit = data.fetch('limit',10)
|
16
16
|
@aggregations = (data['facets'] || {})
|
17
17
|
else
|
18
18
|
@aggregations = {}
|
@@ -25,10 +25,14 @@ module Dbla
|
|
25
25
|
def aggregations
|
26
26
|
# "facets":{"sourceResource.format":{"_type":"terms","missing":77,"total":250,"other":16,"terms":[{"term":"Photographs","count":44},
|
27
27
|
Hash[@aggregations.map do |k,v|
|
28
|
+
next unless v['terms']
|
28
29
|
items = v['terms'].map {|term| Facets::FacetItem.new(value: term['term'], hits: term['count'])}
|
29
30
|
[k, Facets::FacetField.new(k,items)]
|
30
31
|
end]
|
31
32
|
end
|
33
|
+
def facet_by_field_name(facet_field)
|
34
|
+
aggregations[facet_field.to_s]
|
35
|
+
end
|
32
36
|
def spelling
|
33
37
|
Words.new([])
|
34
38
|
end
|
data/lib/dbla/response/facets.rb
CHANGED
data/lib/dbla/version.rb
CHANGED
@@ -0,0 +1,156 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class CatalogController < ApplicationController
|
3
|
+
include Blacklight::Marc::Catalog
|
4
|
+
|
5
|
+
include Blacklight::Catalog
|
6
|
+
|
7
|
+
configure_blacklight do |config|
|
8
|
+
## Default parameters to send to solr for all search-like requests. See also SearchBuilder#processed_parameters
|
9
|
+
config.default_solr_params = {
|
10
|
+
:qt => 'search',
|
11
|
+
:rows => 10
|
12
|
+
}
|
13
|
+
|
14
|
+
# solr path which will be added to solr base url before the other solr params.
|
15
|
+
#config.solr_path = 'select'
|
16
|
+
|
17
|
+
# items to show per page, each number in the array represent another option to choose from.
|
18
|
+
#config.per_page = [10,20,50,100]
|
19
|
+
|
20
|
+
## Default parameters to send on single-document requests to Solr. These settings are the Blackligt defaults (see SearchHelper#solr_doc_params) or
|
21
|
+
## parameters included in the Blacklight-jetty document requestHandler.
|
22
|
+
#
|
23
|
+
#config.default_document_solr_params = {
|
24
|
+
# :qt => 'document',
|
25
|
+
# ## These are hard-coded in the blacklight 'document' requestHandler
|
26
|
+
# # :fl => '*',
|
27
|
+
# # :rows => 1
|
28
|
+
# # :q => '{!raw f=id v=$id}'
|
29
|
+
#}
|
30
|
+
|
31
|
+
config.repository_class = Dbla::Repository
|
32
|
+
config.document_model = Item
|
33
|
+
config.response_model = Dbla::Response
|
34
|
+
config.document_presenter_class = Dbla::DocumentPresenter
|
35
|
+
config.search_builder_class = SearchBuilder
|
36
|
+
# solr field configuration for search results/index views
|
37
|
+
config.index.title_field = 'sourceResource.title'
|
38
|
+
config.index.thumbnail_field = 'object'
|
39
|
+
config.index.display_type_field = 'format'
|
40
|
+
|
41
|
+
# solr field configuration for document/show views
|
42
|
+
#config.show.title_field = 'title_display'
|
43
|
+
#config.show.display_type_field = 'format'
|
44
|
+
|
45
|
+
# solr fields that will be treated as facets by the blacklight application
|
46
|
+
# The ordering of the field names is the order of the display
|
47
|
+
#
|
48
|
+
# Setting a limit will trigger Blacklight's 'more' facet values link.
|
49
|
+
# * If left unset, then all facet values returned by solr will be displayed.
|
50
|
+
# * If set to an integer, then "f.somefield.facet.limit" will be added to
|
51
|
+
# solr request, with actual solr request being +1 your configured limit --
|
52
|
+
# you configure the number of items you actually want _displayed_ in a page.
|
53
|
+
# * If set to 'true', then no additional parameters will be sent to solr,
|
54
|
+
# but any 'sniffed' request limit parameters will be used for paging, with
|
55
|
+
# paging at requested limit -1. Can sniff from facet.limit or
|
56
|
+
# f.specific_field.facet.limit solr request params. This 'true' config
|
57
|
+
# can be used if you set limits in :default_solr_params, or as defaults
|
58
|
+
# on the solr side in the request handler itself. Request handler defaults
|
59
|
+
# sniffing requires solr requests to be made with "echoParams=all", for
|
60
|
+
# app code to actually have it echo'd back to see it.
|
61
|
+
#
|
62
|
+
# :show may be set to false if you don't want the facet to be drawn in the
|
63
|
+
# facet bar
|
64
|
+
config.add_facet_field 'sourceResource.format', label: 'By Format'
|
65
|
+
config.add_facet_field 'dataProvider', label: 'Contributing Institution'
|
66
|
+
config.add_facet_field 'provider.name', label: 'Partner'
|
67
|
+
config.add_facet_field 'sourceResource.language.name', label: 'By Language'
|
68
|
+
config.add_facet_field 'sourceResource.subject.name', label: 'By Subject'
|
69
|
+
|
70
|
+
# Have BL send all facet field names to Solr, which has been the default
|
71
|
+
# previously. Simply remove these lines if you'd rather use Solr request
|
72
|
+
# handler defaults, or have no facets.
|
73
|
+
config.add_facet_fields_to_solr_request!
|
74
|
+
|
75
|
+
# solr fields to be displayed in the index (search results) view
|
76
|
+
# The ordering of the field names is the order of the display
|
77
|
+
config.add_index_field 'sourceResource.format', :label => 'Format'
|
78
|
+
config.add_index_field 'sourceResource.creator', :label => 'Creator'
|
79
|
+
|
80
|
+
# solr fields to be displayed in the show (single result) view
|
81
|
+
# The ordering of the field names is the order of the display
|
82
|
+
|
83
|
+
# "fielded" search configuration. Used by pulldown among other places.
|
84
|
+
# For supported keys in hash, see rdoc for Blacklight::SearchFields
|
85
|
+
#
|
86
|
+
# Search fields will inherit the :qt solr request handler from
|
87
|
+
# config[:default_solr_parameters], OR can specify a different one
|
88
|
+
# with a :qt key/value. Below examples inherit, except for subject
|
89
|
+
# that specifies the same :qt as default for our own internal
|
90
|
+
# testing purposes.
|
91
|
+
#
|
92
|
+
# The :key is what will be used to identify this BL search field internally,
|
93
|
+
# as well as in URLs -- so changing it after deployment may break bookmarked
|
94
|
+
# urls. A display label will be automatically calculated from the :key,
|
95
|
+
# or can be specified manually to be different.
|
96
|
+
|
97
|
+
# This one uses all the defaults set by the solr request handler. Which
|
98
|
+
# solr request handler? The one set in config[:default_solr_parameters][:qt],
|
99
|
+
# since we aren't specifying it otherwise.
|
100
|
+
|
101
|
+
config.add_search_field 'all_fields', :label => 'All Fields'
|
102
|
+
|
103
|
+
|
104
|
+
# Now we see how to over-ride Solr request handler defaults, in this
|
105
|
+
# case for a BL "search field", which is really a dismax aggregate
|
106
|
+
# of Solr search fields.
|
107
|
+
|
108
|
+
config.add_search_field('title') do |field|
|
109
|
+
# solr_parameters hash are sent to Solr as ordinary url query params.
|
110
|
+
field.solr_parameters = { :'spellcheck.dictionary' => 'title' }
|
111
|
+
|
112
|
+
# :solr_local_parameters will be sent using Solr LocalParams
|
113
|
+
# syntax, as eg {! qf=$title_qf }. This is neccesary to use
|
114
|
+
# Solr parameter de-referencing like $title_qf.
|
115
|
+
# See: http://wiki.apache.org/solr/LocalParams
|
116
|
+
field.solr_local_parameters = {
|
117
|
+
:qf => '$title_qf',
|
118
|
+
:pf => '$title_pf'
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
config.add_search_field('author') do |field|
|
123
|
+
field.solr_parameters = { :'spellcheck.dictionary' => 'author' }
|
124
|
+
field.solr_local_parameters = {
|
125
|
+
:qf => '$author_qf',
|
126
|
+
:pf => '$author_pf'
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
# Specifying a :qt only to show it's possible, and so our internal automated
|
131
|
+
# tests can test it. In this case it's the same as
|
132
|
+
# config[:default_solr_parameters][:qt], so isn't actually neccesary.
|
133
|
+
config.add_search_field('subject') do |field|
|
134
|
+
field.solr_parameters = { :'spellcheck.dictionary' => 'subject' }
|
135
|
+
field.qt = 'search'
|
136
|
+
field.solr_local_parameters = {
|
137
|
+
:qf => '$subject_qf',
|
138
|
+
:pf => '$subject_pf'
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
# "sort results by" select (pulldown)
|
143
|
+
# label in pulldown is followed by the name of the SOLR field to sort by and
|
144
|
+
# whether the sort is ascending or descending (it must be asc or desc
|
145
|
+
# except in the relevancy case).
|
146
|
+
config.add_sort_field 'score desc, pub_date_sort desc, title_sort asc', :label => 'relevance'
|
147
|
+
config.add_sort_field 'pub_date_sort desc, title_sort asc', :label => 'year'
|
148
|
+
config.add_sort_field 'author_sort asc, title_sort asc', :label => 'author'
|
149
|
+
config.add_sort_field 'title_sort asc, pub_date_sort desc', :label => 'title'
|
150
|
+
|
151
|
+
# If there are more than this many search results, no spelling ("did you
|
152
|
+
# mean") suggestion is offered.
|
153
|
+
config.spell_max = 5
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
metadata
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Audrey Altman
|
8
8
|
- Ben Armintor
|
9
|
+
- Jeremy Friesen
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
@@ -17,14 +18,14 @@ dependencies:
|
|
17
18
|
requirements:
|
18
19
|
- - "~>"
|
19
20
|
- !ruby/object:Gem::Version
|
20
|
-
version: 4.1
|
21
|
+
version: '4.1'
|
21
22
|
type: :runtime
|
22
23
|
prerelease: false
|
23
24
|
version_requirements: !ruby/object:Gem::Requirement
|
24
25
|
requirements:
|
25
26
|
- - "~>"
|
26
27
|
- !ruby/object:Gem::Version
|
27
|
-
version: 4.1
|
28
|
+
version: '4.1'
|
28
29
|
- !ruby/object:Gem::Dependency
|
29
30
|
name: blacklight
|
30
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,6 +100,7 @@ description: Rails engine to put BL on DPLA -> DBLA
|
|
99
100
|
email:
|
100
101
|
- audrey@dp.la
|
101
102
|
- armintor@gmail.com
|
103
|
+
- jeremy.n.friesen@gmail.com
|
102
104
|
executables: []
|
103
105
|
extensions: []
|
104
106
|
extra_rdoc_files: []
|
@@ -123,10 +125,12 @@ files:
|
|
123
125
|
- lib/dbla/search_builder_behavior.rb
|
124
126
|
- lib/dbla/version.rb
|
125
127
|
- lib/generators/dbla/assets_generator.rb
|
128
|
+
- lib/generators/dbla/catalog_generator.rb
|
126
129
|
- lib/generators/dbla/install_generator.rb
|
127
130
|
- lib/generators/dbla/models_generator.rb
|
128
131
|
- lib/generators/dbla/routes_generator.rb
|
129
132
|
- lib/generators/dbla/search_builder_generator.rb
|
133
|
+
- lib/generators/dbla/templates/catalog_controller.rb
|
130
134
|
- lib/generators/dbla/templates/collection.rb
|
131
135
|
- lib/generators/dbla/templates/dbla.css.scss
|
132
136
|
- lib/generators/dbla/templates/item.rb
|