Skip to content

Commit

Permalink
Merge pull request #264 from pulibrary/236-staff-data-fields
Browse files Browse the repository at this point in the history
[#236] Add in library_staff_records table: areas_of_study,my_scheduler_link, other_entities - Include areas_of_study and other_entities in virtual searchable column
  • Loading branch information
sandbergja authored Jul 18, 2024
2 parents c6351d2 + e767235 commit 201f255
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 16 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ PLATFORMS
arm64-darwin-22
arm64-darwin-23
x86_64-darwin-22
x86_64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
6 changes: 3 additions & 3 deletions app/models/library_staff_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def library_title
document.library_title
end

def section
document.section
def team
document.team
end

def division
Expand Down Expand Up @@ -89,7 +89,7 @@ def url
end

def doc_keys
[:first_name, :middle_name, :last_name, :netid, :library_title, :phone, :email, :section, :division, :department,
[:first_name, :middle_name, :last_name, :netid, :library_title, :phone, :email, :team, :division, :department,
:unit, :office, :building]
end
end
3 changes: 3 additions & 0 deletions app/models/library_staff_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def self.new_from_csv(row)
record.building = row[8]
record.department = row[9]
record.unit = row[11]
record.areas_of_study = row[14]&.gsub('//', ', ')
record.my_scheduler_link = row[18]
record.other_entities = row[19]&.gsub('//', ', ')
record.library_title = title
record.title = title
record.save! if record.valid?
Expand Down
2 changes: 1 addition & 1 deletion app/services/library_staff_loading_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def class_to_load

def expected_headers
%w[puid netid phone name lastName firstName email address building department division
unit team title areasOfStudy websiteUrl bios expertise mySchedulerLink]
unit team title areasOfStudy websiteUrl bios expertise mySchedulerLink otherEntities]
end

def uri
Expand Down
20 changes: 20 additions & 0 deletions db/migrate/20240716210532_add_staff_records_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class AddStaffRecordsFields < ActiveRecord::Migration[7.1]

def up
change_table :library_staff_records do |t|
t.column :areas_of_study, :string
t.column :other_entities, :string
t.column :my_scheduler_link, :string
t.rename :section, :team
end
end
def down
change_table :library_staff_records do |t|
t.remove :areas_of_study
t.remove :other_entities
t.remove :my_scheduler_link
t.rename :team, :section
end
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class UpdateSearchableLibraryStaffRecords < ActiveRecord::Migration[7.1]
def up
change_table :library_staff_records do |t|
t.remove :searchable
t.virtual :searchable, type: :tsvector,
as: "to_tsvector('english', coalesce(title, '') || ' ' || " \
"coalesce(first_name, '') || ' ' || " \
"coalesce(middle_name, '') || ' ' || " \
"coalesce(last_name, '') || ' ' || " \
"coalesce(title, '') || ' ' || " \
"coalesce(email, '') || ' ' || " \
"coalesce(department, '') || ' ' || " \
"coalesce(office, '') || ' ' || " \
"coalesce(building, '') || ' ' || " \
"coalesce(team, '') || ' ' || " \
"coalesce(division, '') || ' ' || " \
"coalesce(unit, '') || ' ' ||" \
"coalesce(areas_of_study, '') || ' ' || " \
"coalesce(other_entities, ''))",
stored: true
t.index ["searchable"], name: "staff_search_idx", using: :gin
end
end

def down
change_table :library_staff_records do |t|
t.remove :searchable
t.virtual :searchable, type: :tsvector,
as: "to_tsvector('english', coalesce(title, '') || ' ' || " \
"coalesce(first_name, '') || ' ' || " \
"coalesce(middle_name, '') || ' ' || " \
"coalesce(last_name, '') || ' ' || " \
"coalesce(title, '') || ' ' || " \
"coalesce(email, '') || ' ' || " \
"coalesce(department, '') || ' ' || " \
"coalesce(office, '') || ' ' || " \
"coalesce(building, '') || ' ' || " \
"coalesce(team, '') || ' ' || " \
"coalesce(division, '') || ' ' || " \
"coalesce(unit, ''))" ,
stored: true
end
end
end
9 changes: 6 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_07_10_210913) do
ActiveRecord::Schema[7.1].define(version: 2024_07_16_214838) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -51,15 +51,18 @@
t.string "title", null: false
t.string "library_title", null: false
t.string "email", null: false
t.string "section"
t.string "team"
t.string "division"
t.string "department"
t.string "unit"
t.string "office"
t.string "building"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.virtual "searchable", type: :tsvector, as: "to_tsvector('english'::regconfig, (((((((((((((((((((((((COALESCE(title, ''::character varying))::text || ' '::text) || (COALESCE(first_name, ''::character varying))::text) || ' '::text) || (COALESCE(middle_name, ''::character varying))::text) || ' '::text) || (COALESCE(last_name, ''::character varying))::text) || ' '::text) || (COALESCE(title, ''::character varying))::text) || ' '::text) || (COALESCE(email, ''::character varying))::text) || ' '::text) || (COALESCE(department, ''::character varying))::text) || ' '::text) || (COALESCE(office, ''::character varying))::text) || ' '::text) || (COALESCE(building, ''::character varying))::text) || ' '::text) || (COALESCE(section, ''::character varying))::text) || ' '::text) || (COALESCE(division, ''::character varying))::text) || ' '::text) || (COALESCE(unit, ''::character varying))::text))", stored: true
t.string "areas_of_study"
t.string "other_entities"
t.string "my_scheduler_link"
t.virtual "searchable", type: :tsvector, as: "to_tsvector('english'::regconfig, (((((((((((((((((((((((((((COALESCE(title, ''::character varying))::text || ' '::text) || (COALESCE(first_name, ''::character varying))::text) || ' '::text) || (COALESCE(middle_name, ''::character varying))::text) || ' '::text) || (COALESCE(last_name, ''::character varying))::text) || ' '::text) || (COALESCE(title, ''::character varying))::text) || ' '::text) || (COALESCE(email, ''::character varying))::text) || ' '::text) || (COALESCE(department, ''::character varying))::text) || ' '::text) || (COALESCE(office, ''::character varying))::text) || ' '::text) || (COALESCE(building, ''::character varying))::text) || ' '::text) || (COALESCE(team, ''::character varying))::text) || ' '::text) || (COALESCE(division, ''::character varying))::text) || ' '::text) || (COALESCE(unit, ''::character varying))::text) || ' '::text) || (COALESCE(areas_of_study, ''::character varying))::text) || ' '::text) || (COALESCE(other_entities, ''::character varying))::text))", stored: true
t.index ["searchable"], name: "staff_search_idx", using: :gin
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
puid,netid,phone,name,lastName,firstName,email,address,building,department,division,unit,team,title,areasOfStudy,websiteUrl,bios,expertise,mySchedulerLink
,,,,,,,,,,,,,,,,,,
"000000001","lucyfs","(555) 123-1234","Stardust, Lucy","Stardust","Lucy Fae",[email protected],Forrestal,Recap Library,Office of the Deputy Dean of Libraries,Facilities,,,"Pest Removal Specialist",,,,,
,,,,,,,,,,,,,,,,,,
puid,netid,phone,name,lastName,firstName,email,address,building,department,division,unit,team,title,areasOfStudy,websiteUrl,bios,expertise,mySchedulerLink,otherEntities
,,,,,,,,,,,,,,,,,,,
"000000001","lucyfs","(555) 123-1234","Stardust, Lucy","Stardust","Lucy Fae",[email protected],Forrestal,Recap Library,Office of the Deputy Dean of Libraries,Facilities,,,"Pest Removal Specialist",,,,,,
,,,,,,,,,,,,,,,,,,,
10 changes: 5 additions & 5 deletions spec/fixtures/files/library_staff/staff-directory.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"puid","netid","phone","name","lastName","firstName",email,address,building,department,division,unit,team,"title","areasOfStudy","websiteUrl","bios","expertise","mySchedulerLink"
"000000001","lucyfs","(555) 123-1234","Stardust, Lucy","Stardust","Lucy Fae",[email protected],Forrestal,Recap Library,Office of the Deputy Dean of Libraries,Facilities,,,"Pest Removal Specialist",,,,,
"000000002","nimbuskt","(555) 111-1111","Trout, Nimbus","Trout","Nimbus Kilgore",[email protected],A-200,Firestone Library,Office of the Deputy Dean of Libraries,Information Technology,IT Operations and Digitization,,"Nap Coordinator","Naps//Coordination",,,,
"000000003","tiberius","(555) 222-2222","Adams, Tiberius","Adams","Spot Tiberius",[email protected],B-300,Firestone Library,My Department,Library - Collections and Access Services,Access & Fulfillment Services,,"Lead Hairball Engineer",,,,,
"000000010","brutus","(555) 222-2222","Cat, Brutus","Cat","Brutus The",[email protected],B-300,Stokes Library,My Department,Library - Collections and Access Services,PCRP - Physical Collections Receipt & Processing Unit,,"Fluffiest cat",,,,,
"puid","netid","phone","name","lastName","firstName",email,address,building,department,division,unit,team,"title","areasOfStudy","websiteUrl","bios","expertise","mySchedulerLink","otherEntities"
"000000001","lucyfs","(555) 123-1234","Stardust, Lucy","Stardust","Lucy Fae",[email protected],Forrestal,Recap Library,Office of the Deputy Dean of Libraries,Facilities,,,"Pest Removal Specialist",,,,,,"MS Chadha Center for Global India"
"000000002","nimbuskt","(555) 111-1111","Trout, Nimbus","Trout","Nimbus Kilgore",[email protected],A-200,Firestone Library,Office of the Deputy Dean of Libraries,Information Technology,IT Operations and Digitization,,"Nap Coordinator","Naps//Coordination",,,,,"Center for Culture, Society and Religion//University Center for Human Values"
"000000003","tiberius","(555) 222-2222","Adams, Tiberius","Adams","Spot Tiberius",[email protected],B-300,Firestone Library,My Department,Library - Collections and Access Services,Access & Fulfillment Services,,"Lead Hairball Engineer",,,,,,"Center for International Security Studies (CISS)//Center for the Study of Democratic Politics (CSDP)//Empirical Studies of Conflict (ESOC)//Innovations for Successful Societies (ISS)//Liechtenstein Institute on Self-Determination (LISD)//Niehaus Center for lization and Governance (NCGG)//Princeton Survey Research Center (SRC)//Research Program in Political Economy (RPPE)"
"000000010","brutus","(555) 222-2222","Cat, Brutus","Cat","Brutus The",[email protected],B-300,Stokes Library,My Department,Library - Collections and Access Services,PCRP - Physical Collections Receipt & Processing Unit,,"Fluffiest cat",,,,,,
6 changes: 6 additions & 0 deletions spec/models/library_staff_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@
expect(results[0].first_name).to eq('Nimbus Kilgore')
expect(results[1].first_name).to eq('Spot Tiberius')
end

it 'finds records by other entities' do
results = described_class.query('Center for Global')
expect(results.length).to eq(1)
expect(results[0].other_entities).to eq('MS Chadha Center for Global India')
end
end
end

0 comments on commit 201f255

Please sign in to comment.