• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orangelight / 00dbc10b-d747-4ad7-b211-7b26d753abbb

14 Aug 2025 01:25PM UTC coverage: 0.483% (-94.9%) from 95.343%
00dbc10b-d747-4ad7-b211-7b26d753abbb

push

circleci

web-flow
Merge pull request #5181 from pulibrary/dependabot/bundler/activestorage-7.2.2.2

Bump activestorage from 7.2.2.1 to 7.2.2.2

47 of 9721 relevant lines covered (0.48%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/services/linked_document_resolver.rb
1
# frozen_string_literal: true
2

3
class LinkedDocumentResolver
×
4
  # A mutable array of Solr Documents linked to a given Solr Document
5
  class LinkedDocuments
×
6
    delegate :empty?, to: :siblings
×
7

8
    # Constructor
9
    # @param root [String] the identifier for the record
10
    # @param siblings [Array<String>] the identifiers for the related records
11
    # @param solr_field [String] the Solr field containing the sibling values
12
    def initialize(root:, siblings:, solr_field:, maximum_records: Orangelight.config['show_page']['linked_documents']['maximum'])
×
13
      @root = root
×
14
      @siblings = siblings
×
15
      @field = solr_field
×
16
      @maximum_records = maximum_records
×
17
    end
×
18

19
    # Retrieves the Solr documents for each adjacent node
20
    # @return [Array<SolrDocument>] sibling documents
21
    def siblings
×
22
      return [] unless @siblings.present? && response.key?('response') &&
×
23
                       !response['response']['docs'].empty?
×
24

25
      sibling_docs = response['response']['docs'].reject { |document| document['id'] == @root }
×
26
      sibling_docs.map { |document| SolrDocument.new(document) }
×
27
    end
×
28

29
    # Decorate the SolrDocument for each sibling node decorated for the View layer
30
    # @param title_field [String] field used to access the value of the title for the catalog record
31
    # @param display_fields [Array<String>] the set of fields exposed for the catalog record
32
    # @return [Array<SolrDocumentDecorator>] sibling document
33
    def decorated(title_field: 'title_display', display_fields: %w[id])
×
34
      siblings.map do |sibling|
×
35
        DecoratorService::SolrDocumentDecorator.new(document: sibling,
×
36
                                                    title_field:,
×
37
                                                    display_fields:)
×
38
      end
×
39
    end
×
40

41
    def total_count_of_linked_documents_in_index
×
42
      response['response']['numFound']
×
43
    end
×
44

45
    private
×
46

47
      # Determine whether or not this number is a BIBID
48
      # @param sibling_number [String] reference number for a linked catalog record
49
      # @return [MatchData,nil] a match containing the ID for the linked BIBID (or nil)
50
      def bib_id?(sibling_number)
×
51
        /(?:^BIB)(.*)/.match(sibling_number)
×
52
      end
×
53

54
      # The Solr field containing the reference number for a linked catalog record
55
      # @param sibling_number [String] reference number for a linked catalog record
56
      # @return [String] the field
57
      def solr_field(sibling_number)
×
58
        bib_id?(sibling_number) ? 'id' : @field
×
59
      end
×
60

61
      # The value for the Solr field referencing the linked catalog record
62
      # @param sibling_number [String] reference number for a linked catalog record
63
      # @return [String] the value
64
      def solr_value(sibling_number)
×
65
        bib_match = bib_id?(sibling_number)
×
66
        bib_match ? bib_match[1] : sibling_number
×
67
      end
×
68

69
      # The query for used to retrieve Documents for all catalog records linked to a given record
70
      # @return [String] the query
71
      def facet_query
×
72
        queries = @siblings.map do |sibling_number|
×
73
          "#{solr_field(sibling_number)}:#{solr_value(sibling_number)}"
×
74
        end
×
75
        queries.join(' OR ')
×
76
      end
×
77

78
      # Retrieve an instance of the FacetedQueryService
79
      # @return [FacetedQueryService] an instance of the service object
80
      def faceted_query_service
×
81
        @faceted_query_service ||= FacetedQueryService.new(Blacklight, @maximum_records)
×
82
      end
×
83

84
      # The response from Solr from the facet query for all linked documents
85
      # @return [Hash] the response (parsed from JSON)
86
      def response
×
87
        return @response unless @response.nil?
×
88
        http_response = faceted_query_service.get_fq_solr_response(facet_query)
×
89
        @response = JSON.parse(http_response.body)
×
90
      end
×
91
  end
×
92
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc