-
Notifications
You must be signed in to change notification settings - Fork 65
Resource Scenarios
Spotlight allows curators to create new exhibit-specific objects with an image, title, and basic descriptive metadata. This configuration allows implementors to use Spotlight without existing data or needing to wire in external indexing processes, and allows curators to build out simple exhibits out-of-the-box.
At this time, uploaded resources must be images (#1071) and are limited to single-image items (#851).
Curators can add exhibit-specific metadata fields from the Curation > Metadata
page.
These fields can be populated on any resource, including manually uploaded resources.
In addition to exhibit-specific custom fields, the Spotlight::Engine
configuration can provide a set of additional fields. Unlike exhibit-specific fields, which map to exhibit-specific field names, the uploaded fields can be mapped to arbitrary fields in the Solr schema. This allows the application maintainer to create some parity between externally indexed resources (so all resources have e.g. the same descriptive metadata field), and some parity across exhibits within an application.
These fields will be automatically added as metadata fields on the search results page.
# Defaults to the blacklight_config.index.title_field:
Spotlight::Engine.config.upload_title_field = nil # OpenStruct.new(...)
Spotlight::Engine.config.upload_fields = [
OpenStruct.new(field_name: :spotlight_upload_description_tesim, label: "Description", form_field_type: :text_area),
OpenStruct.new(field_name: :spotlight_upload_attribution_tesim, label: "Attribution"),
OpenStruct.new(field_name: :spotlight_upload_date_tesim, label: "Date")
]
# The allowed file extensions for uploading non-repository items.
Spotlight::Engine.config.allowed_upload_extensions = %w(jpg jpeg png)
Spotlight, just as with Blacklight, can be configured to work with an existing Solr index. Spotlight will use Blacklight's CatalogController
configuration to provide the default options available to the curator. Blacklight configuration is discussed in depth on the Blacklight wiki.
Spotlight adds some additional requirements to the Solr schema:
- In order to index exhibit-specific fields, out-of-the-box, Spotlight provides an indexing strategy that uses Atomic Updates. This approach requires specific Solr schema configuration, so note the caveats, limitations and required configuration necessary to use this feature. The rake task
spotlight:check:solr
will test if your Solr configuration is configured correctly for Atomic Updates.
Alternatively, if you are unable to use the Atomic Update strategy, your SolrDocument
class must implement a #reindex
method that can update the document in Solr with the exhibit-specific data provided by a #to_solr
call.
- Exhibit-specific fields are generated using a suffix to indicate the expected Solr schema types. These are the default values (which can be overridden in an application initializer):
Spotlight::Engine.config.solr_fields.prefix = "".freeze
Spotlight::Engine.config.solr_fields.boolean_suffix = "_bsi".freeze # boolean, stored, indexed
Spotlight::Engine.config.solr_fields.string_suffix = "_ssim".freeze # string, stored, indexed, multivalued
Spotlight::Engine.config.solr_fields.text_suffix = "_tesim".freeze # text, stored, indexed, multivalued
- Spotlight sends
facet.field
andfacet.query
parameters as part of the search request in order to provide exhibit-specific features (e.g. tags, item visibility). Solr must be configured to respect these parameters (the default).
Another supported resource configuration allows the curator to select resources within the exhibit. To configure this user experience, you need to write some basic Ruby code. First, you need a model that can convert a Spotlight::Resource
into a Solr hash, e.g.
class MyApplicationCustomResource < Spotlight::Resource
def to_solr
super.merge({ some: :values })
end
end
Spotlight::Resource provides your model with several attributes:
-
#exhibit
, the exhibit that this resource belongs to -
#data
, a serialized hash that your application can put arbitrary data into -
#to_solr
, a starter Solr document hash containing some common metadata
You can add a button to the Curation > Items
page by adding a partial that renders your button to the Spotlight::Engine
configuration (in e.g. an initializer):
Spotlight::Engine.config.new_resource_partials += ['my_application_custom_resource/form']
This partial should render a form, wired into a controller that creates (and saves) a new MyApplicationCustomResource
. Generally, this should be constructed similarly to any Rails CRUD resource (e.g. [http://guides.rubyonrails.org/getting_started.html#getting-up-and-running](from the Rails guides)).
At a minimum, you'll probably want a controller with a create action (to receive the POSTed form data), e.g.:
# config/routes.rb
resource :my_application_custom_resources, only: [:create]
class MyApplicationCustomResourcesController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
before_filter :build_resource
authorize_resource
def create
if @resource.save
redirect_to spotlight.admin_exhibit_catalog_index_path(current_exhibit)
else
render 'edit'
end
end
private
def build_resource
@resource = begin
r = MyApplicationCustomResource.new resource_params
r.exhibit = current_exhibit
r
end
end
def resource_params
params.require(:my_application_custom_resource).permit(:data)
end
end
<%= form_for(MyApplicationCustomResource.new, url: my_application_custom_resources_path(exhibit_id: current_exhibit)) do |f| %>
<%= f.text_field :url %>
<%= f.submit t('.add_item'), class: 'btn btn-primary' %>
<% end if can? :manage, MyApplicationCustomResource %>
Configuration
- Blacklight
- Page widgets
- Resource scenarios
- Image sizes
- Queueing backends
- Creating a theme
- Configure S3 data storage
- Translations and Internationalization
- Adding new navigation menu items
Case studies
Building an exhibit
- Quickstart guide
- Configuration settings
- Adding and managing items
- Creating feature pages
- Creating about pages
- Creating browse categories
- Exhibit on exhibits - Stanford specific, yet generalizable
Development