Sha256: f7c268da5b1269c12a55f7cde338da50294e0e49a6a07864203a0dee2fad6b31

Contents?: true

Size: 946 Bytes

Versions: 7

Compression:

Stored size: 946 Bytes

Contents

# frozen_string_literal: true
module Valkyrie::Persistence::Solr::Queries
  # Responsible for efficiently returning all {Valkyrie::Resource}s which
  # reference a {Valkyrie::Resource} in a given property.
  class FindInverseReferencesQuery
    attr_reader :resource, :property, :connection, :resource_factory
    def initialize(resource:, property:, connection:, resource_factory:)
      @resource = resource
      @property = property
      @connection = connection
      @resource_factory = resource_factory
    end

    def run
      enum_for(:each)
    end

    def each
      docs = DefaultPaginator.new
      while docs.has_next?
        docs = connection.paginate(docs.next_page, docs.per_page, "select", params: { q: query })["response"]["docs"]
        docs.each do |doc|
          yield resource_factory.to_resource(object: doc)
        end
      end
    end

    def query
      "#{property}_ssim:id-#{resource.id}"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
valkyrie-1.2.0.rc1 lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb
valkyrie-1.1.2 lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb
valkyrie-1.1.1 lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb
valkyrie-1.1.0 lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb
valkyrie-1.0.0 lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb
valkyrie-1.0.0.rc2 lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb
valkyrie-1.0.0.rc1 lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb