Skip to content

Commit

Permalink
Adds vocabulary column to subject table
Browse files Browse the repository at this point in the history
update multiple genre vocab
Update the browse_facet task to check for subject facet
update browselists load_facet to look for subject facet
Include fixtures
Updates subjects.sorted

Co-authored-by: Nikitas Tampakis <[email protected]>
  • Loading branch information
christinach and tampakis committed Sep 19, 2024
1 parent b0ebcb1 commit f2235f4
Show file tree
Hide file tree
Showing 10 changed files with 1,283 additions and 1,698 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Metrics/ModuleLength:
- 'app/helpers/blacklight_helper.rb'
- 'app/helpers/application_helper.rb'
- 'app/models/concerns/blacklight/document/json_ld.rb'
- 'lib/orangelight/browse_lists.rb'

Metrics/PerceivedComplexity:
Exclude:
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ class CatalogController < ApplicationController
config.add_show_field 'other_format_display', label: 'Other format(s)'
config.add_show_field 'indexes_display', label: 'Indexes'
config.add_show_field 'finding_aid_display', label: 'Finding aid'
config.add_show_field 'cumulative_index_finding_aid_display', label: "Cumulative index/\u200BFinding aid"
config.add_show_field 'cumulative_index_finding_aid_display', label: 'Cumulative index/&#8203;Finding aid'

config.add_show_field 'subject_display', label: 'Subject(s)', helper_method: :subjectify
config.add_show_field 'form_genre_display', label: 'Form/&#8203;Genre'
config.add_show_field 'form_genre_remaining_display', label: 'Other form/&#8203;genre'
config.add_show_field 'place_name_display', label: 'Place name(s)'
config.add_show_field 'other_title_display', label: 'Other title(s)'
config.add_show_field 'other_title_1display', hash: true
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/orangelight/browsables_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,15 @@ def should_check_availability?(bib_id)
def current_browse_per_page
params[:rpp].present? ? params[:rpp].to_i : 10
end

