class SitemapController
Public Instance Methods
index()
click to toggle source
# File lib/generators/blacklight/sitemaps/templates/sitemap_controller.rb, line 4 def index @access_list = access_list end
show()
click to toggle source
# File lib/generators/blacklight/sitemaps/templates/sitemap_controller.rb, line 8 def show @solr_response = Blacklight.default_index.connection.select( params: { q: "{!prefix f=hashed_id_si v=#{access_params}}}", defType: 'lucene', fl: 'id,timestamp', facet: false, rows: 3_000_000 # a sufficiently large number to prevent Solr from ever attempting paging } ) end
Private Instance Methods
access_list()
click to toggle source
Important note: 4,000 is a good average_chunk because it's large enough to fit into the 4096 leaves option (3 character placeholders) scheme, and can be rendered by Rails performantly. Larger numbers can tax Rails.
# File lib/generators/blacklight/sitemaps/templates/sitemap_controller.rb, line 35 def access_list approximate_chunk_size = [4000, max_documents].min # Sufficiently less than 50,000 max per sitemap return [] if approximate_chunk_size == 0 access = (Math.log(max_documents / approximate_chunk_size) / Math.log(16)).ceil (0...(16**access)) .to_a .map { |v| v.to_s(16).rjust(access, '0') } end
access_params()
click to toggle source
# File lib/generators/blacklight/sitemaps/templates/sitemap_controller.rb, line 23 def access_params params.require(:id) # :id collides with Solr id but they are different. This is the Sitemap ID. end
max_documents()
click to toggle source
# File lib/generators/blacklight/sitemaps/templates/sitemap_controller.rb, line 27 def max_documents Rails.cache.fetch('index_max_docs', expires_in: 1.day) do Blacklight.default_index.connection.select(params: { q: '*:*', rows: 0 })['response']['numFound'] end end