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

pulibrary / allsearch_api / ed1cefda-f43b-4b58-95dd-12a33b7f1f7a

02 Jul 2025 06:23PM UTC coverage: 96.252% (-3.2%) from 99.494%
ed1cefda-f43b-4b58-95dd-12a33b7f1f7a

Pull #381

circleci

sandbergja
Refactor RackResponseController so that subclasses don't need to implement #json

Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>
Pull Request #381: Rewrite DPUL and FindingAids controllers as rack applications

29 of 30 new or added lines in 3 files covered. (96.67%)

94 existing lines in 20 files now uncovered.

976 of 1014 relevant lines covered (96.25%)

63.21 hits per line

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

100.0
/app/models/concerns/solr.rb
1
# frozen_string_literal: true
2

3
# This module helps classes communicate with Solr APIs
4
module Solr
2✔
5
  def solr_service_response
2✔
6
    response = Net::HTTP.get_response(solr_uri)
51✔
7
    response_code = response.code.to_i
45✔
8
    if response_code > 399
45✔
UNCOV
9
      raise AllsearchError.new(problem: 'UPSTREAM_ERROR',
1✔
10
                               msg: "Solr returned a #{response_code} for " \
11
                                    "path #{solr_uri.path} on host #{solr_uri.host}")
12
    end
13
    JSON.parse(response.body, symbolize_names: true)
44✔
14
  end
15

16
  def number
2✔
17
    service_response[:response][:numFound]
44✔
18
  end
19

20
  def more_link
2✔
21
    URI::HTTPS.build(host: "#{service_subdomain}.princeton.edu", path: '/catalog',
60✔
22
                     query: "q=#{query_terms}&search_field=all_fields")
23
  end
24

25
  def documents
2✔
26
    @documents ||= service_response[:response][:docs]
44✔
27
  end
28

29
  def self.status_uris
2✔
UNCOV
30
    solr_services_configs.map do |_name, config|
1✔
UNCOV
31
      solr_config = config[:solr]
4✔
UNCOV
32
      URI::HTTP.build(host: solr_config[:host],
4✔
33
                      port: solr_config[:port],
34
                      path: '/solr/admin/cores',
35
                      query: 'action=STATUS')
36
    end.uniq.compact
37
  end
38

39
  def self.solr_services_configs
2✔
UNCOV
40
    Rails.application.config_for(:allsearch).select { |_key, value| value.keys.include?(:solr) }
9✔
41
  end
42

43
  private
2✔
44

45
  # :reek:ManualDispatch
46
  def solr_uri
2✔
47
    @solr_uri ||= begin
53✔
48
      query = "q=#{@query_terms}&rows=3&facet=false&fl=#{solr_fields.join(',')}&sort=#{solr_sort}"
51✔
49
      query = "#{query}&#{extra_solr_params}" if respond_to? :extra_solr_params
51✔
50
      URI::HTTP.build(host: solr_config[:host],
51✔
51
                      port: solr_config[:port],
52
                      path: "/solr/#{solr_collection}/select",
53
                      query:)
54
    end
55
  end
56

57
  def solr_collection
2✔
58
    Rails.application.config_for(:allsearch)[service][:solr][:collection]
51✔
59
  end
60

61
  def solr_config
2✔
62
    Rails.application.config_for(:allsearch)[service][:solr]
102✔
63
  end
64

65
  def service_subdomain
2✔
66
    Rails.application.config_for(:allsearch)[service][:subdomain]
88✔
67
  end
68
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