An extension to projecthydra/solrizer that provides utilities for loading objects from Fedora Repositories and creating solr documents from them.


The gem is hosted on The best way to manage the gems for your project is to use bundler. Create a Gemfile in the root of your application and include the following:

source ""

gem 'solrizer-fedora'


bundle install

Pre-requisite to Use of Solrizer-Fedora

In order to use solrizer-fedora, you must have a Solr and a Fedora instance available. The easiest approach is to set up an instance of hydra-jetty.

Setup local hydra-jetty

In order to use solrizer-fedora, you must first set up an instance of hydra-jetty.

Once you have set this up, cd into the directory and type:

java -jar start.jar

You must tell the app where to find fedora and solr. Put that information into config/fedora.yml and config/solr.yml:

Sample config files:


    url: http://fedoraAdmin:[email protected]:8983/fedora
    url: http://fedoraAdmin:[email protected]:8983/fedora
    url: http://fedoraAdmin:[email protected]:8080/fedora


    url: http://localhost:8983/solr
    url: http://localhost:8983/solr
test: &<span class="caps">TEST</span>
    url: http://localhost:8983/solr
    url: http://localhost:8983/solr
    url: http://localhost:8080/solr/production 
    url: http://localhost:8080/solr/production 


Fire up the console:

Start up a console and load solrizer-fedora:

require "rubygems"
require "solrizer-fedora"

Initialize ActiveFedora:


Create an instance of Solrizer::Fedora::Solrizer:

solrizer =

Or, if you want to index full text rather than just fields (and you have provided a full text solr index in your solr.yml):

full_text_solrizer =>true)

Solrizing a single object in your repository:

If you have an existing object in your repository, you can solrize it by passing its pid:

solrizer.solrize "demo:5"

If you have either an instance of ActiveFedora::Base or Fedora::Object, you can solrize it by passing the object itself:

my_object =

solrizer.solrize my_object

To view the resulting document, open a web browser and go to the jetty’s solr admin page (most likely http://localhost/solr/admin) and query your solr instance for the pid (e.g. id:demo\:5).

Solrizing all the objects in your repository:

In order to solrize all the objects in your repository, run:


Advanced Usage

Solrizer-fedora inspects your repository objects and attempts to match your objects to your ruby models based on the hasModel declarations in the RELS-EXT datastream.

Go to the fedora admin interface (http://FEDORA_BASE_URL/fedora/admin) and create a new object with an PID of “changeme:123” and whatever Label you want.

Once you have created that object you will need to add the RELS-EXT datastream to it. Make the datastream ID “RELS-EXT”, MIME-Type of “application/rdf+xml”, and put the XML below in the XML from text field.

<rdf:RDF xmlns:rdf="">
  <rdf:Description rdf:about="info:fedora/changeme:123">
    <hasModel xmlns="info:fedora/fedora-system:def/model#" rdf:resource="info:fedora/afmodel:MyObject"></hasModel>

Solrizer-fedora will check to see if you have a matching ruby model called MyObject. If you do, it will load it and add any specific solr fields specified. So, assuming the following model:

class MyObject < ActiveFedora::Base

   :name => "properties", :type=> ActiveFedora::MetadataDatastream do |m|
    m.field 'foo', :string


Now add another datastream to the changeme:123 object and give it a datastream ID of “properties”, a MIME-Type of “text/xml”, and add the following to the XML from text field:


If you still have your fedora-solrizer class from above you can now solrize the object by ID:

solrizer.solrize "changeme:123"  

Now your solr doc with the “changeme:123” ID will include the following:

<arr name="foo_t">

Rake tasks


Required Argument:

  • PID=ns:123 The pid of the object to index

Optional Arguments:

  • FULL_TEXT=true does a full text index


Optional Arguments:

  • FULL_TEXT=true does a full text index
  • INDEX_LIST=filename.csv indexes only the pids in the csv file

Modifying and Testing the Solrizer-Fedora gem

In order to run the RSpec tests, it is necessary to have a hydra-jetty instance running. This can be accomplished two ways:

Using the bundled jetty instance:

Configure the bundled hydra-jetty instance.

git submodule init
git submodule update

Once you have updated the jetty submodule, you can easily run the rspec tests with the following rake task:

rake hudson

While the primary intention of this task is to provide test coverage and documentation out on projecthydra’s continuous integration server, it can also be used locally to run tests without having to install and configure an instance of hydra-jetty.

Note: if you have another instance of hydra-jetty running, you should either close it down prior to running the rake hudson task.

Using a different instance of hydra-jetty:

If you prefer, you can run the specs against a different hydra-jetty instance. Follow the instructions included with those projects to start the jetty instance.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so it doesn’t get broken unintentionally in a future version.
  • Commit, do not mess with rake file, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.


Copyright © 2010 Matt Zumwalt and MediaShelf. See LICENSE for details.