Class: Hyrax::CustomQueries::FindByPropertyValue
- Inherits:
-
Object
- Object
- Hyrax::CustomQueries::FindByPropertyValue
- Defined in:
- app/services/hyrax/custom_queries/find_by_property_value.rb
Overview
Finds resources for arbitrary properties using the Solr index.
Class Method Summary collapse
Instance Method Summary collapse
-
#find_by_property_value(property:, value:, field_suffix: :ssim, search_field: nil, **options) ⇒ NilClass, Valkyrie::Resource
Returns one resource matching the specified property and value.
-
#find_ids_by_property_pairs(pairs:, field_suffix: :ssim, **options) ⇒ Array<String>
Returns ids for resources matching all specified property/value pairs.
-
#find_many_by_property_pairs(pairs:, field_suffix: :ssim, **options) ⇒ Array<Valkyrie::Resource>
Returns resources matching all specified property/value pairs.
-
#find_many_by_property_value(property:, value:, field_suffix: :ssim, search_field: nil, **options) ⇒ Array<Valkyrie::Resource>
Returns resources matching the specified property and value.
-
#initialize(query_service:, query_rows: 1_000) ⇒ FindByPropertyValue
constructor
A new instance of FindByPropertyValue.
Constructor Details
#initialize(query_service:, query_rows: 1_000) ⇒ FindByPropertyValue
Returns a new instance of FindByPropertyValue.
16 17 18 19 |
# File 'app/services/hyrax/custom_queries/find_by_property_value.rb', line 16 def initialize(query_service:, query_rows: 1_000) @query_service = query_service @query_rows = query_rows end |
Class Method Details
.queries ⇒ Object
9 10 11 12 13 14 |
# File 'app/services/hyrax/custom_queries/find_by_property_value.rb', line 9 def self.queries [:find_ids_by_property_pairs, :find_many_by_property_pairs, :find_many_by_property_value, :find_by_property_value] end |
Instance Method Details
#find_by_property_value(property:, value:, field_suffix: :ssim, search_field: nil, **options) ⇒ NilClass, Valkyrie::Resource
Returns one resource matching the specified property and value.
82 83 84 85 86 |
# File 'app/services/hyrax/custom_queries/find_by_property_value.rb', line 82 def find_by_property_value(property:, value:, field_suffix: :ssim, search_field: nil, **) [:rows] = 1 find_many_by_property_value(property: property, value: value, field_suffix: field_suffix, search_field: search_field, **).first end |
#find_ids_by_property_pairs(pairs:, field_suffix: :ssim, **options) ⇒ Array<String>
Returns ids for resources matching all specified property/value pairs.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/hyrax/custom_queries/find_by_property_value.rb', line 28 def find_ids_by_property_pairs(pairs:, field_suffix: :ssim, **) = { rows: @query_rows }.merge() query = pairs.map do |k, v| suffix = if field_suffix.is_a? Hash field_suffix[k] || :ssim else field_suffix end "+#{k}_#{suffix}:\"#{RSolr.solr_escape(v)}\"" end response = Hyrax::SolrService.query_result(query.join(' '), fl: 'id', **) response['response']['docs'].map { |doc| doc['id'] } end |
#find_many_by_property_pairs(pairs:, field_suffix: :ssim, **options) ⇒ Array<Valkyrie::Resource>
Returns resources matching all specified property/value pairs.
49 50 51 52 |
# File 'app/services/hyrax/custom_queries/find_by_property_value.rb', line 49 def find_many_by_property_pairs(pairs:, field_suffix: :ssim, **) found_ids = find_ids_by_property_pairs(pairs: pairs, field_suffix: field_suffix, **) @query_service.find_many_by_ids(ids: found_ids).to_a # Wings emits an Enumerator end |
#find_many_by_property_value(property:, value:, field_suffix: :ssim, search_field: nil, **options) ⇒ Array<Valkyrie::Resource>
Returns resources matching the specified property and value.
63 64 65 66 67 68 69 70 |
# File 'app/services/hyrax/custom_queries/find_by_property_value.rb', line 63 def find_many_by_property_value(property:, value:, field_suffix: :ssim, search_field: nil, **) if search_field search_field_array = search_field.split('_') field_suffix = search_field_array.last property = search_field_array[0...-1].join('_') end find_many_by_property_pairs(pairs: { property => value }, field_suffix: field_suffix, **) end |