Skip to content

Commit

Permalink
Return Resources instead of SolrHits
Browse files Browse the repository at this point in the history
  • Loading branch information
dlpierce committed Dec 20, 2024
1 parent d5cb3f1 commit 056346f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions app/services/hyrax/custom_queries/find_by_date_range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ def initialize(query_service:)
# @param models [Array]
# @param start_datetime [DateTime]
# @param end_datetime [DateTime]
# @return [Array<Hyrax::Resource>]
def find_by_date_range(start_datetime:, end_datetime: nil, models: nil)
end_range = end_datetime.blank? ? '*' : end_datetime.utc.xmlschema
args = "system_create_dtsi:[#{start_datetime.utc.xmlschema} TO #{end_range}]"
args += " AND has_model_ssim: (#{models.map { |m| "\"#{m}\"" }.join(' OR ')})" unless models.empty?
Hyrax::SolrService.query(args)
query = "system_create_dtsi:[#{start_datetime.utc.xmlschema} TO #{end_range}]"
query += " AND has_model_ssim: (#{models.map { |m| "\"#{m}\"" }.join(' OR ')})" unless models.empty?
ids = Hyrax::SolrService.query_result(query, fl: 'id')['response']['docs'].map { |doc| doc['id'] }
Hyrax.query_service.find_many_by_ids(ids: ids)
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions app/services/hyrax/custom_queries/find_models_by_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def initialize(query_service:)
#
# @param model [Class]
# @param ids [Enumerable<#to_s>, Symbol]
# @return [Array<Hyrax::Resource>]
#
def find_models_by_access(mode:, models: nil, agent:, group: nil)
args = "#{Hydra.config.permissions[mode.to_sym][(group ? 'group' : 'individual').to_sym]}:#{agent}"
args += " AND has_model_ssim: (#{models.map { |m| "\"#{m}\"" }.join(' OR ')})" unless models.empty?
Hyrax::SolrService.query(args)
query = "#{Hydra.config.permissions[mode.to_sym][(group ? 'group' : 'individual').to_sym]}:#{agent}"
query += " AND has_model_ssim: (#{models.map { |m| "\"#{m}\"" }.join(' OR ')})" unless models.empty?
ids = Hyrax::SolrService.query_result(query, fl: 'id')['response']['docs'].map { |doc| doc['id'] }
Hyrax.query_service.find_many_by_ids(ids: ids)
end
end
end
Expand Down

0 comments on commit 056346f

Please sign in to comment.