-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace ActiveFedora where with Valkyrized where
- Loading branch information
Showing
6 changed files
with
125 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
# Methods in this class search solr to get the ids and then use the query service to find the objects. | ||
class FindObjectsViaSolrService | ||
class_attribute :solr_query_builder, :solr_service, :query_service | ||
self.solr_query_builder = Hyrax::SolrQueryBuilderService | ||
self.solr_service = Hyrax::SolrService | ||
self.query_service = Hyrax.query_service | ||
|
||
class << self | ||
# Find objects matching search criteria. | ||
# @param model [Class] | ||
# @param field_pairs [Hash] a list of pairs of property name and values | ||
# @param join_with [String] the value we're joining the clauses with (default: ' OR ' for backward compatibility with ActiveFedora where) | ||
# @param type [String] The type of query to run. Either 'raw' or 'field' (default: 'field') | ||
# @param use_valkyrie [Boolean] if true, return Valkyrie resource(s); otherwise, return ActiveFedora object(s) | ||
# @return [ActiveFedora | Valkyrie::Resource] objects matching the query | ||
def find_for_model_by_field_pairs(model:, field_pairs:, join_with: ' OR ', type: 'field', use_valkyrie: Hyrax.config.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) | ||
return query_service.find_many_by_ids(ids: ids) if use_valkyrie | ||
ids.map { |id| query_service.find_by_alternate_identifier(alternate_identifier: id.to_str, use_valkyrie: false) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
RSpec.describe Hyrax::FindObjectsViaSolrService do | ||
describe ".find_for_model_by_field_pairs", clean_repo: true do | ||
let(:collection1) { valkyrie_create(:hyrax_collection, title: ['Foo']) } | ||
let(:collection2) { valkyrie_create(:hyrax_collection, title: ['Too']) } | ||
let(:collection_ids) { [collection1.id, collection2.id] } | ||
let(:field_pairs) do | ||
{ id: collection_ids.map(&:to_s) } | ||
end | ||
|
||
it "returns ActiveFedora objects matching the query" do | ||
expect(described_class.find_for_model_by_field_pairs(model: ::Collection, field_pairs: field_pairs, use_valkyrie: false).map(&:title)).to match_array [['Foo'], ['Too']] | ||
end | ||
it "returns Valkyrie::Resources matching the query" do | ||
expect(described_class.find_for_model_by_field_pairs(model: ::Collection, field_pairs: field_pairs, use_valkyrie: true).map(&:title)).to match_array [['Foo'], ['Too']] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters