Module: ActiveFedora::QueryResultBuilder
- Defined in:
- lib/active_fedora/query_result_builder.rb
Constant Summary collapse
- HAS_MODEL_SOLR_FIELD =
SolrQueryBuilder.solr_name("has_model", :symbol).freeze
Class Method Summary collapse
-
.class_from_solr_document(hit, opts = {}) ⇒ Object
Returns the best singular class for the solr object.
-
.classes_from_solr_document(hit, _opts = {}) ⇒ Object
Returns all possible classes for the solr object.
- .lazy_reify_solr_results(solr_results, opts = {}) ⇒ Object
- .reify_solr_result(hit, _opts = {}) ⇒ Object
- .reify_solr_results(solr_results, opts = {}) ⇒ Object
Class Method Details
.class_from_solr_document(hit, opts = {}) ⇒ Object
Returns the best singular class for the solr object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_fedora/query_result_builder.rb', line 30 def self.class_from_solr_document(hit, opts = {}) # Set the default starting point to the class specified, if available. best_model_match = Model.from_class_uri(opts[:class]) unless opts[:class].nil? Array(hit[HAS_MODEL_SOLR_FIELD]).each do |value| model_value = Model.from_class_uri(value) next unless model_value # Set as the first model in case opts[:class] was nil best_model_match ||= model_value # If there is an inheritance structure, use the most specific case. best_model_match = model_value if best_model_match > model_value end ActiveFedora::Base.logger.warn "Could not find a model for #{hit['id']}, defaulting to ActiveFedora::Base" if ActiveFedora::Base.logger && !best_model_match best_model_match || ActiveFedora::Base end |
.classes_from_solr_document(hit, _opts = {}) ⇒ Object
Returns all possible classes for the solr object
21 22 23 24 25 26 27 |
# File 'lib/active_fedora/query_result_builder.rb', line 21 def self.classes_from_solr_document(hit, _opts = {}) classes = [] hit[HAS_MODEL_SOLR_FIELD].each { |value| classes << Model.from_class_uri(value) } classes.compact end |
.lazy_reify_solr_results(solr_results, opts = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/active_fedora/query_result_builder.rb', line 3 def self.lazy_reify_solr_results(solr_results, opts = {}) Enumerator.new do |yielder| solr_results.each do |hit| yielder.yield(reify_solr_result(hit, opts)) end end end |
.reify_solr_result(hit, _opts = {}) ⇒ Object
15 16 17 18 |
# File 'lib/active_fedora/query_result_builder.rb', line 15 def self.reify_solr_result(hit, _opts = {}) klass = class_from_solr_document(hit) klass.find(hit[SOLR_DOCUMENT_ID], cast: true) end |
.reify_solr_results(solr_results, opts = {}) ⇒ Object
11 12 13 |
# File 'lib/active_fedora/query_result_builder.rb', line 11 def self.reify_solr_results(solr_results, opts = {}) solr_results.collect { |hit| reify_solr_result(hit, opts) } end |