-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #371 from LafayetteCollegeLibraries/develop
2019.9
- Loading branch information
Showing
78 changed files
with
2,382 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
module Actors | ||
class ImageActor < ::Spot::BaseActor | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
class SolrSuggestActor < ::Hyrax::Actors::AbstractActor | ||
# @param [Hyrax::Actors::Environment] env | ||
# @return [void] | ||
def create(env) | ||
next_actor.create(env) && update_suggest_dictionaries(env) | ||
end | ||
|
||
# @param [Hyrax::Actors::Environment] env | ||
# @return [void] | ||
def update(env) | ||
next_actor.update(env) && update_suggest_dictionaries(env) | ||
end | ||
|
||
# @param [Hyrax::Actors::Environment] env | ||
# @return [void] | ||
def destroy(env) | ||
next_actor.destroy(env) && update_suggest_dictionaries(env) | ||
end | ||
|
||
private | ||
|
||
# Enqueue the job to update the solr suggest dictionaries if this actor | ||
# isn't a part of a batch ingest | ||
# | ||
# @param [Hyrax::Actors::Environment] env | ||
# @return [void] | ||
def update_suggest_dictionaries(env) | ||
Spot::UpdateSolrSuggestDictionariesJob.perform_now unless part_of_batch_ingest?(env) | ||
end | ||
|
||
# @return [Symbol] | ||
def batch_ingest_key | ||
::Spot::Importers::Base::RecordImporter::BATCH_INGEST_KEY | ||
end | ||
|
||
# Does the environment's attributes include the BATCH_INGEST_KEY? | ||
# | ||
# @param [Hyrax::Actors::Environment] env | ||
# @return [true, false] | ||
def part_of_batch_ingest?(env) | ||
env.attributes.include?(batch_ingest_key) && env.attributes[batch_ingest_key] == true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
module Spot | ||
# Starting point for Spot models. Adds mixin to better pass-around | ||
# RDF language-tagged values (see {::DeserializesRdfLiterals}) | ||
# as well as allowing us to apply a +date_uploaded+ value on +#create+. | ||
# | ||
# @example | ||
# module Hyrax | ||
# class WorkActor < ::Spot::BaseActor | ||
# end | ||
# end | ||
# | ||
class BaseActor < ::Hyrax::Actors::BaseActor | ||
include ::DeserializesRdfLiterals | ||
|
||
private | ||
|
||
# Overrides the BaseActor method to allow us to stuff in | ||
# `date_uploaded` values where necessary. | ||
# | ||
# @return [void] | ||
def apply_deposit_date(env) | ||
env.curation_concern.date_uploaded = get_date_uploaded_value(env) | ||
end | ||
|
||
# @param [Hyrax::Actors::Environment] env | ||
# @return [DateTime] | ||
def get_date_uploaded_value(env) | ||
concern = env.curation_concern | ||
|
||
if env.attributes[:date_uploaded].present? | ||
DateTime.parse(env.attributes[:date_uploaded]).utc | ||
elsif concern.date_uploaded.present? | ||
# since this is only being called on `#create`, the concern | ||
# shouldn't necessarily have a date_uploaded set already. | ||
# but, in the event that it is, we should retain the value | ||
# as a UTC DateTime. | ||
DateTime.parse(concern.date_uploaded.to_s).utc | ||
else | ||
# this is what `BaseActor#apply_deposit_date` does, so we'll | ||
# keep that as our fallback. | ||
::Hyrax::TimeService.time_in_utc | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# frozen_string_literal: true | ||
module Qa::Authorities | ||
# An base class for building out local authorities to use Solr's | ||
# suggestion engine for autocomplete-options for fields. | ||
# This is a more flexible approach than using Blacklight's | ||
# suggestion search, which appears to only work for a single field. | ||
# | ||
# To begin, first ensure that a suggestion dictionary has been set-up + created | ||
# for your field. In +schemal.xml+, you'll want to ensure that a copyfield | ||
# has been created as the pool to draw from. Note: this field needs to be | ||
# a stored field. | ||
# | ||
# @example Configuring a copyfield for suggestions | ||
# <copyField source="keyword_sim" dest="keyword_suggest_ssim" /> | ||
# | ||
# In +solrconfig.xml+, you'll need to build a suggester. The property | ||
# +suggestAnalyzerFieldType+ should be a simple tokenizing field. | ||
# | ||
# @example Configuring a suggestion dictionary | ||
# <lst name="suggester"> | ||
# <str name="name">keyword</str> | ||
# <str name="lookupImpl">AnalyzingInfixLookupFactory</str> | ||
# <str name="dictionaryImpl">DocumentDictionaryFactory</str> | ||
# <str name="indexPath">suggestion_index_keyword</str> | ||
# <str name="highlight">false</str> | ||
# <str name="suggestAnalyzerFieldType">textSuggest</str> | ||
# <!-- | ||
# buildOnCommit can bring ingests to a crawl, so we suggest | ||
# leaving this false and manually triggering builds via | ||
# a cron-job or something similar | ||
# --> | ||
# <str name="buildOnCommit">false</str> | ||
# <str name="field">keyword_suggest_ssim</str> | ||
# </lst> | ||
# | ||
class SolrSuggest < Qa::Authorities::Base | ||
BUILD_ALL_KEYWORD = :__all__ | ||
|
||
attr_reader :dictionary | ||
|
||
def self.build_dictionaries! | ||
new(BUILD_ALL_KEYWORD).build_dictionary! | ||
end | ||
|
||
def initialize(dictionary) | ||
@dictionary = dictionary | ||
end | ||
|
||
# @return [void] | ||
def build_dictionary! | ||
params = { 'suggest' => true } | ||
|
||
if dictionary == BUILD_ALL_KEYWORD | ||
params['suggest.buildAll'] = true | ||
else | ||
params['suggest.dictionary'] = dictionary | ||
params['suggest.build'] = true | ||
end | ||
|
||
connection.get(suggest_path, params: params) | ||
end | ||
|
||
# @return [RSolr::Client] | ||
|
||
def search(query) | ||
solr_suggestion_for_query(query) | ||
end | ||
|
||
def term(_id) | ||
{} | ||
end | ||
|
||
def all | ||
[] | ||
end | ||
|
||
private | ||
|
||
def connection | ||
ActiveFedora::SolrService.instance.conn | ||
end | ||
|
||
# @return [String] | ||
def suggest_path | ||
@suggest_path ||= begin | ||
url = Rails.application.config_for(:solr)['url'] | ||
URI.join(url + '/', 'suggest').path | ||
end | ||
end | ||
|
||
# @param [String] query | ||
# @return [Array<Hash<String => String>>] | ||
def solr_suggestion_for_query(query) | ||
params = { | ||
'suggest.q' => query, | ||
'suggest.dictionary' => dictionary | ||
} | ||
|
||
raw = connection.get(suggest_path, params: params) | ||
parse_raw_response(raw, query: query) | ||
end | ||
|
||
# Takes the Solr response and transforms the results into the | ||
# Questioning Authority preferred format. | ||
# | ||
# @param [Hash<String => *>] raw | ||
# @param [Hash] options | ||
# @option [String] query | ||
# The initial query, used to extract results from the returned Hash | ||
# @return [Array<Hash<String => String>>] | ||
def parse_raw_response(raw, query:) | ||
suggestions = raw.dig('suggest', dictionary, query, 'suggestions') | ||
suggestions ||= [] | ||
|
||
suggestions.map do |res| | ||
{ id: res['term'], label: res['term'], value: res['term'] } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# Generated via | ||
# `rails generate hyrax:work Image` | ||
module Hyrax | ||
# Generated controller for Image | ||
class ImagesController < ApplicationController | ||
# Adds Hyrax behaviors to the controller. | ||
include Hyrax::WorksControllerBehavior | ||
include Hyrax::BreadcrumbsForWorks | ||
self.curation_concern_type = ::Image | ||
|
||
# Use this line if you want to use a custom presenter | ||
self.show_presenter = Hyrax::ImagePresenter | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
# Generated form for Image | ||
class ImageForm < Hyrax::Forms::WorkForm | ||
include ::IdentifierFormFields | ||
include ::LanguageTaggedFormFields | ||
include ::NestedFormFields | ||
|
||
self.model_class = ::Image | ||
self.terms += [:resource_type] | ||
end | ||
end |
Oops, something went wrong.