Skip to content

Commit

Permalink
Add: configuration options (#45)
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
ewlarson authored Apr 25, 2024
1 parent c5e808d commit 965164a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 74 deletions.
2 changes: 1 addition & 1 deletion app/helpers/blacklight/allmaps/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def georeferenceable?(document = @document)
document.iiif_manifest_url ? true : false
rescue
# Blacklight
document["iiif_manifest_url_ssi"] ? true : false
document[CatalogController.blacklight_config.default_iiif_manifest_field] ? true : false
end
end
end
Expand Down
6 changes: 0 additions & 6 deletions app/jobs/blacklight/allmaps/application_job.rb

This file was deleted.

3 changes: 1 addition & 2 deletions app/models/concerns/blacklight/allmaps/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ module Blacklight
module Allmaps
module SolrDocument
# Blacklight
# @TODO: Make this configurable
def iiif_manifest_url
self["iiif_manifest_url_ssi"]
self[CatalogController.blacklight_config.default_iiif_manifest_field]
end
end
end
Expand Down
10 changes: 7 additions & 3 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ LIGHT=blacklight bundle exec rake blacklight_allmaps:solr
cd .internal_test_app
rake blacklight_allmaps:index:bl_fixtures
rake blacklight_allmaps:sidecars:harvest:allmaps
rake blacklight_allmaps:index:bl_georeferenced_facet
rake blacklight_allmaps:index:georeferenced_facet
rails s
```

Expand All @@ -48,7 +48,7 @@ LIGHT=geoblacklight bundle exec rake blacklight_allmaps:solr
cd .internal_test_app
rake blacklight_allmaps:index:gbl_fixtures
rake blacklight_allmaps:sidecars:harvest:allmaps
rake blacklight_allmaps:index:gbl_georeferenced_facet
rake blacklight_allmaps:index:georeferenced_facet
rails s
```

Expand All @@ -65,4 +65,8 @@ following steps:

## Running the Test suite

LIGHT=geoblacklight bundle exec rake ci
```LIGHT=blacklight bundle exec rake ci```

or

```LIGHT=geoblacklight bundle exec rake ci```
63 changes: 6 additions & 57 deletions lib/blacklight/allmaps/tasks/index.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ namespace :blacklight_allmaps do
end

desc "Index - add Allmaps facet data to GeoBlacklight solr"
task gbl_georeferenced_facet: [:environment] do
task georeferenced_facet: [:environment] do
# Steps
# 1. Use cursor to paginate all documents in Solr
# 2. Determine which documents have georeferenced data
# 3. Clean JSON for re-indexing
# 4. Add gbl_georeferenced_b values
# 4. Add georeferenced values
# 5. Re-index the georeferenced documents

# 1. Get all the documents from Solr
Expand All @@ -36,13 +36,13 @@ namespace :blacklight_allmaps do
fl: "*", # all fields
cursorMark: cursor_mark, # use the cursor mark to handle paging
rows: 1000,
sort: "id asc" # must sort by id to use the cursor mark
sort: "#{CatalogController.blacklight_config.default_solr_unique_key} asc" # must sort by id to use the cursor mark
}
)

response["response"]["docs"].each do |doc|
# 2. Determine which documents have georeferenced data
solr_document = SolrDocument.find(doc["id"])
solr_document = SolrDocument.find(doc[CatalogController.blacklight_config.default_solr_unique_key])
if solr_document.sidecar_allmaps.present? && solr_document.sidecar_allmaps.annotated?

# 3. Clean JSON for re-indexing
Expand All @@ -58,59 +58,8 @@ namespace :blacklight_allmaps do

cleaned_doc = doc.except!(*keys_for_deletion)

# 4. Add gbl_georeferenced_b value
# @TODO: add allmaps_id?
cleaned_doc["gbl_georeferenced_b"] = true

# 5. Re-index the georeferenced documents
Blacklight.default_index.connection.add cleaned_doc
end
end

break if response["nextCursorMark"] == cursor_mark # this means the result set is finished
cursor_mark = response["nextCursorMark"]
end
Blacklight.default_index.connection.commit
end

