Skip to content

Commit

Permalink
Use faster solr faceting for dashboard stats (#6865)
Browse files Browse the repository at this point in the history
  • Loading branch information
CGillen authored Aug 7, 2024
1 parent cc5b673 commit 519dc97
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions app/models/hyrax/statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,20 @@ def statistics(object, start_date, user_id = nil)

def query_works(query)
models = Hyrax::ModelRegistry.work_rdf_representations.map { |m| "\"#{m}\"" }
Hyrax::SolrService.query("has_model_ssim:(#{models.join(' OR ')})", fl: query, rows: 100_000)
response = Hyrax::SolrService.get(fq: "has_model_ssim:(#{models.join(' OR ')})", 'facet.field': query, 'facet.missing': true, rows: 0)
Hash[*response['facet_counts']['facet_fields'][query]]
end

def work_types
results = query_works("human_readable_type_tesim")
results.group_by { |result| result['human_readable_type_tesim']&.join('') || "Unknown" }.transform_values(&:count)
types = query_works("human_readable_type_sim")
types['Unknown'] = types.delete(nil)
types
end

def resource_types
results = query_works("resource_type_tesim")
resource_types = []
results.each do |y|
if y["resource_type_tesim"].nil? || (y["resource_type_tesim"] == [""])
resource_types.push("Unknown")
elsif y["resource_type_tesim"].count > 1
y["resource_type_tesim"].each do |t|
resource_types.push(t)
end
else
resource_types.push(y["resource_type_tesim"].join(""))
end
end
resource_types.group_by { |rt| rt }.transform_values(&:count)
types = query_works("resource_type_sim")
types['Unknown'] = types.delete(nil)
types
end

private
Expand Down

0 comments on commit 519dc97

Please sign in to comment.