Skip to content

Commit

Permalink
Add configuration support for wildcarded index, show and facet fields
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Feb 9, 2014
1 parent 0a04f94 commit 7181e3f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
12 changes: 10 additions & 2 deletions app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ def render_index_field_label *args
document = args.first

field = options[:field]
html_escape t(:'blacklight.search.index.label', label: index_fields(document)[field].label)
html_escape t(:"blacklight.search.index.#{document_index_view_type}.label", default: :'blacklight.search.index.label', label: index_field_label(document, field))
end

def index_field_label document, field
t(:"blacklight.search.fields.index.#{field}", default: [:"blacklight.search.fields.#{field}", index_fields(document)[field].label])
end

##
Expand Down Expand Up @@ -226,7 +230,11 @@ def render_document_show_field_label *args

field = options[:field]

html_escape t(:'blacklight.search.show.label', label: document_show_fields(document)[field].label)
html_escape t(:'blacklight.search.show.label', label: document_show_field_label(document, field))
end

def document_show_field_label document, field
t(:"blacklight.search.fields.index.#{field}", default: [:"blacklight.search.fields.#{field}", document_show_fields(document)[field].label])
end

##
Expand Down
34 changes: 33 additions & 1 deletion lib/blacklight/configuration/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,27 @@ def add_solr_field config_key, *args, &block
field_config_from_key_and_hash(config_key, *args)
when Array
field_config_from_array(config_key, *args)
return # we've iterated over the array above.
else
field_config_from_field_or_hash(config_key, *args)
end

return if field_config.is_a? Array
# look up any dynamic fields
if field_config.field.to_s =~ /\*/ and luke_fields
salient_fields = luke_fields.select { |k,v| k =~ Regexp.new(field_config.field.to_s.gsub('*', '.+')) }

salient_fields.each do |field, luke_config|
config = field_config.dup
config.field = field
if self[config_key.pluralize][ config.field ]
self[config_key.pluralize][ config.field ] = config.merge(self[config_key.pluralize][ config.field ])
else
add_solr_field(config_key, config)
end
end

return
end

if block_given?
yield field_config
Expand All @@ -94,6 +110,22 @@ def add_solr_field config_key, *args, &block
end

protected
def luke_fields
if @table[:luke_fields] === false
return nil
end

@table[:luke_fields] ||= begin
if has_key? :blacklight_solr
blacklight_solr.get('admin/luke', params: { fl: '*', 'json.nl' => 'map' })['fields']
end
rescue
false
end

@table[:luke_fields] || nil
end

# Add a solr field by a solr field name and hash
def field_config_from_key_and_hash config_key, solr_field, field_or_hash = {}
field_config = field_config_from_field_or_hash(config_key, field_or_hash)
Expand Down

0 comments on commit 7181e3f

Please sign in to comment.