desc "Index - add Allmaps facet data to Blacklight solr"
task bl_georeferenced_facet: [:environment] do
# Steps
# 1. Use cursor to paginate all documents in Solr
# 2. Determine which documents have georeferenced data
# 3. Clean JSON for re-indexing
# 4. Add bl_georeferenced_bsi values
# 5. Re-index the georeferenced documents

# 1. Get all the documents from Solr
cursor_mark = "*"
loop do
response = Blacklight.default_index.connection.get(
"select", params: {
q: "*:*", # all docs
fl: "*", # all fields
cursorMark: cursor_mark, # use the cursor mark to handle paging
rows: 1000,
sort: "id asc" # must sort by id to use the cursor mark
}
)

response["response"]["docs"].each do |doc|
# 2. Determine which documents have georeferenced data
solr_document = SolrDocument.find(doc["id"])
if solr_document.sidecar_allmaps.present? && solr_document.sidecar_allmaps.annotated?

# 3. Clean JSON for re-indexing
keys_for_deletion = %w[
_version_
timestamp
]

cleaned_doc = doc.except!(*keys_for_deletion)

# 4. Add gbl_georeferenced_b value
# @TODO: add allmaps_id?
cleaned_doc["bl_georeferenced_bsi"] = true
# 4. Add georeferenced value
cleaned_doc[CatalogController.blacklight_config.default_georeferenced_field] = true

# 5. Re-index the georeferenced documents
Blacklight.default_index.connection.add cleaned_doc
Expand Down
10 changes: 6 additions & 4 deletions lib/generators/blacklight/allmaps/blacklight_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BlacklightGenerator < Rails::Generators::Base
desc <<-DESCRIPTION
This generator makes the following changes to your application:
1. Copies stylesheets to Blacklight app
2. Adds Blacklight::Allmaps viewer to CatalogController
2. Adds Blacklight::Allmaps configuration to CatalogController
3. Adds georeferenced facet to CatalogController
4. Includes Blacklight::Allmaps::SolrDocument in SolrDocument
DESCRIPTION
Expand All @@ -21,12 +21,14 @@ def add_bl_stylesheets
end
end

def add_bl_allmaps_viewer
# Use the allmaps viewer
def add_configuration
inject_into_file "app/controllers/catalog_controller.rb", after: "#config.show.thumbnail_field = 'thumbnail_path_ss'" do
"\n
# Blacklight::Allmaps Viewer
config.show.partials.insert(1, :blacklight_allmaps)"
config.show.partials.insert(1, :blacklight_allmaps)
config.default_solr_unique_key = \"id\"
config.default_georeferenced_field = \"bl_georeferenced_bsi\"
config.default_iiif_manifest_field = \"iiif_manifest_url_ssi\""
end
end

Expand Down
12 changes: 11 additions & 1 deletion lib/generators/blacklight/allmaps/geoblacklight_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class GeoblacklightGenerator < Rails::Generators::Base
This generator makes the following changes to your application:
1. Adds stylesheets to application.scss
2. Adds GeoBlacklight to Gemfile
3. Adds Blacklight::Allmaps Tabbed Viewer to CatalogController
3. Adds Blacklight::Allmaps configuration to CatalogController
4. Adds Blacklight::Allmaps Tabbed Viewer to CatalogController
DESCRIPTION

def add_gbl_stylesheets
Expand All @@ -24,6 +25,15 @@ def add_geoblacklight
append_to_file "Gemfile", '"geoblacklight", "~> 4.4"'
end

def add_configuration
inject_into_file "app/controllers/catalog_controller.rb", after: "config.raw_endpoint.enabled = true" do
"\n
# Blacklight::Allmaps Viewer
config.default_solr_unique_key = \"id\"
config.default_georeferenced_field = \"gbl_georeferenced_b\""
end
end

def add_gbl_tabbed_viewer
# Use the tabbed viewer
inject_into_file "app/controllers/catalog_controller.rb", after: "config.show.partials << \"show_default_viewer_container\"" do
Expand Down

0 comments on commit 965164a

Please sign in to comment.