BlacklightFacetExtras: Blacklight plugin that exposes Solr facet parameters (range, query, tagging + exclusions, etc) to Blacklight

Description

BlacklightFacetExtras adds some ugly parsing and manipulating to the Blacklight solr configuration and solr parameter parsing, but seems to get the job done, more or less.

Requirements

A Rails app using the Blacklight plugin (tested against post-version 2.7).

Installation

This is a plugin, not a gem (because the structure was copied from existing plugins; in theory, it should be possible to make this a gem in the future).

A couple different ways to get the source into your vendor/plugins directory.

Go into your application directory, and run:

./script/plugin install git://github.com/cbeer/blacklight_facet_extras.git

Later you can run ./script/plugin update blacklight_facet_extras if you like.

Requires git installed on your system. There are other ways to get the plugin in there too.

OR cd $your_app/vendor/plugins git clone git://github.com/cbeer/blacklight_facet_extras.git

Configuration

config = {

:field_names => [
  "format",
  "dc_date_year_i",
  "timestamp_query",
  "author"
],
:labels => {
  "format" => "display_partial",
  "dc_date_year_i" => "Year",
  "timestamp_query" => "Published"
}
:rangex => {
  "dc_date_year_i" => {  # turns dc_date_year_i into a range facet
    :start => 1940,
    :end => 2010,
    :gap => 10
  }
},
:tag => {
  "format" => {  # turns format into a OR'ed set of facets
    :ex => "format"
  }
},
:query => {
  "timestamp_query" => { # the facet "Published" may contain two values, the results of these queries: 
    'this week' => 'timestamp:[NOW-7DAY TO *]'
    'this week' => 'timestamp:[NOW-1MONTH TO *]'
  }
},
:pivot => {
  "author" => ["author", "title"]
},
:filter => {
  "subject" => lambda { |value| value =~ /--/ }, 
  "date" => lambda { |value| Chronic.parse(value) rescue value }
}

}

Injection

This plugin assumes it is in a Blacklight Rails app, uses Blacklight methods, Rails methods, and standard ruby module includes to inject it’s behaviors into the app.

You can turn off this injection if you like, although it will make the plugin less (or non-) functional unless you manually do similar injection. See lib/blacklight_facet_extras.rb#inject! to see exactly what’s going on.

In any initializer, you can set:

BlacklightFacetExtras.omit_inject = true

to turn off all injection. The plugin will be completely non-functional if you do this, of course. But perhaps you could try to re-use some of it’s classes in a non-Blacklight, highly hacked Blacklight, or even non-Rails application this way.

You can also turn off injection of individual components, which could be more useful:

BlacklightFacetExtras.omit_inject = {
  :view_helpers => false,
  :controller_mixin => false
}

Tests

There are none. This is bad I know, sorry.