Class: Wings::CustomQueries::FindIdsByModel
- Inherits:
-
Object
- Object
- Wings::CustomQueries::FindIdsByModel
- Defined in:
- lib/wings/services/custom_queries/find_ids_by_model.rb
Overview
Instance Attribute Summary collapse
-
#query_service ⇒ Object
readonly
Returns the value of attribute query_service.
Class Method Summary collapse
Instance Method Summary collapse
- #find_ids_by_model(model:, ids: :all) ⇒ Enumerable<Valkyrie::ID>
-
#initialize(query_service:, query_rows: 1_000) ⇒ FindIdsByModel
constructor
A new instance of FindIdsByModel.
Constructor Details
#initialize(query_service:, query_rows: 1_000) ⇒ FindIdsByModel
Returns a new instance of FindIdsByModel.
12 13 14 15 |
# File 'lib/wings/services/custom_queries/find_ids_by_model.rb', line 12 def initialize(query_service:, query_rows: 1_000) @query_service = query_service @query_rows = query_rows end |
Instance Attribute Details
#query_service ⇒ Object (readonly)
Returns the value of attribute query_service.
17 18 19 |
# File 'lib/wings/services/custom_queries/find_ids_by_model.rb', line 17 def query_service @query_service end |
Class Method Details
.queries ⇒ Object
8 9 10 |
# File 'lib/wings/services/custom_queries/find_ids_by_model.rb', line 8 def self.queries [:find_ids_by_model] end |
Instance Method Details
#find_ids_by_model(model:, ids: :all) ⇒ Enumerable<Valkyrie::ID>
Note:
uses solr to do the lookup
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wings/services/custom_queries/find_ids_by_model.rb', line 27 def find_ids_by_model(model:, ids: :all) return enum_for(:find_ids_by_model, model: model, ids: ids) unless block_given? model_name = ModelRegistry.lookup(model).model_name solr_query = "_query_:\"{!raw f=has_model_ssim}#{model_name}\"" solr_response = Hyrax::SolrService.get(solr_query, fl: 'id', rows: @query_rows)['response'] loop do response_docs = solr_response['docs'] response_docs.select! { |doc| ids.include?(doc['id']) } unless ids == :all response_docs.each { |doc| yield doc['id'] } break if (solr_response['start'] + solr_response['docs'].count) >= solr_response['numFound'] solr_response = Hyrax::SolrService.get(solr_query, fl: 'id', rows: @query_rows, start: solr_response['start'] + @query_rows)['response'] end end |