Skip to content

Commit

Permalink
Removing Solr release versions in the URL to Solr documentation pages…
Browse files Browse the repository at this point in the history
…; Fixing typo. errors; Removing references to in-memory implementations of the Solr QueryService and Persister; Changed the method name from Solr::Repository::handle_409 to Solr::Repository::handle_conflict
  • Loading branch information
jrgriffiniii committed Aug 10, 2018
1 parent 6c187b7 commit 8baf00d
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/valkyrie/persistence/solr/metadata_adapter.rb
Expand Up @@ -51,7 +51,7 @@ def query_service
end

# Generate the Valkyrie ID for this unique metadata adapter
# This uses an MD5 hash of the URL endpoint to ensure that this is unique
# This uses the URL of the Solr endpoint to ensure that this is unique
# @return [Valkyrie::ID]
def id
@id ||= Valkyrie::ID.new(Digest::MD5.hexdigest(connection.base_uri.to_s))
Expand Down
8 changes: 4 additions & 4 deletions lib/valkyrie/persistence/solr/model_converter.rb
Expand Up @@ -19,7 +19,7 @@ def initialize(resource, resource_factory:)
def convert!
# Appends the resource type to the Solr Document
to_h.merge(Valkyrie::Persistence::Solr::Queries::MODEL.to_sym => [resource.internal_resource])
to_h.merge(indexer_solr(resource))
.merge(indexer_solr(resource))
end

# Generate the Solr Document for a Valkyrie Resource using the indexer
Expand Down Expand Up @@ -74,7 +74,7 @@ def add_single_values(attribute_hash)
# Determines whether or not a field is multivalued
# @note this is tied to conventions in the Solr Schema
# @see https://github.com/samvera-labs/valkyrie/blob/master/solr/config/schema.xml
# @see https://lucene.apache.org/solr/guide/7_4/defining-fields.html#defining-fields
# @see https://lucene.apache.org/solr/guide/defining-fields.html#defining-fields
# @param [String] field
# @return [Boolean]
def multivalued?(field)
Expand Down Expand Up @@ -228,7 +228,7 @@ def self.handles?(value)
# Constructs a SolrRow object for a Property with a Hash value
# @note this prepends the string "serialized-" to the value indexed in Solr
# This is indexed as a stored multivalued text
# @see https://lucene.apache.org/solr/guide/7_4/defining-fields.html#defining-fields
# @see https://lucene.apache.org/solr/guide/defining-fields.html#defining-fields
# @see https://github.com/samvera-labs/valkyrie/blob/master/solr/config/schema.xml
# @return [SolrRow]
def result
Expand Down Expand Up @@ -414,7 +414,7 @@ def result
# - stored multivalued text
# - stored multivalued english text
# If the string is greater than 1000 characters in length, it is only indexed as a stored multivalued text
# @see https://lucene.apache.org/solr/guide/7_4/defining-fields.html#defining-fields
# @see https://lucene.apache.org/solr/guide/defining-fields.html#defining-fields
# @see https://github.com/samvera-labs/valkyrie/blob/master/solr/config/schema.xml
# @return [Array<Symbol>]
def fields
Expand Down
6 changes: 3 additions & 3 deletions lib/valkyrie/persistence/solr/orm_converter.rb
Expand Up @@ -58,7 +58,7 @@ def updated_at
end

# Construct the OptimisticLockToken object using the "_version_" field value in the Solr Document
# @see https://lucene.apache.org/solr/guide/7_4/updating-parts-of-documents.html#optimistic-concurrency
# @see https://lucene.apache.org/solr/guide/updating-parts-of-documents.html#optimistic-concurrency
# @return [Valkyrie::Persistence::OptimisticLockToken]
def token
Valkyrie::Persistence::OptimisticLockToken.new(adapter_id: resource_factory.adapter_id, token: version)
Expand All @@ -80,7 +80,7 @@ def id
# Construct the Hash containing the Valkyrie Resource attributes using the Solr Document
# @note this filters for attributes which have been indexed as stored multivalued texts (tsim)
# @see https://github.com/samvera-labs/valkyrie/blob/master/solr/config/schema.xml
# @see https://lucene.apache.org/solr/guide/7_4/defining-fields.html#defining-fields
# @see https://lucene.apache.org/solr/guide/defining-fields.html#defining-fields
# @return [Hash]
def attribute_hash
build_literals(strip_tsim(solr_document.select do |k, _v|
Expand All @@ -89,7 +89,7 @@ def attribute_hash
end

# Removes the substring "_tsim" within Hash keys
# This is used when mapping Solr Document Hashs into Valkyrie Resource attributes
# This is used when mapping Solr Document Hashes into Valkyrie Resource attributes
# @see #attribute_hash
# @param [Hash] hsh
# @return [Hash]
Expand Down
8 changes: 3 additions & 5 deletions lib/valkyrie/persistence/solr/persister.rb
Expand Up @@ -10,13 +10,11 @@ class Persister

# @param adapter [Valkyrie::Persistence::Solr::MetadataAdapter] The adapter with the
# configured solr connection.
# @note (see Valkyrie::Persistence::Memory::Persister#initialize)
def initialize(adapter:)
@adapter = adapter
end

# (see Valkyrie::Persistence::Memory::Persister#save)
#
# Persists a Valkyrie Resource into a Solr index
# @note Fields are saved using Solr's dynamic fields functionality.
# If the text has length > 1000, it is stored as *_tsim
# otherwise it's stored as *_tsim, *_ssim, and *_tesim
Expand All @@ -30,14 +28,14 @@ def save(resource:)
repository([resource]).persist.first
end

# (see Valkyrie::Persistence::Memory::Persister#save_all)
# Persists a set of Valkyrie Resources into a Solr index
# @param [Array<Valkyrie::Resource>] resources
# @return [Valkyrie::Resource] the set of persisted resources
def save_all(resources:)
repository(resources).persist
end

# (see Valkyrie::Persistence::Memory::Persister#delete)
# Deletes a Valkyrie Resource persisted into a Solr index
# @param [Valkyrie::Resource] resource
# @return [Valkyrie::Resource] the deleted resource
def delete(resource:)
Expand Down
6 changes: 3 additions & 3 deletions lib/valkyrie/persistence/solr/queries/default_paginator.rb
Expand Up @@ -5,21 +5,21 @@ module Valkyrie::Persistence::Solr::Queries
# all Documents in an index.
class DefaultPaginator
# Default parameter for the next page in search results in a Solr query request
# @see https://lucene.apache.org/solr/guide/7_4/pagination-of-results.html
# @see https://lucene.apache.org/solr/guide/pagination-of-results.html
# @return [Integer]
def next_page
1
end

# Default parameter for the number of documents in a page of search results in a Solr query request
# @see https://lucene.apache.org/solr/guide/7_4/pagination-of-results.html
# @see https://lucene.apache.org/solr/guide/pagination-of-results.html
# @return [Integer]
def per_page
100
end

# Default state for the whether or not additional pages of search results in a Solr query response exist
# @see https://lucene.apache.org/solr/guide/7_4/pagination-of-results.html
# @see https://lucene.apache.org/solr/guide/pagination-of-results.html
# @return [Boolean]
def has_next?
true
Expand Down
Expand Up @@ -59,7 +59,7 @@ def member_ids
end

# Generate the Solr join query using the id_ssi field
# @see https://lucene.apache.org/solr/guide/7_4/other-parsers.html#join-query-parser
# @see https://lucene.apache.org/solr/guide/other-parsers.html#join-query-parser
# @return [String]
def query
"{!join from=#{MEMBER_IDS} to=join_id_ssi}id:#{id}"
Expand Down
Expand Up @@ -38,7 +38,7 @@ def each
end

# Generate the Solr join query using the id_ssi field
# @see https://lucene.apache.org/solr/guide/7_4/other-parsers.html#join-query-parser
# @see https://lucene.apache.org/solr/guide/other-parsers.html#join-query-parser
# @return [String]
def query
"{!join from=#{property}_ssim to=join_id_ssi}id:#{id}"
Expand Down
9 changes: 0 additions & 9 deletions lib/valkyrie/persistence/solr/query_service.rb
Expand Up @@ -11,7 +11,6 @@ def initialize(connection:, resource_factory:)
@resource_factory = resource_factory
end

# (see Valkyrie::Persistence::Memory::QueryService#find_by)
# Find resources by Valkyrie ID
# @param [Valkyrie::ID] id
# @return [Valkyrie::Resource]
Expand All @@ -21,7 +20,6 @@ def find_by(id:)
Valkyrie::Persistence::Solr::Queries::FindByIdQuery.new(id, connection: connection, resource_factory: resource_factory).run
end

# (see Valkyrie::Persistence::Memory::QueryService#find_by_alternate_identifier)
# Find resources by a Valkyrie alternate identifier
# @param [Valkyrie::ID] alternate_identifier
# @return [Valkyrie::Resource]
Expand All @@ -31,7 +29,6 @@ def find_by_alternate_identifier(alternate_identifier:)
Valkyrie::Persistence::Solr::Queries::FindByAlternateIdentifierQuery.new(alternate_identifier, connection: connection, resource_factory: resource_factory).run
end

# (see Valkyrie::Persistence::Memory::QueryService#find_many_by_ids)
# Find resources using a set of Valkyrie IDs
# @param [Array<Valkyrie::ID>] ids
# @return [Array<Valkyrie::Resource>]
Expand All @@ -44,38 +41,33 @@ def find_many_by_ids(ids:)
Valkyrie::Persistence::Solr::Queries::FindManyByIdsQuery.new(ids, connection: connection, resource_factory: resource_factory).run
end

# (see Valkyrie::Persistence::Memory::QueryService#find_all)
# Find all of the Valkyrie Resources persisted in the Solr index
# @return [Array<Valkyrie::Resource>]
def find_all
Valkyrie::Persistence::Solr::Queries::FindAllQuery.new(connection: connection, resource_factory: resource_factory).run
end

# (see Valkyrie::Persistence::Memory::QueryService#find_all_of_model)
# Find all of the Valkyrie Resources of a model persisted in the Solr index
# @param [Class, String] model the Valkyrie::Resource Class
# @return [Array<Valkyrie::Resource>]
def find_all_of_model(model:)
Valkyrie::Persistence::Solr::Queries::FindAllQuery.new(connection: connection, resource_factory: resource_factory, model: model).run
end

# (see Valkyrie::Persistence::Memory::QueryService#find_parents)
# Find all of the parent resources for a given Valkyrie Resource
# @param [Valkyrie::Resource] member resource
# @return [Array<Valkyrie::Resource>] parent resources
def find_parents(resource:)
find_inverse_references_by(resource: resource, property: :member_ids)
end

# (see Valkyrie::Persistence::Memory::QueryService#find_members)
# Find all of the member resources for a given Valkyrie Resource
# @param [Valkyrie::Resource] parent resource
# @return [Array<Valkyrie::Resource>] member resources
def find_members(resource:, model: nil)
Valkyrie::Persistence::Solr::Queries::FindMembersQuery.new(resource: resource, model: model, connection: connection, resource_factory: resource_factory).run
end

# (see Valkyrie::Persistence::Memory::QueryService#find_references_by)
# Find all of the resources referenced by a given Valkyrie Resource using a specific property
# @param [Valkyrie::Resource] resource
# @param [Symbol, String] property
Expand All @@ -84,7 +76,6 @@ def find_references_by(resource:, property:)
Valkyrie::Persistence::Solr::Queries::FindReferencesQuery.new(resource: resource, property: property, connection: connection, resource_factory: resource_factory).run
end

# (see Valkyrie::Persistence::Memory::QueryService#find_inverse_references_by)
# Find all of the resources referencing a given Valkyrie Resource using a specific property
# (e. g. find all resources referencing a parent resource as a collection using the property "member_of_collections")
# @param [Valkyrie::Resource] referenced resource
Expand Down
8 changes: 4 additions & 4 deletions lib/valkyrie/persistence/solr/repository.rb
Expand Up @@ -39,7 +39,7 @@ def add_documents(documents)
rescue RSolr::Error::Http => exception
# Error 409 conflict is returned when versions do not match
if exception.response[:status] == 409
handle_409
handle_conflict
end
raise exception
end
Expand Down Expand Up @@ -67,10 +67,10 @@ def generate_id(resource)
resource.id = SecureRandom.uuid
end

# If a 409 error response is encountered when attempting to commit updates to Solr, raise a StaleObjectError
# @see https://lucene.apache.org/solr/guide/7_2/updating-parts-of-documents.html#optimistic-concurrency
# If a 409 conflict response is encountered when attempting to commit updates to Solr, raise a StaleObjectError
# @see https://lucene.apache.org/solr/guide/updating-parts-of-documents.html#optimistic-concurrency
# @see https://tools.ietf.org/html/rfc7231#section-6.5.8
def handle_409
def handle_conflict
raise Valkyrie::Persistence::StaleObjectError, "One or more resources have been updated by another process." if resources.count > 1
raise Valkyrie::Persistence::StaleObjectError, "The object #{resources.first.id} has been updated by another process."
end
Expand Down

0 comments on commit 8baf00d

Please sign in to comment.