-
Notifications
You must be signed in to change notification settings - Fork 10
Solr and Blacklight Support
bmckinney edited this page Mar 4, 2017
·
16 revisions
Create this file: app/models/blacklight/eds/repository.rb
require 'ebsco/eds'
module Blacklight::Eds
class Repository < Blacklight::AbstractRepository
def find(id, params = {})
search params.merge(id: id, fields: blacklight_config.show_fields.values)
end
##
# Execute a search against EDS
#
def search(params = {})
send_and_receive blacklight_config.solr_path, params.blacklight_params.to_unsafe_h
end
def send_and_receive(path, bl_params = {})
benchmark('EDS fetch', level: :debug) do
eds = EBSCO::EDS::Session.new
eds_results = eds.search(bl_params.update({'hl'=>'on'}))
# the current page disappears in the EDS response in some cases (e.g., apply facets and it resets to page 1)
# this is really an issue with searching EDS as stateless
if bl_params.has_key?('page')
eds_results = eds.get_page(bl_params['page'].to_i)
end
eds_response = eds_results.to_solr
solr_response = blacklight_config.response_model.new(eds_response, bl_params,
document_model: blacklight_config.document_model,
blacklight_config: blacklight_config)
solr_response
end
end
end
end
Note:
- If IP authentication is configured in EBSCOadmin:
eds = EBSCO::EDS::Session.new({:profile=>'eds-api'})
- If User ID authentication is configured, add the following environment vars and create the session with no options:
EDS_USER=user_id;EDS_PASS=secret;EDS_PROFILE=eds-api
eds = EBSCO::EDS::Session.new
Then add this to app/controllers/catalog_controller.rb:
config.repository_class = Blacklight::Eds::Repository
Add ebsco-eds to the Gemfile:
gem 'ebsco-eds'
Add this to catalog_controller.rb:
config.add_index_field 'title_display', label: 'Title', :highlight => true
Add the solr highlight parameter to the search params in repository.rb:
eds_results = eds.search(bl_params.update({'hl'=>'on'}))
Add this to catalog_controller.rb:
config.add_sort_field 'score desc', :label => 'most relevant'
config.add_sort_field 'pub_date_sort desc', :label => 'most recent'
Add this to catalog_controller.rb:
config.add_search_field('title') do |field|
# solr_parameters hash are sent to Solr as ordinary url query params.
field.solr_parameters = { :'spellcheck.dictionary' => 'title' }
# :solr_local_parameters will be sent using Solr LocalParams
# syntax, as eg {! qf=$title_qf }. This is neccesary to use
# Solr parameter de-referencing like $title_qf.
# See: http://wiki.apache.org/solr/LocalParams
field.solr_local_parameters = {
qf: '$title_qf',
pf: '$title_pf'
}
end
config.add_search_field('author') do |field|
field.solr_parameters = { :'spellcheck.dictionary' => 'author' }
field.solr_local_parameters = {
qf: '$author_qf',
pf: '$author_pf'
}
end
# Specifying a :qt only to show it's possible, and so our internal automated
# tests can test it. In this case it's the same as
# config[:default_solr_parameters][:qt], so isn't actually neccesary.
config.add_search_field('subject') do |field|
field.solr_parameters = { :'spellcheck.dictionary' => 'subject' }
field.qt = 'search'
field.solr_local_parameters = {
qf: '$subject_qf',
pf: '$subject_pf'
}
end
Add this to catalog_controller.rb:
config.add_facet_field 'format', label: 'Format'
config.add_facet_field 'subject_topic_facet', label: 'Topic', limit: 20, index_range: 'A'..'Z'
config.add_facet_field 'language_facet', label: 'Language', limit: true