• 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

22.78
/app/models/index_manager.rb
1
class IndexManager < ActiveRecord::Base
1✔
2
  # @param solr_url Solr URL to get the index manager for (or initialize a new
3
  #   one)
4
  # @returns [IndexManager]
5
  def self.for(solr_url)
1✔
UNCOV
6
    IndexManager.find_or_initialize_by(solr_collection: solr_url)
×
7
  end
8

9
  def self.reindex!(solr_url: nil)
1✔
UNCOV
10
    solr_url ||= rebuild_solr_url
×
UNCOV
11
    manager = self.for(solr_url)
×
UNCOV
12
    return false if manager.in_progress?
×
13

UNCOV
14
    manager.last_dump_completed = nil
×
UNCOV
15
    manager.save
×
UNCOV
16
    manager.wipe!
×
UNCOV
17
    manager.index_remaining!
×
UNCOV
18
    true
×
19
  end
20

21
  def self.rebuild_solr_url
1✔
UNCOV
22
    "#{Rails.application.config.solr['url']}-rebuild"
×
23
  end
24

25
  belongs_to :dump_in_progress, class_name: 'Dump'
1✔
26
  belongs_to :last_dump_completed, class_name: 'Dump'
1✔
27

28
  def wipe!
1✔
UNCOV
29
    RSolr.connect(url: solr_collection).delete_by_query('*:*')
×
30
  end
31

32
  def index_next_dump!
1✔
UNCOV
33
    return unless next_dump
×
34

UNCOV
35
    self.dump_in_progress = next_dump
×
UNCOV
36
    self.in_progress = true
×
UNCOV
37
    save
×
UNCOV
38
    generate_batch do
×
UNCOV
39
      next_dump.dump_files.each do |dump_file|
×
UNCOV
40
        Index::DumpFileJob.perform_async(dump_file.id, solr_collection)
×
41
      end
42
    end
43
  end
44

45
  def index_remaining!
1✔
UNCOV
46
    logger.warn 'IndexManager is in progress' if in_progress?
×
47

48
    # Don't do anything unless there's a job to index and we're not already
49
    # indexing.
UNCOV
50
    return unless next_dump && !in_progress?
×
51

UNCOV
52
    save!
×
53
    # Create an overall catchup batch.
UNCOV
54
    batch = Sidekiq::Batch.new
×
UNCOV
55
    batch.on(:success, 'IndexManager::Workflow#indexed_remaining', 'index_manager_id' => id)
×
UNCOV
56
    batch.description = "Performing catch-up index into #{solr_collection}"
×
UNCOV
57
    batch.jobs do
×
UNCOV
58
      Index::RemainingDumpsJob.perform_async(id)
×
59
    end
60
  end
61

62
  def generate_batch(&)
1✔
UNCOV
63
    batch = Sidekiq::Batch.new
×
UNCOV
64
    batch.on(:success, IndexManager::Workflow, 'dump_id' => next_dump.id, 'index_manager_id' => id)
×
UNCOV
65
    batch.description = "Indexing Dump #{next_dump.id} into #{solr_collection}"
×
UNCOV
66
    batch.jobs(&)
×
67
  end
68

69
  def next_dump
1✔
UNCOV
70
    @next_dump ||=
×
UNCOV
71
      if last_dump_completed&.full_dump?
×
UNCOV
72
        previous_to_full_incremental || next_incremental
×
UNCOV
73
      elsif last_dump_completed
×
UNCOV
74
        next_incremental
×
75
      else
UNCOV
76
        recent_full_dump || first_incremental
×
77
      end
78
  end
79

80
  def recent_full_dump
1✔
UNCOV
81
    Dump.full_dump.joins(:event).order('events.start' => 'DESC').first
×
82
  end
83

84
  def first_incremental
1✔
UNCOV
85
    Dump.changed_records.joins(:event).order('events.start' => 'ASC').first
×
86
  end
87

88
  def previous_to_full_incremental
1✔
UNCOV
89
    Dump.changed_records.joins(:event).where('events.start < ?', last_dump_completed.event.start.to_s).where.not(id: last_dump_completed.id).order('events.start' => 'DESC').first
×
90
  end
91

92
  def next_incremental
1✔
UNCOV
93
    incremental_dump = Dump.changed_records.joins(:event).where('events.start': last_dump_completed.event.start..Float::INFINITY).where.not(id: last_dump_completed.id).order('events.start' => 'ASC').first
×
UNCOV
94
    if incremental_dump&.dump_files&.empty?
×
UNCOV
95
      self.last_dump_completed = incremental_dump
×
UNCOV
96
      incremental_dump = next_incremental
×
97
    end
UNCOV
98
    incremental_dump
×
99
  end
100

101
  class Workflow
1✔
102
    # Callback for when the batch of DumpFiles is done indexing.
103
    def on_success(status, options)
1✔
UNCOV
104
      index_manager = IndexManager.find(options['index_manager_id'])
×
UNCOV
105
      dump = Dump.find(options['dump_id'])
×
UNCOV
106
      index_manager.last_dump_completed = dump
×
UNCOV
107
      index_manager.dump_in_progress = nil
×
UNCOV
108
      index_manager.save
×
109
      # If there's a parent batch it's meant to keep going until it runs out of
110
      # dumps.
UNCOV
111
      if status.parent_bid
×
UNCOV
112
        return unless index_manager.next_dump
×
113

UNCOV
114
        overall = Sidekiq::Batch.new(status.parent_bid)
×
UNCOV
115
        overall.jobs do
×
UNCOV
116
          index_manager.index_next_dump!
×
117
        end
118
      else
UNCOV
119
        index_manager.in_progress = false
×
UNCOV
120
        index_manager.save
×
121
      end
122
    end
123

124
    def indexed_remaining(_status, options)
1✔
UNCOV
125
      index_manager = IndexManager.find(options['index_manager_id'])
×
UNCOV
126
      RSolr.connect(url: index_manager.solr_collection).commit
×
UNCOV
127
      index_manager.dump_in_progress = nil
×
UNCOV
128
      index_manager.in_progress = false
×
UNCOV
129
      index_manager.save
×
130
    end
131
  end
132
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