Skip to content

Commit

Permalink
Add pulmap solr config
Browse files Browse the repository at this point in the history
Add map service
Add route and controller for maps
Add service controller to refactor the rest of the controllers

Co-authored-by: Jane Sandberg <[email protected]>
  • Loading branch information
christinach and sandbergja committed Sep 14, 2023
1 parent fe0b560 commit 19cb275
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
/config/master.key

.byebug_history
solr
/solr/*
8 changes: 8 additions & 0 deletions .lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ services:
core: findingaids
config:
dir: "solr/solr_configs/pulfalight-production/conf"
pulmap:
type: solr:8.4
portforward: true
core: pulmap
config:
dir: "solr/solr_configs/pulmap/conf"
proxy:
catalog_solr:
- catalog.dev.solr.lndo.site:8983
dpul_solr:
- dpul.dev.solr.lndo.site:8983
findingaids_solr:
- findingaids.dev.solr.lndo.site:8983
pulmap:
- pulmap.dev.solr.lndo.site:8983
20 changes: 4 additions & 16 deletions app/controllers/art_museum_controller.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# frozen_string_literal: true

class ArtMuseumController < ApplicationController
class ArtMuseumController < ServiceController
rescue_from ActionController::ParameterMissing, with: :show_query_errors
def show
@art_museum_query = ArtMuseum.new(query_terms: query_params)

render json: art_museum_query.our_response
def initialize
super
@service = ArtMuseum
end

private

def query_params
params.require(:query)
end

def show_query_errors(exception)
render json: { error: exception.message }, status: :bad_request
end

attr_reader :art_museum_query
end
20 changes: 4 additions & 16 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# frozen_string_literal: true

class CatalogController < ApplicationController
class CatalogController < ServiceController
rescue_from ActionController::ParameterMissing, with: :show_query_errors
def show
@catalog_query = Catalog.new(query_terms: query_params)

render json: catalog_query.our_response
def initialize
super
@service = Catalog
end

private

def query_params
params.require(:query)
end

def show_query_errors(exception)
render json: { error: exception.message }, status: :bad_request
end

attr_reader :catalog_query
end
20 changes: 4 additions & 16 deletions app/controllers/dpul_controller.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# frozen_string_literal: true

class DpulController < ApplicationController
class DpulController < ServiceController
rescue_from ActionController::ParameterMissing, with: :show_query_errors
def show
@dpul_query = Dpul.new(query_terms: query_params)

render json: dpul_query.our_response
def initialize
super
@service = Dpul
end

private

def query_params
params.require(:query)
end

def show_query_errors(exception)
render json: { error: exception.message }, status: :bad_request
end

attr_reader :dpul_query
end
20 changes: 4 additions & 16 deletions app/controllers/findingaids_controller.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# frozen_string_literal: true

class FindingaidsController < ApplicationController
class FindingaidsController < ServiceController
rescue_from ActionController::ParameterMissing, with: :show_query_errors
def show
@findingaids_query = Findingaids.new(query_terms: query_params)

render json: findingaids_query.our_response
def initialize
super
@service = Findingaids
end

private

def query_params
params.require(:query)
end

def show_query_errors(exception)
render json: { error: exception.message }, status: :bad_request
end

attr_reader :findingaids_query
end
10 changes: 10 additions & 0 deletions app/controllers/pulmap_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class PulmapController < ServiceController
rescue_from ActionController::ParameterMissing, with: :show_query_errors

def initialize
super
@service = Pulmap
end
end
21 changes: 21 additions & 0 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class ServiceController < ApplicationController
def show
@query = service.new(query_terms: query_params)

render json: query.our_response
end

private

attr_reader :query, :service

def query_params
params.require(:query)
end

def show_query_errors(exception)
render json: { error: exception.message }, status: :bad_request
end
end
32 changes: 32 additions & 0 deletions app/models/pulmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

# This class is responsible for querying Findingaids (aka PULFAlight)
class Pulmap
include ActiveModel::API
include Parsed
include Solr
attr_reader :query_terms, :service, :service_response

def initialize(query_terms:)
@query_terms = query_terms
@service = 'pulmap'
@service_response = solr_service_response(query_terms:)
end

def solr_collection
'pulmap'
end

def solr_fields
%w[uuid dc_title_s dc_creator_sm dc_publisher_s dc_format_s dc_description_s dc_rights_s layer_geom_type_s]
end

def solr_sort
'score desc'
end

def more_link
@service = 'maps'
super
end
end
47 changes: 47 additions & 0 deletions app/models/pulmap_document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

# This class is responsible for getting relevant
# metadata from Pulmap's JSON
class PulmapDocument < Document
private

def id
json[:uuid]
end

def url
"https://maps.princeton.edu/catalog/#{id}"
end

def title
json[:dc_title_s]
end

def creator
json[:dc_creator_sm]&.first
end

def publisher
json[:dc_publisher_s]
end

def type
json[:dc_format_s]
end

def description
json[:dc_description_s]
end

def doc_keys
[:rights, :layer_geom_type]
end

def rights
json[:dc_rights_s]
end

def layer_geom_type
json[:layer_geom_type_s]
end
end
13 changes: 13 additions & 0 deletions config/allsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ default: &default
port: 8983
collection: "pulfalight-production"
ssl: true
pulmap:
solr:
host: "lib-solr8-prod.princeton.edu"
port: 8983
collection: "pulmap"
ssl: true

development:
<<: *default
Expand All @@ -40,6 +46,13 @@ development:
port: <%= ENV["lando_findingaids_solr_conn_port"] %>
collection: "findingaids"
ssl: false

pulmap:
solr:
host: <%= ENV["lando_pulmap_solr_conn_host"] %>
port: <%= ENV["lando_pulmap_solr_conn_port"] %>
collection: "pulmap"
ssl: false

staging:
<<: *default
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
get '/search/catalog/', to: 'catalog#show', defaults: { format: 'json' }
get '/search/dpul/', to: 'dpul#show', defaults: { format: 'json' }
get '/search/findingaids/', to: 'findingaids#show', defaults: { format: 'json' }
get '/search/pulmap', to: 'pulmap#show', defaults: { format: 'json' }
end
72 changes: 72 additions & 0 deletions spec/fixtures/files/solr/pulmap/scribner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"responseHeader":{
"zkConnected":true,
"status":0,
"QTime":0,
"params":{
"ps":"0",
"indent":"2",
"echoParams":"all",
"fl":"uuid,dc_title_s,dc_creator_sm,dc_publisher_s,dc_format_s,dc_description_s,dc_rights_s,layer_geom_type_s",
"publisher_qf":"\n dc_publisher_ti^5\n dc_creator_tmi\n ",
"subject_qf":"\n dc_subject_tmi\n dct_spatial_tmi\n ",
"_forwardedCount":"1",
"tie":"0.01",
"defType":"edismax",
"qf":"\n text^1\n dc_description_ti^2\n dc_creator_tmi^3\n dc_publisher_ti^3\n dct_isPartOf_tmi^4\n dc_subject_tmi^5\n dct_spatial_tmi^5\n dct_temporal_tmi^5\n dc_title_ti^6\n dc_rights_ti^7\n dct_provenance_ti^8\n layer_geom_type_ti^9\n layer_slug_ti^10\n dc_identifier_ti^10\n ",
"title_qf":"\n dc_title_ti^10\n dct_isPartOf_tmi\n ",
"wt":"json",
"mm":"1<-1 3<50% 6<90%",
"qs":"1",
"q.alt":"*:*",
"facet.field":["dct_isPartOf_sm",
"dct_provenance_s",
"dct_spatial_sm",
"dc_creator_sm",
"dc_format_s",
"dc_language_s",
"dc_publisher_s",
"dc_rights_s",
"dc_subject_sm",
"layer_geom_type_s",
"solr_year_i"],
"publisher_pf":"\n dc_publisher_ti^5\n dc_creator_tmi\n ",
"subject_pf":"\n dc_subject_tmi\n dct_spatial_tmi\n ",
"start":"0",
"sort":"score desc",
"rows":"3",
"q":"scribner",
"facet.limit":"10",
"spellcheck":"true",
"pf":"\n text^1\n dc_description_ti^2\n dc_creator_tmi^3\n dc_publisher_ti^3\n dct_isPartOf_tmi^4\n dc_subject_tmi^5\n dct_spatial_tmi^5\n dct_temporal_tmi^5\n dc_title_ti^6\n dc_rights_ti^7\n dct_provenance_ti^8\n layer_geom_type_ti^9\n layer_slug_ti^10\n dc_identifier_ti^10\n ",
"title_pf":"\n dc_title_ti^10\n dct_isPartOf_tmi\n ",
"facet.mincount":"1",
"facet":"false"}},
"response":{"numFound":16,"start":0,"docs":[
{
"dc_rights_s":"Public",
"dc_title_s":"Indiana.",
"dc_description_s":"Shows railroads and canals.; Compiled according to Census of 1880 and latest surveys.; From: Encyclopaedia Britannica, 9th ed. Vol. XII, plate VII. Scale approximately 1:2,000,000",
"dc_format_s":"JPEG",
"dc_publisher_s":"Scribner"},
{
"uuid":"princeton-6682x6396",
"dc_title_s":"South America : wall-atlas",
"dc_rights_s":"Public",
"dc_description_s":"\"Card series.\" Relief shown by hachures and form lines. \"Entered according to Act of Congress in the year 1865 by Charles Scribner & Co. ...\" Inset: Profiles from west to east. Wall map. Scribner, Armstrong, & Co. flourished ca. 1871-1879. cf. Tooley's dictionary of mapmakers.",
"dc_creator_sm":["Guyot, A. (Arnold), 1807-1884"],
"dc_publisher_s":"New York : Published by Scribner, Armstrong & Co. ... [between 1871 and 1879].",
"layer_geom_type_s":"Image",
"dc_format_s":"TIFF"},
{
"uuid":"princeton-2b88qf00b",
"dc_title_s":"Africa : wall-atlas",
"dc_rights_s":"Public",
"dc_description_s":"\"Card series.\" Relief shown by hachures and form lines. \"Entered according to Act of Congress in the year 1865 by Charles Scribner & Co. ...\" Insets: Profiles from north to south -- Profiles from east to west. Wall map. Scribner, Armstrong, & Co. flourished ca. 1871-1879. cf. Tooley's dictionary of mapmakers.",
"dc_creator_sm":["Guyot, A. (Arnold), 1807-1884"],
"dc_publisher_s":"New York : Scribner, Armstrong, & Co. [between 1871 and 1879].",
"layer_geom_type_s":"Image",
"dc_format_s":"TIFF"}]
},
"spellcheck":{
"suggestions":[]}}
Loading

0 comments on commit 19cb275

Please sign in to comment.