Class: Hyrax::FindObjectsViaSolrService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/find_objects_via_solr_service.rb

Overview

Methods in this class search solr to get the ids and then use the query service to find the objects.

Class Method Summary collapse

Class Method Details

.find_for_model_by_field_pairs(model:, field_pairs:, join_with: ' OR ', type: 'field', use_valkyrie: Hyrax.config.use_valkyrie?) ⇒ Array<ActiveFedora|Valkyrie::Resource>

Find objects matching search criteria.

Parameters:

  • model (Class)

    if not using Valkyrie, this is expected to be an ActiveFedora::Base object that supports #where

  • field_pairs (Hash)

    a list of pairs of property name and values

  • join_with (String) (defaults to: ' OR ')

    the value we're joining the clauses with (default: ' OR ' for backward compatibility with ActiveFedora where)

  • type (String) (defaults to: 'field')

    The type of query to run. Either 'raw' or 'field' (default: 'field')

  • use_valkyrie (Boolean) (defaults to: Hyrax.config.use_valkyrie?)

    if true, return Valkyrie resource(s); otherwise, return ActiveFedora object(s)

Returns:

  • (Array<ActiveFedora|Valkyrie::Resource>)

    objects matching the query


18
19
20
21
22
23
24
# File 'app/services/hyrax/find_objects_via_solr_service.rb', line 18

def find_for_model_by_field_pairs(model:, field_pairs:, join_with: ' OR ', type: 'field', use_valkyrie: Hyrax.config.use_valkyrie?)
  return model.where(field_pairs).to_a unless use_valkyrie
  query = solr_query_builder.construct_query_for_model(model, field_pairs, join_with, type)
  results = solr_service.query(query)
  ids = results.map(&:id)
  query_service.find_many_by_ids(ids: ids).to_a
end