blacklight 3.1.2 → 3.2.0pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -2
- data/README.md +7 -2
- data/VERSION +1 -1
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/javascripts/blacklight/blacklight.js +23 -1
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +369 -0
- data/app/assets/stylesheets/blacklight/_facets.css.scss +117 -0
- data/app/assets/stylesheets/blacklight/_folder.css.scss +38 -0
- data/app/assets/stylesheets/blacklight/_formatting.css.scss +164 -0
- data/app/assets/stylesheets/blacklight/_header.css.scss +36 -0
- data/app/assets/stylesheets/blacklight/_layout.css.scss +79 -0
- data/app/assets/stylesheets/blacklight/_print.css.scss +54 -0
- data/app/assets/stylesheets/blacklight/_search_history.css.scss +44 -0
- data/app/assets/stylesheets/blacklight/_susy_framework.css.scss +228 -0
- data/app/assets/stylesheets/blacklight/blacklight.css.scss +27 -0
- data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +48 -0
- data/app/controllers/bookmarks_controller.rb +2 -1
- data/app/controllers/folder_controller.rb +4 -0
- data/app/controllers/saved_searches_controller.rb +4 -0
- data/app/controllers/search_history_controller.rb +4 -0
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +64 -104
- data/app/helpers/blacklight/catalog_helper_behavior.rb +4 -4
- data/app/helpers/blacklight/facets_helper_behavior.rb +52 -5
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +14 -59
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +56 -0
- data/app/helpers/search_history_constraints_helper.rb +3 -0
- data/app/models/record_mailer.rb +1 -2
- data/app/views/_flash_msg.html.erb +4 -5
- data/app/views/_user_util_links.html.erb +3 -1
- data/app/views/bookmarks/index.html.erb +2 -2
- data/app/views/catalog/_bookmark_control.html.erb +6 -6
- data/app/views/catalog/_facet_layout.html.erb +4 -0
- data/app/views/catalog/_facet_limit.html.erb +20 -33
- data/app/views/catalog/_facets.html.erb +1 -5
- data/app/views/catalog/_folder_control.html.erb +5 -5
- data/app/views/catalog/_index_default.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +4 -3
- data/app/views/catalog/_show_default.html.erb +1 -1
- data/app/views/catalog/_show_tools.html.erb +6 -6
- data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
- data/app/views/catalog/index.atom.builder +2 -2
- data/app/views/catalog/index.rss.builder +1 -1
- data/app/views/catalog/opensearch.xml.builder +10 -0
- data/app/views/catalog/show.html.erb +1 -1
- data/app/views/folder/_tools.html.erb +4 -4
- data/app/views/layouts/blacklight.html.erb +25 -37
- data/app/views/record_mailer/email_record.text.erb +1 -1
- data/app/views/record_mailer/sms_record.text.erb +2 -2
- data/app/views/search_history/index.html.erb +1 -1
- data/blacklight.gemspec +11 -9
- data/lib/{generators/blacklight/templates/SolrMarc.jar → SolrMarc.jar} +0 -0
- data/lib/blacklight.rb +5 -3
- data/lib/blacklight/catalog.rb +3 -4
- data/lib/blacklight/configurable.rb +54 -39
- data/lib/blacklight/configuration.rb +126 -0
- data/lib/blacklight/configuration/fields.rb +142 -0
- data/lib/blacklight/configuration/search_field.rb +12 -0
- data/lib/blacklight/configuration/solr_field.rb +12 -0
- data/lib/blacklight/configuration/sort_field.rb +17 -0
- data/lib/blacklight/controller.rb +16 -14
- data/lib/blacklight/engine.rb +1 -1
- data/lib/blacklight/global_configurable.rb +46 -0
- data/lib/blacklight/search_fields.rb +21 -54
- data/lib/blacklight/solr/document.rb +13 -3
- data/lib/blacklight/solr_helper.rb +88 -52
- data/lib/blacklight/utils.rb +18 -0
- data/lib/generators/blacklight/assets_generator.rb +14 -20
- data/lib/generators/blacklight/blacklight_generator.rb +14 -6
- data/lib/generators/blacklight/jetty_generator.rb +1 -1
- data/lib/generators/blacklight/templates/assets/standard.css.scss +51 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +148 -0
- data/lib/generators/blacklight/templates/config/blacklight_config.rb +2 -239
- data/lib/generators/blacklight/templates/config/sass.rb +5 -0
- data/lib/generators/blacklight/templates/solr_conf/schema.xml +514 -164
- data/lib/generators/blacklight/templates/solr_conf/solrconfig.xml +1591 -323
- data/lib/generators/blacklight/templates/solr_document.rb +2 -0
- data/lib/railties/all_tests.rake +36 -3
- data/lib/railties/blacklight_cucumber.rake +6 -4
- data/lib/railties/blacklight_rspec.rake +5 -4
- data/test_support/bin/run-tests.sh +2 -13
- data/test_support/bin/test.sh +30 -23
- data/test_support/features/did_you_mean.feature +14 -13
- data/test_support/features/step_definitions/saved_searches_steps.rb +1 -1
- data/test_support/features/step_definitions/search_steps.rb +4 -4
- data/test_support/spec/controllers/application_controller_spec.rb +3 -13
- data/test_support/spec/controllers/catalog_controller_spec.rb +102 -24
- data/test_support/spec/controllers/folder_controller_spec.rb +7 -1
- data/test_support/spec/helpers/blacklight_helper_spec.rb +45 -34
- data/test_support/spec/helpers/facets_helper_spec.rb +68 -0
- data/test_support/spec/helpers/html_head_helper_spec.rb +37 -0
- data/test_support/spec/helpers/{render_constraints_helper_spec.rb → search_history_constraints_helper_spec.rb} +26 -7
- data/test_support/spec/lib/blacklight_configurable_spec.rb +92 -0
- data/test_support/spec/lib/blacklight_configuration_spec.rb +295 -0
- data/test_support/spec/lib/{configurable_spec.rb → global_configurable_spec.rb} +2 -2
- data/test_support/spec/lib/search_fields_spec.rb +26 -29
- data/test_support/spec/{helpers → lib}/solr_helper_spec.rb +268 -287
- data/test_support/spec/lib/tasks/solr_marc_task_spec.rb +1 -1
- data/test_support/spec/lib/utils_spec.rb +58 -0
- data/test_support/spec/models/solr_docment_spec.rb +4 -8
- data/test_support/spec/views/catalog/_facets.html.erb_spec.rb +27 -170
- data/test_support/spec/views/catalog/_index_default.erb_spec.rb +38 -20
- data/test_support/spec/views/catalog/_show_default.erb_spec.rb +38 -19
- data/test_support/spec/views/catalog/index.atom.builder_spec.rb +19 -1
- metadata +148 -145
- data/app/assets/stylesheets/blacklight/blacklight.css +0 -493
- data/app/assets/stylesheets/yui.css +0 -31
- data/app/views/catalog/opensearch.xml.erb +0 -11
- data/doc/Atom-Responses.md +0 -90
- data/doc/CUSTOMIZING.md +0 -121
- data/doc/Extending-blacklight-with-the-document-extension-framework.md +0 -1
- data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -131
- data/doc/Features.md +0 -147
- data/doc/Integration-with-Rails-Footnotes.md +0 -20
- data/doc/Pagination.md +0 -38
- data/doc/Quickstart.md +0 -97
- data/doc/Upgrading-Guide.md +0 -98
- data/doc/User-Authentication.md +0 -54
- data/doc/Using-a-custom-solr-uniquekey-field.md +0 -36
- data/lib/blacklight/comma_link_renderer.rb +0 -28
- data/lib/railties/jetty_solr_server.rb +0 -108
- data/test_support/spec/views/catalog/show.html.erb_spec.rb +0 -101
@@ -0,0 +1,142 @@
|
|
1
|
+
module Blacklight
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
# This mixin provides Blacklight::Configuration with generic
|
5
|
+
# solr fields configuration
|
6
|
+
module Fields
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
# Add a configuration block for a collection of solr fields
|
12
|
+
def define_field_access(key)
|
13
|
+
key = key.to_s if respond_to? :to_s
|
14
|
+
|
15
|
+
self.default_values[key.pluralize.to_sym] = ActiveSupport::OrderedHash.new
|
16
|
+
|
17
|
+
unless self.const_defined? key.camelcase
|
18
|
+
class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
19
|
+
class #{key.camelcase} < SolrField; end
|
20
|
+
END_EVAL
|
21
|
+
end
|
22
|
+
|
23
|
+
class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
24
|
+
def add_#{key}(*args, &block)
|
25
|
+
add_solr_field("#{key}", *args, &block)
|
26
|
+
end
|
27
|
+
END_EVAL
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module InstanceMethods
|
32
|
+
# Add a solr field configuration to the given configuration key
|
33
|
+
#
|
34
|
+
# The recommended and strongly encouraged format is a field name, configuration pair, e.g.:
|
35
|
+
# add_solr_field :index_field, 'format', :label => 'Format'
|
36
|
+
#
|
37
|
+
# Alternative formats include:
|
38
|
+
#
|
39
|
+
# * a field name and block format:
|
40
|
+
#
|
41
|
+
# add_solr_field :index_field, 'format' do |field|
|
42
|
+
# field.label = 'Format'
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# * a plain block:
|
46
|
+
#
|
47
|
+
# add_solr_field :index_field do |field|
|
48
|
+
# field.field = 'format'
|
49
|
+
# field.label = 'Format'
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# * a configuration hash:
|
53
|
+
#
|
54
|
+
# add_solr_field :index_field, :field => 'format', :label => 'Format'
|
55
|
+
#
|
56
|
+
# * a Field instance:
|
57
|
+
#
|
58
|
+
# add_solr_field :index_field, IndexField.new(:field => 'format', :label => 'Format')
|
59
|
+
#
|
60
|
+
# * an array of hashes:
|
61
|
+
#
|
62
|
+
# add_solr_field :index_field, [{:field => 'format', :label => 'Format'}, IndexField.new(:field => 'date', :label => 'Date')]
|
63
|
+
#
|
64
|
+
#
|
65
|
+
# @param String config_key
|
66
|
+
# @param Array *args
|
67
|
+
# @para
|
68
|
+
#
|
69
|
+
def add_solr_field config_key, *args, &block
|
70
|
+
field_config = case args.first
|
71
|
+
when String
|
72
|
+
field_config_from_key_and_hash(config_key, *args)
|
73
|
+
when Symbol
|
74
|
+
args.first = args.first.to_s
|
75
|
+
field_config_from_key_and_hash(config_key, *args)
|
76
|
+
when Array
|
77
|
+
field_config_from_array(config_key, *args)
|
78
|
+
else
|
79
|
+
field_config_from_field_or_hash(config_key, *args)
|
80
|
+
end
|
81
|
+
|
82
|
+
return if field_config.is_a? Array
|
83
|
+
|
84
|
+
if block_given?
|
85
|
+
yield field_config
|
86
|
+
end
|
87
|
+
|
88
|
+
field_config.normalize!(self)
|
89
|
+
field_config.validate!
|
90
|
+
|
91
|
+
self[config_key.pluralize][ field_config.field ] = field_config
|
92
|
+
end
|
93
|
+
|
94
|
+
protected
|
95
|
+
# Add a solr field by a solr field name and hash
|
96
|
+
def field_config_from_key_and_hash config_key, solr_field, field_or_hash = {}
|
97
|
+
field_config = field_config_from_field_or_hash(config_key, field_or_hash)
|
98
|
+
field_config.field = solr_field
|
99
|
+
|
100
|
+
field_config
|
101
|
+
end
|
102
|
+
|
103
|
+
# Add multiple solr fields using a hash or Field instance
|
104
|
+
def field_config_from_array config_key, array_of_fields_or_hashes
|
105
|
+
array_of_fields_or_hashes.map do |field_or_hash|
|
106
|
+
add_solr_field(config_key, field_or_hash)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Add a solr field using a hash or Field instance
|
111
|
+
def field_config_from_field_or_hash config_key, field_or_hash = {}
|
112
|
+
hash_arg_to_config(field_or_hash, field_class_from_key(config_key))
|
113
|
+
end
|
114
|
+
|
115
|
+
# for our add_* methods, takes the optional hash param,
|
116
|
+
# and makes it into a specific config OpenStruct, like
|
117
|
+
# FacetField or SearchField. Or if the param already was
|
118
|
+
# one, that's cool. Or if the param is nil, make
|
119
|
+
# an empty one. Second argument is an actual class object.
|
120
|
+
def hash_arg_to_config(hash_arg, klass)
|
121
|
+
case hash_arg
|
122
|
+
when Hash
|
123
|
+
klass.new(hash_arg)
|
124
|
+
when NilClass
|
125
|
+
klass.new
|
126
|
+
else
|
127
|
+
# this assumes it already is an element of klass, or acts like one,
|
128
|
+
# if not something bad will happen later, that's your problem.
|
129
|
+
hash_arg
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
# convert a config key to the appropriate Field class
|
135
|
+
def field_class_from_key key
|
136
|
+
"Blacklight::Configuration::#{key.camelcase}".constantize
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Blacklight
|
2
|
+
class Configuration::SearchField < Configuration::SolrField
|
3
|
+
def normalize! blacklight_config
|
4
|
+
# Some normalization, calculate display_label from key,
|
5
|
+
# and make sure we have a qt from defaults.
|
6
|
+
self.key = self.field
|
7
|
+
self.label ||= self.key.try(:titlecase)
|
8
|
+
self.qt ||= blacklight_config.default_solr_params[:qt] if blacklight_config.default_solr_params
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Blacklight
|
2
|
+
class Configuration::SolrField < OpenStructWithHashAccess
|
3
|
+
def normalize! blacklight_config
|
4
|
+
self.label ||= self.field.try(:titleize)
|
5
|
+
end
|
6
|
+
|
7
|
+
def validate!
|
8
|
+
raise ArgumentError.new("Must supply a solr field name") if self.field.nil?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Blacklight
|
2
|
+
class Configuration::SortField < Configuration::SolrField
|
3
|
+
def normalize! blacklight_config
|
4
|
+
self.sort ||= self.field
|
5
|
+
|
6
|
+
self.field ||= self.key
|
7
|
+
self.field ||= self.label.try(:parameterize)
|
8
|
+
self.field ||= self.sort
|
9
|
+
|
10
|
+
self.key ||= self.field
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate!
|
14
|
+
raise ArgumentError.new("Must supply a solr sort string") if self.sort.nil?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -5,6 +5,8 @@
|
|
5
5
|
module Blacklight::Controller
|
6
6
|
|
7
7
|
def self.included(base)
|
8
|
+
base.send :include, Blacklight::SearchFields
|
9
|
+
|
8
10
|
base.send :before_filter, :default_html_head # add JS/stylesheet stuff
|
9
11
|
# now in application.rb file under config.filter_parameters
|
10
12
|
# filter_parameter_logging :password, :password_confirmation
|
@@ -22,9 +24,9 @@ module Blacklight::Controller
|
|
22
24
|
base.send :helper_method, :extra_head_content
|
23
25
|
base.send :helper_method, :stylesheet_links
|
24
26
|
base.send :helper_method, :javascript_includes
|
27
|
+
base.send :helper_method, :has_user_authentication_provider?
|
25
28
|
end
|
26
29
|
|
27
|
-
|
28
30
|
# test for exception notifier plugin
|
29
31
|
def error
|
30
32
|
raise RuntimeError, "Generating a test error..."
|
@@ -40,14 +42,7 @@ module Blacklight::Controller
|
|
40
42
|
# http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
|
41
43
|
# for how to turn off a filter in a sub-class and such.
|
42
44
|
def default_html_head
|
43
|
-
|
44
|
-
stylesheet_links << ["application"]
|
45
|
-
javascript_includes << ["application"]
|
46
|
-
else
|
47
|
-
stylesheet_links << ['yui', 'jquery/ui-lightness/jquery-ui-1.8.1.custom.css', 'blacklight/blacklight', {:media=>'all'}]
|
48
|
-
|
49
|
-
javascript_includes << ['jquery-1.4.2.min.js', 'jquery-ui-1.8.1.custom.min.js', 'blacklight/blacklight' ]
|
50
|
-
end
|
45
|
+
|
51
46
|
end
|
52
47
|
|
53
48
|
|
@@ -117,6 +112,16 @@ module Blacklight::Controller
|
|
117
112
|
flash.discard if request.xhr?
|
118
113
|
end
|
119
114
|
|
115
|
+
##
|
116
|
+
#
|
117
|
+
#
|
118
|
+
def has_user_authentication_provider?
|
119
|
+
respond_to? :current_user
|
120
|
+
end
|
121
|
+
|
122
|
+
def require_user_authentication_provider
|
123
|
+
raise ActionController::RoutingError.new('Not Found') unless has_user_authentication_provider?
|
124
|
+
end
|
120
125
|
##
|
121
126
|
# To handle failed authorization attempts, redirect the user to the
|
122
127
|
# login form and persist the current request uri as a parameter
|
@@ -126,13 +131,10 @@ module Blacklight::Controller
|
|
126
131
|
# (e.g. protected page -> logout -> returned to protected page -> home)
|
127
132
|
redirect_to root_url and flash.discard and return if request.referer and request.referer.ends_with? request.fullpath
|
128
133
|
|
134
|
+
redirect_to root_url and return unless has_user_authentication_provider?
|
135
|
+
|
129
136
|
redirect_to new_user_session_url(:referer => request.fullpath)
|
130
137
|
end
|
131
138
|
|
132
|
-
private
|
133
|
-
# Detect if the Rails asset pipeline is enabled
|
134
|
-
def use_asset_pipeline?
|
135
|
-
Rails.application.config.respond_to?(:assets) and Rails.application.config.assets.enabled
|
136
|
-
end
|
137
139
|
end
|
138
140
|
|
data/lib/blacklight/engine.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Blacklight::GlobalConfigurable
|
2
|
+
|
3
|
+
# The config environment name used by the #config method
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
# class MyThing
|
7
|
+
# extend Blacklight::GlobalConfigurable
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Now MyThing.config will be the result of:
|
11
|
+
# MyThing.configure(:production) {|config|}
|
12
|
+
#
|
13
|
+
# You set shared attributes by leaving the first argument blank or passing the :shared value:
|
14
|
+
# MyThing.configure {|config|}
|
15
|
+
# or
|
16
|
+
# MyThing.cofigure(:shared) {|config|}
|
17
|
+
|
18
|
+
# sets the @configs variable to a new Hash with empty Hash for :shared key and @config to nil
|
19
|
+
def reset_configs!
|
20
|
+
@config = nil
|
21
|
+
@configs = {:shared=>{}}
|
22
|
+
end
|
23
|
+
|
24
|
+
# A hash of all environment configs
|
25
|
+
# The key is the environment name, the value a Hash
|
26
|
+
def configs
|
27
|
+
@configs ? @configs : (reset_configs! and @configs)
|
28
|
+
end
|
29
|
+
|
30
|
+
# The main config accessor. It merges the current configs[::Rails.env]
|
31
|
+
# with configs[:shared] and lazy-loads @config to the result.
|
32
|
+
def config
|
33
|
+
@config ||= configs[:shared].merge(configs[::Rails.env] ||= {})
|
34
|
+
end
|
35
|
+
alias_method :blacklight_config, :config
|
36
|
+
|
37
|
+
# Accepts a value for the environment to configure and a block
|
38
|
+
# A hash is yielded to the block
|
39
|
+
# If the "env" != :shared,
|
40
|
+
# the hash is created by deep cloning the :shared environment config.
|
41
|
+
# This makes it possible to create defaults in the :shared config
|
42
|
+
def configure(env = :shared, &blk)
|
43
|
+
configs[env] = {}
|
44
|
+
yield configs[env]
|
45
|
+
end
|
46
|
+
end
|
@@ -2,16 +2,16 @@
|
|
2
2
|
##
|
3
3
|
# Module to deal with accessing (and setting some defaults) in an array of
|
4
4
|
# hashes that describe Blacklight search fields. Requires the base class this
|
5
|
-
# module is added to implements a #
|
6
|
-
#
|
5
|
+
# module is added to implements a #blacklight_config method that returns a hash, where
|
6
|
+
# blacklight_config[:search_fields] will be an array of hashes describing search fields.
|
7
7
|
#
|
8
|
-
# = Search Field
|
8
|
+
# = Search Field blacklight_configuration Hash =
|
9
9
|
# [:key]
|
10
10
|
# "title", required, unique key used in search URLs to specify search_field
|
11
|
-
# [:
|
11
|
+
# [:label]
|
12
12
|
# "Title", # user-displayable label, optional, if not supplied :key.titlecase will be used
|
13
13
|
# [:qt]
|
14
|
-
# "search", # Solr qt param, request handler, usually can be left blank; defaults to
|
14
|
+
# "search", # Solr qt param, request handler, usually can be left blank; defaults to blacklight_config[:default_solr_params][:qt] if not specified.
|
15
15
|
# [:solr_parameters]
|
16
16
|
# {:qf => "something"} # optional hash of additional parameters to pass to solr for searches on this field.
|
17
17
|
# [:solr_local_parameters]
|
@@ -21,88 +21,55 @@
|
|
21
21
|
#
|
22
22
|
# Optionally you can supply a :key, which is what Blacklight will use
|
23
23
|
# to identify this search field in HTTP query params. If no :key is
|
24
|
-
# supplied, one will be computed from the :
|
24
|
+
# supplied, one will be computed from the :label. If that will
|
25
25
|
# result in a collision of keys, you should supply one explicitly.
|
26
26
|
#
|
27
27
|
##
|
28
28
|
module Blacklight::SearchFields
|
29
29
|
extend ActiveSupport::Memoizable
|
30
|
+
extend ActiveSupport::Concern
|
30
31
|
|
31
|
-
|
32
|
+
included do
|
33
|
+
helper Blacklight::SearchFields if respond_to? :helper
|
34
|
+
end
|
35
|
+
|
36
|
+
# Looks up search field config list from blacklight_config[:search_fields], and
|
32
37
|
# 'normalizes' all field config hashes using normalize_config method.
|
33
38
|
# Memoized for efficiency of normalization.
|
34
39
|
def search_field_list
|
35
|
-
|
36
|
-
|
37
|
-
if (duplicates = normalized.collect{|h| h[:key]}.uniq!)
|
38
|
-
raise "Duplicate keys found in search_field config: #{duplicates.inspect}"
|
39
|
-
end
|
40
|
-
|
41
|
-
normalized
|
40
|
+
blacklight_config.search_fields.values
|
42
41
|
end
|
43
|
-
memoize :search_field_list
|
44
42
|
|
45
43
|
# Returns suitable argument to options_for_select method, to create
|
46
44
|
# an html select based on #search_field_list. Skips search_fields
|
47
45
|
# marked :include_in_simple_select => false
|
48
46
|
def search_field_options_for_select
|
49
|
-
|
50
|
-
[field_def
|
47
|
+
blacklight_config.search_fields.collect do |key, field_def|
|
48
|
+
[field_def.label, field_def.key] unless field_def.include_in_simple_select == false
|
51
49
|
end.compact
|
52
50
|
end
|
53
51
|
|
54
|
-
# Looks up a search field
|
52
|
+
# Looks up a search field blacklight_config hash from search_field_list having
|
55
53
|
# a certain supplied :key.
|
56
54
|
def search_field_def_for_key(key)
|
57
|
-
|
58
|
-
search_field_list.find {|c| c[:key] == key}
|
55
|
+
blacklight_config.search_fields[key]
|
59
56
|
end
|
60
57
|
|
61
58
|
# Returns default search field, used for simpler display in history, etc.
|
62
|
-
# if not set in
|
59
|
+
# if not set in blacklight_config, defaults to first field listed in #search_field_list
|
63
60
|
def default_search_field
|
64
|
-
|
61
|
+
blacklight_config.default_search_field || search_field_list.first
|
65
62
|
end
|
66
|
-
memoize :default_search_field
|
67
63
|
|
68
64
|
# Shortcut for commonly needed operation, look up display
|
69
65
|
# label for the key specified. Returns "Keyword" if a label
|
70
66
|
# can't be found.
|
71
67
|
def label_for_search_field(key)
|
72
68
|
field_def = search_field_def_for_key(key)
|
73
|
-
if field_def && field_def
|
74
|
-
field_def
|
69
|
+
if field_def && field_def.label
|
70
|
+
field_def.label
|
75
71
|
else
|
76
72
|
"Keyword"
|
77
73
|
end
|
78
74
|
end
|
79
|
-
|
80
|
-
protected
|
81
|
-
# Fill in missing default values in a search_field config hash.
|
82
|
-
def normalize_config(field_hash)
|
83
|
-
|
84
|
-
|
85
|
-
# Accept legacy two-element array, if it's not a Hash, assume it's legacy.
|
86
|
-
# No great way to 'duck type' here.
|
87
|
-
unless ( field_hash.kind_of?(Hash))
|
88
|
-
# Consistent with legacy behavior where two fields can have the same label,
|
89
|
-
# as long as they have different qt's, we base the unique :key on :qt.
|
90
|
-
field_hash = {:display_label => field_hash[0], :key => field_hash[1], :qt => field_hash[1]}
|
91
|
-
else
|
92
|
-
# Make a copy of passed in Hash so we don't alter original.
|
93
|
-
field_hash = field_hash.clone
|
94
|
-
end
|
95
|
-
|
96
|
-
raise Exception.new("Search field config is missing ':key' => #{field_hash.inspect}") unless field_hash[:key]
|
97
|
-
|
98
|
-
# If no display_label was provided, turn the :key into one.
|
99
|
-
field_hash[:display_label] ||= field_hash[:key].titlecase
|
100
|
-
|
101
|
-
# If no :qt was provided, take from config default
|
102
|
-
field_hash[:qt] ||= config[:default_solr_params][:qt] if config[:default_solr_params]
|
103
|
-
|
104
|
-
field_hash
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
75
|
end
|
@@ -85,6 +85,7 @@ module Blacklight::Solr::Document
|
|
85
85
|
base.send :include, RSolr::Ext::Model
|
86
86
|
base.send :include, InstanceMethods
|
87
87
|
base.send :extend, ClassMethods
|
88
|
+
base.send :extend, ActiveModel::Naming
|
88
89
|
|
89
90
|
# after_initialize hook comes from RSolr::Ext::Model, I think.
|
90
91
|
# We need to make sure all extensions get applied.
|
@@ -97,6 +98,10 @@ module Blacklight::Solr::Document
|
|
97
98
|
def id
|
98
99
|
self[self.class.unique_key]
|
99
100
|
end
|
101
|
+
|
102
|
+
def to_param
|
103
|
+
URI.escape(CGI.escape(id), '.')
|
104
|
+
end
|
100
105
|
end
|
101
106
|
|
102
107
|
|
@@ -201,9 +206,14 @@ module Blacklight::Solr::Document
|
|
201
206
|
module ClassMethods
|
202
207
|
attr_writer :registered_extensions
|
203
208
|
|
204
|
-
|
205
|
-
|
206
|
-
|
209
|
+
attr_writer :unique_key
|
210
|
+
def unique_key
|
211
|
+
# XXX Blacklight.config[:unique_key] should be deprecated soon
|
212
|
+
@unique_key ||= Blacklight.config[:unique_key] if Blacklight.respond_to?(:config) and Blacklight.config[:unique_key]
|
213
|
+
@unique_key ||= 'id'
|
214
|
+
|
215
|
+
@unique_key
|
216
|
+
end
|
207
217
|
|
208
218
|
def connection
|
209
219
|
@connection ||= Blacklight.solr
|