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

pulibrary / bibdata / f04bc944-f9b4-4a42-8b26-dcacd0e3e688

11 Mar 2025 10:27PM UTC coverage: 34.017% (-58.1%) from 92.162%
f04bc944-f9b4-4a42-8b26-dcacd0e3e688

Pull #2653

circleci

christinach
Add new lc_subject_facet field.
Helps with the vocabulary work https://github.com/pulibrary/orangelight/pull/3386
In this new field we index only the lc subject heading and the subdivisions
So that when the user searches using the Details section, they can query solr for
all the subject headings and their divisions.

This is needed for the Subject browse Vocabulary work.
example: "lc_subject_facet": [
             "Booksellers and bookselling—Italy—Directories",
             "Booksellers and bookselling-Italy",
             "Booksellers and bookselling"
              ]
Pull Request #2653: Add new lc_subject_facet field.

1 of 3 new or added lines in 1 file covered. (33.33%)

2215 existing lines in 93 files now uncovered.

1294 of 3804 relevant lines covered (34.02%)

0.99 hits per line

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

24.39
/marc_to_solr/lib/solr_deleter.rb
1
require 'net/http'
1✔
2
require 'json'
1✔
3

4
# This class allow us to delete Solr records with our current
5
# version of Traject. Once we upgrade to Traject version 3.1
6
# or later we could use Traject's native delete feature
7
# (see https://github.com/traject/traject/commit/c731d09c6cb15fbe572e4a294a7a127b525b7277)
8
# but keep in mind that Traject's implementation is still in experimental mode
9
# and it does not (yet) support batches.
10
class SolrDeleter
1✔
11
  def initialize(solr_url, logger = nil)
1✔
UNCOV
12
    @solr_url = solr_url
×
UNCOV
13
    @logger = logger
×
14
  end
15

16
  def delete(ids, batch_size = 100)
1✔
UNCOV
17
    ids.each_slice(batch_size) do |batch|
×
UNCOV
18
      delete_batch(batch)
×
19
    end
20
  end
21

22
  private
1✔
23

24
    # content_type = "text/xml"
25
    # request payload is XML (even if the response is in JSON via the wt=json param)
26
    def request_deletion(uri:, body:, content_type: 'text/xml')
1✔
UNCOV
27
      @logger&.info "Deleting #{body}"
×
UNCOV
28
      start_time = Time.now
×
UNCOV
29
      response = Faraday.post(uri) do |req|
×
UNCOV
30
        req.headers = { 'Content-Type' => content_type }
×
UNCOV
31
        req.body = body
×
UNCOV
32
        req.options.open_timeout = 60
×
UNCOV
33
        req.options.read_timeout = 60
×
UNCOV
34
        req.options.write_timeout = 60
×
35
      end
UNCOV
36
      @logger&.info("Delete completed in #{Time.now - start_time} seconds. URL: #{uri}")
×
UNCOV
37
      response
×
38
    rescue Faraday::TimeoutError
UNCOV
39
      @logger&.warn("Delete timed out after #{Time.now - start_time} seconds. URL: #{uri} : #{body}")
×
UNCOV
40
      nil
×
41
    end
42

43
    def build_request_body(ids:)
1✔
UNCOV
44
      output = ['<delete>']
×
UNCOV
45
      ids.each do |id|
×
UNCOV
46
        output << "<id>#{id}</id>"
×
47
      end
48

UNCOV
49
      output << '</delete>'
×
UNCOV
50
      output.join
×
51
    end
52

53
    def valid_response?(response)
1✔
UNCOV
54
      return false if response.nil?
×
55

UNCOV
56
      response.status == 200
×
57
    end
58

59
    def delete_batch(batch)
1✔
UNCOV
60
      uri = "#{@solr_url}/update?waitSearcher=false&wt=json"
×
UNCOV
61
      body = build_request_body(ids: batch)
×
62

UNCOV
63
      response = request_deletion(uri:, body:)
×
UNCOV
64
      return if valid_response?(response)
×
65

66
      # Only retry once
UNCOV
67
      retry_response = request_deletion(uri:, body:)
×
UNCOV
68
      return if valid_response?(retry_response)
×
69

UNCOV
70
      unless retry_response.nil?
×
UNCOV
71
        Honeybadger.notify("Error deleting Solr documents. IDs: #{batch.join(', ')}. Status: #{retry_response.status}. Body: #{retry_response.body}")
×
72
      end
73
    end
74
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