Skip to content
This repository was archived by the owner on May 17, 2026. It is now read-only.

Solr: Query for all works

Paul Danelli edited this page Feb 18, 2022 · 2 revisions

Querying Solr is much faster than querying Fedora, so this is advisable in almost all circumstances. By using the ActiveFedora::SolrSerice you can run queries and then if necessary turn the records back into Hyrax Works via an additional find query.

# Example query looks for all works with a creator using the email provided
query_string = "generic_type_sim:Work AND (creator_tesim:\"*#{email}*\")"
docs = ActiveFedora::SolrService.get(query_string, rows: 1_000_000).dig("response", "docs")

# Simple SolrHit wrapper
docs.map { |doc| ActiveFedora::SolrHit.new(doc) }

You could also use the reify method to turn the SolrHit into the correct work:

docs.map { |doc| ActiveFedora::SolrHit.new(doc).reify }

One thing to note however, is that this will take the work UUID from the SolrHit and perform an ActiveFedora::find(id) query for each of them, which is going to be very slow.

Clone this wiki locally