def vocab_type(vocab)
if vocab == 'Library of Congress genre/form term'
'lcgft_s'
elsif vocab == 'Rare books genre term'
'rbgenr_s'
else
'subject_facet'
end
end
end
end
38 changes: 37 additions & 1 deletion app/views/orangelight/browsables/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,43 @@
</div>
</div>
<div class="col-12">
<% if @model != 'call_numbers' %>
<% if @model == 'subjects' %>
<div id="content" class="browse-row">
<table class="browse browse--subjects documents-list">
<thead>
<tr>
<th> <%= @list_name %> </th>
<th>Type</th>
</tr>
</thead>
<tbody >
<% @orangelight_browsables.each_with_index do |orangelight_subject, i| %>
<% facet_field = vocab_type(orangelight_subject.vocabulary) %>
<% if orangelight_subject.id == @match && @exact_match %>
<tr class="alert alert-info clickable-row" data-href="/catalog/?f[<%=facet_field%>][]=<%=CGI.escape orangelight_subject.label%>">
<strong>
<% else %>
<tr class="row-<%=i.even? ? 'odd' : 'even' %>">
<% end %>
<td class="<%=orangelight_subject.dir%>"><%= link_to orangelight_subject.label, "/catalog/?f[#{facet_field}][]=#{CGI.escape orangelight_subject.label}", dir: orangelight_subject.dir %>
<%= "(#{orangelight_subject.count})"%></td>
<td><%= orangelight_subject.vocabulary %></td>
<% if orangelight_subject.id == @match && @exact_match %>
</strong>
</tr>
<% else %>
</tr>
<% end %>
<% if orangelight_subject.id == @match && !@exact_match %>
<tr class="alert alert-info"> <td colspan=5>
<span class="glyphicon glyphicon-search" aria-hidden="true"></span> <strong>Your query "<%= @query %>" would be here.</strong> </td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
<% elsif @model != 'call_numbers' %>
<ul class="browse">
<% @orangelight_browsables.sort.each_with_index do |orangelight_name, i| %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20220601195523_add_vocabulary_to_browse.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddVocabularyToBrowse < ActiveRecord::Migration[6.0]
def change
add_column :alma_orangelight_subjects, :vocabulary, :string
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
t.integer "count"
t.text "sort"
t.string "dir"
t.string "vocabulary"
t.index ["sort"], name: "index_alma_orangelight_subjects_on_sort"
end

Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
system(%Q(#{sql_command} "TRUNCATE TABLE #{BrowseLists.table_prefix}_call_numbers RESTART IDENTITY;"))
system(%Q(#{sql_command} "\\copy #{BrowseLists.table_prefix}_names(sort,count,label,dir) from 'spec/fixtures/authors.sorted' CSV;"))
system(%Q(#{sql_command} "\\copy #{BrowseLists.table_prefix}_name_titles(sort,count,label,dir) from 'spec/fixtures/name_titles.sorted' CSV;"))
system(%Q(#{sql_command} "\\copy #{BrowseLists.table_prefix}_subjects(sort,count,label,dir) from 'spec/fixtures/subjects.sorted' CSV;"))
system(%Q(#{sql_command} "\\copy #{BrowseLists.table_prefix}_subjects(sort,count,label,dir,vocabulary) from 'spec/fixtures/subjects.sorted' CSV;"))
system(%Q(#{sql_command} "\\copy #{BrowseLists.table_prefix}_call_numbers(sort,label,dir,scheme,title,author,date,bibid,holding_id,location) from 'spec/fixtures/call_numbers.sorted' CSV;"))

48 changes: 44 additions & 4 deletions lib/orangelight/browse_lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def core_url
end

def browse_facet(_sql_command, facet_request, conn, facet_field, table_name)
return browse_subject(facet_request, conn, facet_field, table_name) if facet_field == "subject_facet"
resp = conn.get "#{facet_request}#{facet_field}"
req = JSON.parse(resp.body)
CSV.open(output_root.join("#{table_name}.csv"), 'wb') do |csv|
Expand All @@ -62,12 +63,51 @@ def browse_facet(_sql_command, facet_request, conn, facet_field, table_name)
end
end

def load_facet(sql_command, _facet_request, _conn, _facet_field, table_name)
def browse_subject(facet_request, conn, facet_field, table_name)
lcgft_s = 'lcgft_s'
rbgenr_s = 'rbgenr_s'
subjects = JSON.parse(conn.get("#{facet_request}#{facet_field}").body)
lcgft = JSON.parse(conn.get("#{facet_request}#{lcgft_s}").body)
rbgenr = JSON.parse(conn.get("#{facet_request}#{rbgenr_s}").body)
CSV.open("/tmp/#{table_name}.csv", 'wb') do |csv|
label = ''
subjects['facet_counts']['facet_fields'][facet_field.to_s].each_with_index do |fac, index|
if index.even?
label = fac
else
csv << [label.normalize_em, fac.to_s, label, label.dir, 'Library of Congress subject heading']
end
end
lcgft['facet_counts']['facet_fields'][lcgft_s].each_with_index do |fac, index|
if index.even?
label = fac
else
csv << [label.normalize_em, fac.to_s, label, label.dir, 'Library of Congress genre/form term']
end
end
rbgenr['facet_counts']['facet_fields'][rbgenr_s].each_with_index do |fac, index|
if index.even?
label = fac
else
csv << [label.normalize_em, fac.to_s, label, label.dir, 'Rare books genre term']
end
end
end
end

def load_facet(sql_command, _facet_request, _conn, facet_field, table_name)
system(%(cp /tmp/#{table_name}.sorted /tmp/#{table_name}.sorted.backup))
system(%(#{sql_command} "TRUNCATE TABLE #{table_name} RESTART IDENTITY;"))
system(%(#{sql_command} "\\copy #{table_name}(sort,count,label,dir) from '/tmp/#{table_name}.csv' CSV;"))
system(%(#{sql_command} \"\\copy (Select sort,count,label,dir from #{table_name} order by unaccent(sort)) To '/tmp/#{table_name}.sorted' With CSV;"))
load_facet_file(sql_command, "/tmp/#{table_name}.sorted", table_name)
if facet_field == "subject_facet"
system(%(#{sql_command} "\\copy #{table_name}(sort,count,label,dir,vocabulary) from '/tmp/#{table_name}.csv' CSV;"))
system(%(#{sql_command} \"\\copy (Select sort,count,label,dir,vocabulary from #{table_name} order by unaccent(sort)) To '/tmp/#{table_name}.sorted' With CSV;"))
system(%(#{sql_command} "TRUNCATE TABLE #{table_name} RESTART IDENTITY;"))
system(%(#{sql_command} "\\copy #{table_name}(sort,count,label,dir,vocabulary) from '/tmp/#{table_name}.sorted' CSV;"))
else
system(%(#{sql_command} "\\copy #{table_name}(sort,count,label,dir) from '/tmp/#{table_name}.csv' CSV;"))
system(%(#{sql_command} \"\\copy (Select sort,count,label,dir from #{table_name} order by unaccent(sort)) To '/tmp/#{table_name}.sorted' With CSV;"))
load_facet_file(sql_command, "/tmp/#{table_name}.sorted", table_name)
end
end

def load_cn(sql_command, _facet_request, _conn, facet_field, table_name)
Expand Down
Loading

0 comments on commit f2235f4

Please sign in to comment.