blacklight 4.6.3 → 4.7.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/controllers/bookmarks_controller.rb +4 -0
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +76 -21
- data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +8 -1
- data/app/views/catalog/_citation.html.erb +1 -1
- data/app/views/catalog/_did_you_mean.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +1 -1
- data/blacklight.gemspec +1 -1
- data/config/locales/blacklight.en.yml +3 -0
- data/config/locales/blacklight.fr.yml +3 -0
- data/doc/Atom-Responses.md +90 -0
- data/doc/Blacklight-3.0-Release-Notes-And-Upgrade-Guide.md +107 -0
- data/doc/Blacklight-3.2-Release-Notes-and-Upgrade-Guide.md +191 -0
- data/doc/Blacklight-3.3-release-notes-and-upgrade-guide.md +37 -0
- data/doc/Blacklight-3.4-release-notes-and-upgrade-guide.md +27 -0
- data/doc/Blacklight-3.5-release-notes-and-upgrade-guide.md +44 -0
- data/doc/Blacklight-3.6-release-notes-and-upgrade-guide.md +25 -0
- data/doc/Blacklight-3.7-release-notes-and-upgrade-guide.md +80 -0
- data/doc/Blacklight-3.8-release-notes-and-upgrade-guide.md +11 -0
- data/doc/Blacklight-4.0-release-notes-and-upgrade-guide.md +135 -0
- data/doc/Blacklight-4.1-release-notes-and-upgrade-guide.md +17 -0
- data/doc/Blacklight-4.2-release-notes-and-upgrade-guide.md +25 -0
- data/doc/Blacklight-4.3-release-notes-and-upgrade-guide.md +21 -0
- data/doc/Blacklight-4.4-release-notes-and-upgrade-guide.md +41 -0
- data/doc/Blacklight-Add-ons.md +28 -0
- data/doc/Blacklight-configuration.md +411 -0
- data/doc/Blacklight-on-Heroku.md +135 -0
- data/doc/Code4Lib-2014.md +48 -0
- data/doc/Community-principles.md +44 -0
- data/doc/Configuring-and-Customizing-Blacklight.md +271 -0
- data/doc/Configuring-rails-routes.md +13 -0
- data/doc/Contributing-to-Blacklight.md +25 -0
- data/doc/Examples.md +94 -0
- data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +141 -0
- data/doc/FAQs.md +1 -0
- data/doc/Home.md +80 -0
- data/doc/How-to-release-a-version.md +29 -0
- data/doc/Indexing-your-data-into-solr.md +32 -0
- data/doc/Integration-with-Rails-Footnotes.md +20 -0
- data/doc/Internationalization.md +32 -0
- data/doc/JSON-API.md +17 -0
- data/doc/Pagination.md +51 -0
- data/doc/Providing-your-own-view-templates.md +109 -0
- data/doc/Quickstart.md +115 -0
- data/doc/README_SOLR.md +245 -0
- data/doc/Release-Notes-And-Upgrade-Guides.md +20 -0
- data/doc/Roadmap.md +43 -0
- data/doc/Sunspot-for-indexing.md +46 -0
- data/doc/Theming.md +64 -0
- data/doc/User-Authentication.md +60 -0
- data/doc/testing.md +57 -0
- data/lib/blacklight.rb +6 -0
- data/lib/blacklight/base.rb +2 -0
- data/lib/blacklight/catalog.rb +4 -3
- data/lib/blacklight/catalog/search_context.rb +8 -1
- data/lib/blacklight/configurable.rb +1 -2
- data/lib/blacklight/solr/document.rb +2 -1
- data/lib/blacklight/solr_helper.rb +8 -0
- data/lib/blacklight/user.rb +7 -2
- data/lib/blacklight/utils.rb +9 -1
- data/lib/generators/blacklight/templates/catalog_controller.rb +1 -4
- data/spec/helpers/blacklight_helper_spec.rb +84 -9
- data/spec/helpers/hash_as_hidden_fields_spec.rb +1 -1
- data/spec/lib/blacklight_spec.rb +6 -0
- data/spec/lib/blacklight_user_spec.rb +4 -0
- data/spec/lib/solr_helper_spec.rb +8 -6
- data/spec/lib/utils_spec.rb +35 -5
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +1 -1
- metadata +49 -8
@@ -0,0 +1,32 @@
|
|
1
|
+
Blacklight uses the [Rails i18n framework|http://guides.rubyonrails.org/i18n.html] to provide a translatable (or, application customized) version of most text in the Blacklight default templates. Blacklight ships with a set of English translations (other languages welcome!) in [blacklight.en.yml|https://github.com/projectblacklight/blacklight/blob/master/config/locales/blacklight.en.yml].
|
2
|
+
|
3
|
+
You can also customize the English strings in your local application, which will override the Blacklight-distributed strings.
|
4
|
+
|
5
|
+
## A quick i18n example
|
6
|
+
A locale entry that looks like this:
|
7
|
+
|
8
|
+
```yaml
|
9
|
+
en:
|
10
|
+
blacklight:
|
11
|
+
application_name: 'Blacklight'
|
12
|
+
```
|
13
|
+
|
14
|
+
Is referenced in the Blacklight code as:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
I18n.t 'blacklight.application_name'
|
18
|
+
# OR
|
19
|
+
t('blacklight.application_name')
|
20
|
+
```
|
21
|
+
|
22
|
+
You could override this in your application's ```config/locales/en.yml```:
|
23
|
+
|
24
|
+
```yaml
|
25
|
+
en:
|
26
|
+
blacklight:
|
27
|
+
application_name: 'My Blacklight Application'
|
28
|
+
```
|
29
|
+
|
30
|
+
And then everywhere Blacklight views show the application name, it will use your label ("My Blacklight Application") instead of ours ("Blacklight").
|
31
|
+
|
32
|
+
There are other i18n tricks (that we use) covered in the [Rails i18n Rails guide|http://guides.rubyonrails.org/i18n.html], including pluralization, interpolation, etc.
|
data/doc/JSON-API.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Feature added in v4.5
|
2
|
+
|
3
|
+
By default the search page, the show page, and the facet list page can return JSON responses provided you set the format suffix:
|
4
|
+
|
5
|
+
Search results
|
6
|
+
`/catalog.json?search_field=all_fields&q=auckland`
|
7
|
+
|
8
|
+
Facet list
|
9
|
+
`/catalog/facet/subject_topic_facet.json`
|
10
|
+
|
11
|
+
Single record
|
12
|
+
`/catalog/2009002600.json`
|
13
|
+
|
14
|
+
|
15
|
+
If you wish to alter the format of the returned JSON, you can override `render_search_results_as_json` and `render_facet_list_as_json` methods in CatalogController.
|
16
|
+
|
17
|
+
See: https://github.com/projectblacklight/blacklight/blob/master/lib/blacklight/catalog.rb#L175-L191
|
data/doc/Pagination.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
Blacklight uses [kaminari](https://github.com/amatsuda/kaminari) for providing pagination of Solr responses.
|
2
|
+
|
3
|
+
One motivation for this is so a pagination view theme can be provided that you can use for your custom code with ordinary ActiveRecord or anything else kaminari can handle, to have consistency between the rest of your app's pagination and Blacklight's Solr response pagination.
|
4
|
+
|
5
|
+
## How it works
|
6
|
+
|
7
|
+
The Blacklight #paginate_params helper method takes an RSolr::Response, and converts it to something Kaminari #paginate can handle. (Basically just by translating some attribute names). So you could call:
|
8
|
+
|
9
|
+
paginate( paginate_params(@response) ) # where @response is an RSolr::Response
|
10
|
+
|
11
|
+
But there's a shortcut Blacklight helper method which compacts this, #paginate_rsolr_response:
|
12
|
+
|
13
|
+
paginate_rsolr_response @response, :theme => 'blacklight'
|
14
|
+
|
15
|
+
The `theme => 'blacklight'` part will be passed through kaminari, and tell kaminari to use the theme that the Blacklight plugin supplies at [app/views/kaminari/blacklight](https://github.com/projectblacklight/blacklight/tree/master/app/views/kaminari/blacklight)
|
16
|
+
|
17
|
+
Any other arguments of ordinary kaminari paginate can also be passed in there. If all client code uses #paginate_solr_response, it also provides a 'hook' for local apps to completely over-ride pagination rendering, perhaps not even using kaminari.
|
18
|
+
|
19
|
+
Additionally, we sometimes want to output a "Showing X through Y of N" message, which kaminari doesnt' have a way to do by default, so we just provide our own way in a Blacklight view helper method, which takes a RSolr::Response too:
|
20
|
+
|
21
|
+
render_pagination_info(@response)
|
22
|
+
|
23
|
+
## Changing the kaminari theme
|
24
|
+
|
25
|
+
If you want to change how pagination links are rendered, the easiest/cleanest thing to do is to over-ride the 'blacklight' theme that the Blacklight plugin defines. Copy the view templates in Blacklight source at app/views/kaminari/blacklight to your own local app/views/kaminari/blacklight. You actually only need to copy files you'll want to modify, templates not overridden with a local copy will still be found by kaminari from the Blacklight gem. You can use any techniques available for creating a kaminari theme when editing these files, including over-riding more kaminari view templates if available. See the kaminari documentation.
|
26
|
+
|
27
|
+
There are other ways you could change how Blacklight pagination renders, but by doing it this way, any code (in core Blacklight or additional plugins you install) that tries to render pagination using kaminari with 'blacklight' theme will get your locally defined theme.
|
28
|
+
|
29
|
+
The "pagination info" (showing X through Y of N) is not part of the kaminari theme, but just a blacklight view helper method, #render_pagination_info. To change this, just over-ride this method [[over-ride locally|CUSTOMIZING]] like any other Blacklight view helper method.
|
30
|
+
|
31
|
+
## Using kaminari theme for your own pagination
|
32
|
+
|
33
|
+
Your local app may show pagination of ActiveRecord objects, that you'd like to appear consistent with other Blacklight pagination. Just use kaminari to show the pagination HTML, with the theme :blacklight. This technique can be used for anything kaminari can paginate, such as Mongoid et al, in addition to ActiveRecord. Fetch the ActiveRecords using ordinary kaminari techniques (see kaminari docs) and then:
|
34
|
+
|
35
|
+
paginate @my_active_records, :theme => 'blacklight'
|
36
|
+
|
37
|
+
That's it. There's currently no great way to display the #render_pagination_info for anything but RSolr::Response.
|
38
|
+
|
39
|
+
## Changing the default kaminari pagination options
|
40
|
+
|
41
|
+
Sometimes you you just want to tweak a few things with pagination and it doesn't require crawling into the RSolr response or creating a kaminari theme. Here's how you do that.
|
42
|
+
|
43
|
+
First, generate the kaminari config initializer:
|
44
|
+
|
45
|
+
rails g kaminari:config
|
46
|
+
|
47
|
+
You will get a file in config/initializers/kaminari_config.rb that is mostly commented out. The config options are mostly self-explanatory, but let's say that you don't like that Blacklight gives you 4 pages of links on either side of the current page. Uncomment:
|
48
|
+
|
49
|
+
# config.window = 4
|
50
|
+
|
51
|
+
and change 4 to whatever number is preferable. More information on the kaminari general configuration options is available here: https://github.com/amatsuda/kaminari#general-configuration-options
|
@@ -0,0 +1,109 @@
|
|
1
|
+
> TODO: Validate this page for Blacklight 4.x!
|
2
|
+
|
3
|
+
# Customizing the User Interface
|
4
|
+
## Layouts
|
5
|
+
|
6
|
+
The built-in Blacklight controllers all by default use a Rails view layout called "blacklight", that lives in the Blacklight source. This ends up being a bit confusing, but is the best way we have at present to have out of the box default using a layout with full functionality, without stepping on a possibly existing local 'application' layout.
|
7
|
+
|
8
|
+
To change what layout the Blacklight controllers use, simply implement a method #layout_name in your local application_controller.rb that returns the name of the layout you'd like them to use.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
# [from app/controllers/application_controller.rb]
|
12
|
+
class ApplicationController < ActionController::Base
|
13
|
+
...
|
14
|
+
def layout_name
|
15
|
+
"application"
|
16
|
+
end
|
17
|
+
...
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
When implementing your own layout instead of using the stock one, you may want to look at the Blacklight app/views/layouts/blacklight.html.erb file to see what helper methods are called there, to maintain full Blacklight functionality you may want to call these same helper methods.
|
22
|
+
|
23
|
+
* `render_head_content` renders content within the
|
24
|
+
html `<head>` tag, which includes document-specific alternative
|
25
|
+
formats as well as tags generated by plugins, etc.
|
26
|
+
* `sidebar_items` renders features including sidebar content, e.g. facet
|
27
|
+
lists.
|
28
|
+
* flash messages
|
29
|
+
* user util links
|
30
|
+
|
31
|
+
## Overriding Views (templates and partials)
|
32
|
+
As a Rails Engine, you can easily override views in your app. You can see what views and partials are provided by looking in `[[./app/views|https://github.com/projectblacklight/blacklight/tree/master/app/views]]` inside the Blacklight source.
|
33
|
+
|
34
|
+
Once you find the view you'd like to change, you should create a file with the same name and relative path in your own application (e.g. if you wanted to override [[./app/views/catalog/_show_partials/_default.html.erb|https://github.com/projectblacklight/blacklight/blob/master/app/views/catalog/_show_partials/_default.html.erb]] you would create ./app/views/catalog/_show_partials/_default.html.erb in your local application. Frequently, you will start by copying the existing Blacklight view and modifying it from there.
|
35
|
+
|
36
|
+
It is generally recommended that you override as little as possible, in order to maximize your forward compatibility. Look to override either a small, focused partial template, or a helper method of partial template called from a larger template, so your application's version can call out to those same helpers or partial templates within blacklight core code.
|
37
|
+
|
38
|
+
## Overriding the CatalogController
|
39
|
+
Overriding the Blacklight `CatalogController` implementation is easy, and the skeleton of the `CatalogController` is generated into your application for you when you install Blacklight.
|
40
|
+
|
41
|
+
See the [[Extending or Modifying Blacklight Search Behavior]] for tips and approaches to customizing the catalog.
|
42
|
+
|
43
|
+
## Overriding Other Controllers
|
44
|
+
|
45
|
+
1. Find the controller you're interested in blacklight's app/controllers/ .
|
46
|
+
2. Create a file with the same name in your local app/controllers.
|
47
|
+
3. This file requires the original class, and then re-opens it to add more methods.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require "#{Blacklight.controllers_dir}/some_controller"
|
51
|
+
|
52
|
+
class SomeController < ApplicationController
|
53
|
+
# custom code goes here
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
In that "custom code goes here", you can redefine certain methods (action methods or otherwise) to do something different. You can also add new methods (again action methods or otherwise), etc.
|
58
|
+
|
59
|
+
It's kind of hard to call 'super' to call original functionality:
|
60
|
+
|
61
|
+
* the ruby language features here make 'super' unavailable, although you can work around that confusingly with the rails #alias_method_chain method.
|
62
|
+
* but more importantly, action methods in particular don't really suit themselves to being over-ridden and called by super, because the original implementation often does something you'd want to change but there's no easy way to 'undo' -- calling 'render', which can only be called once.
|
63
|
+
|
64
|
+
So basically, if you find yourself wanting to access some functionaltiy in the original implementation of a method that you also want to over-ride -- the best solution is probably to refactor Blacklight core code to put that functionality in a subsidiary method, so you can over-ride the action method entirely but call that logic from core. Action methods should be short and sweet anyway.
|
65
|
+
|
66
|
+
|
67
|
+
## Custom View Helpers
|
68
|
+
|
69
|
+
(This is accurate for Blacklight 3.1.1 and subsequent. Before that, things were messier).
|
70
|
+
|
71
|
+
One of the most common things you might need to do is create a view helper -- especially to override some Blacklight behavior implemented in it's own view helpers. The first step is looking at Blacklight source to determine what view helper method you want to override.
|
72
|
+
|
73
|
+
Blacklight comes packaged with several view helper modules. There is a BlacklightHelper in (blacklight source) app/helpers/blacklight_helper.rb , and several others that correspond to specific controller. (Note, depending on version of Rails and configuration, all helpers may get loaded for every request, even ones that are named to correspond only to a particular other controller).
|
74
|
+
|
75
|
+
If you simply created a local helper with the same name as a helper in Blacklight, that will end up preventing the Blacklight helper from being loaded at all though, which is not what you want to do to override.
|
76
|
+
|
77
|
+
We've structured each Blacklight view helper module into two parts to make it easy to selectively over-ride methods. For instance, here's Blacklight's app/helpers/blacklight_helper.rb:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
module BlacklightHelper
|
81
|
+
include Blacklight::BlacklightHelperBehavior
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
Now, the actual methods will be found in app/helpers/blacklight/blacklight_helper_behavior.rb instead.
|
86
|
+
|
87
|
+
If you want to over-ride a helper method, copy the wrapper blacklight_helper into your local app, with the 'include' line, and now you can individually over-ride methods from BlacklightHelperBehavior, and the other methods you don't over-ride will still have their default implementation.
|
88
|
+
|
89
|
+
YOUR `app/helpers/blacklight_helper.rb`
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
module BlacklightHelper
|
93
|
+
include Blacklight::BlacklightHelperBehavior
|
94
|
+
|
95
|
+
def application_name
|
96
|
+
"Bestest University Search"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
One helper you might want to over-ride for customization is #render_document_partial (currently defined in [[blacklight_helper|https://github.com/projectblacklight/blacklight/blob/master/app/helpers/blacklight_helper.rb]]), which you can over-ride to choose differnet local partial views to display a document on search results or detail page, possibly varying depending on type of document according to your own local logic.
|
102
|
+
|
103
|
+
## Adding in your own CSS or Javascript
|
104
|
+
|
105
|
+
Within your local application, you can use the [[Rails Asset Pipeline|http://guides.rubyonrails.org/asset_pipeline.html]] to manipulate javascript and css documents.
|
106
|
+
|
107
|
+
**todo??** better instructions for over-riding BL's built in CSS using SASS? (jrochkind thought jamesws wrote such already, but can't find them now)
|
108
|
+
|
109
|
+
The Blacklight generator added a file to your app at `./app/assets/stylesheets/blacklight_themes/standard.css.scss`, elements of the BL default theme can be customized or over-ridden there. If there's something you want to do but aren't sur e the best way, feel free to ask on the listserv.
|
data/doc/Quickstart.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
Blacklight is a Ruby on Rails Engine plugin, meaning it provides a small application that runs inside an existing Ruby on Rails project. For notes on upgrading Blacklight, check out our [[Release Notes And Upgrade Guides]] index.
|
2
|
+
|
3
|
+
This Quickstart will walk you through installing Blacklight and Solr, and indexing a sample set of records. If you want information about configuring Blacklight to use an existing Solr index with your data in it, see the [[Blacklight configuration]] document.
|
4
|
+
|
5
|
+
## Pre-requisites
|
6
|
+
* Ruby 1.9 or higher (consider using [[RVM|https://rvm.beginrescueend.com/rvm/install/]] or [[RBEnv|http://rbenv.org/]] to manage your Ruby version).
|
7
|
+
* Java 1.5 or higher (in order to run solr under a java servlet container)
|
8
|
+
* **For Windows users**: You may want to use [RailsInstaller](http://railsinstaller.org/) to get a Ruby on Rails environment.
|
9
|
+
|
10
|
+
> NOTE: We run our continuous integration tests against Ruby 1.9.3, Ruby 2.0 and JRuby (running in 1.9 mode) using the latest release of Rails on a Redhat Linux machine. While Blacklight may work with older versions of Ruby, we can't commit ourselves to supporting them.
|
11
|
+
|
12
|
+
In addition, you should have the Bundler and Rails ruby gems installed:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
$ gem install bundler
|
16
|
+
$ gem install rails
|
17
|
+
```
|
18
|
+
|
19
|
+
## Install and Use
|
20
|
+
|
21
|
+
1. Create a new rails 3 application
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ rails new my_app
|
25
|
+
# create
|
26
|
+
# create README
|
27
|
+
# create Rakefile
|
28
|
+
# create config.ru
|
29
|
+
# create .gitignore
|
30
|
+
# create Gemfile
|
31
|
+
# [...]
|
32
|
+
|
33
|
+
$ cd my_app
|
34
|
+
```
|
35
|
+
|
36
|
+
Rails automatically created an `public/index.html` file. However, Blacklight will provide a default `root` route for your application, so you probably want to remove it:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
$ rm public/index.html
|
40
|
+
```
|
41
|
+
|
42
|
+
2. Append this line to your application's `Gemfile`
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem 'blacklight'
|
46
|
+
```
|
47
|
+
|
48
|
+
Especially if you are running on Linux, you may have to add `gem 'therubyracer'` to your gemfile, to get a Javascript runtime needed by the asset pipeline.
|
49
|
+
|
50
|
+
then, update the bundle
|
51
|
+
|
52
|
+
```bash
|
53
|
+
$ bundle install
|
54
|
+
```
|
55
|
+
|
56
|
+
3. Install blacklight using Devise for user authentication:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
$ rails generate blacklight --devise
|
60
|
+
```
|
61
|
+
If you would prefer to integrate with an alternative user authentication provider, see the [[User Authentication]] documentation. You can also install with no support for logged in users simply by omitting the devise install, and generating blacklight with `rails generate blacklight` (no --devise argument).
|
62
|
+
|
63
|
+
4. Run your database migrations to create Blacklight's database tables:
|
64
|
+
|
65
|
+
```bash
|
66
|
+
$ rake db:migrate
|
67
|
+
```
|
68
|
+
|
69
|
+
5. You will need to install and configure Solr. You can install
|
70
|
+
Blacklight's example Solr configuration (using the jetty servlet container) that is configured to work with
|
71
|
+
the Blacklight defaults:
|
72
|
+
|
73
|
+
```bash
|
74
|
+
$ rails generate blacklight:jetty
|
75
|
+
```
|
76
|
+
|
77
|
+
**For Windows Users: ** This step will only work on *nix platforms. You can manually download and extract a tagged version of [blacklight-jetty](https://github.com/projectblacklight/blacklight-jetty/tags). After extracting the file, you need to update the `config/jetty.yml` file to add the `jetty_home` key to your test environment, e.g.:
|
78
|
+
|
79
|
+
```yaml
|
80
|
+
test:
|
81
|
+
jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
|
82
|
+
jetty_home: <%= ENV['TEST_JETTY_PATH'] || File.join(Rails.root, 'test_jetty') %>
|
83
|
+
startup_wait: 15
|
84
|
+
```
|
85
|
+
|
86
|
+
|
87
|
+
6. Make sure your Solr server is running. If you installed the Blacklight demo Solr/Jetty package, you can start the Jetty/Solr server using:
|
88
|
+
|
89
|
+
```bash
|
90
|
+
$ cd jetty; java -jar start.jar &
|
91
|
+
```
|
92
|
+
|
93
|
+
6. Index some data. You can index test MARC records provided Blacklight running:
|
94
|
+
|
95
|
+
```bash
|
96
|
+
$ rake solr:marc:index_test_data
|
97
|
+
```
|
98
|
+
|
99
|
+
7. Start up your application
|
100
|
+
|
101
|
+
```bash
|
102
|
+
$ rails server
|
103
|
+
```
|
104
|
+
|
105
|
+
Visit the catalog at [[http://localhost:3000/catalog]].
|
106
|
+
|
107
|
+
[[https://github.com/projectblacklight/projectblacklight.github.com/raw/master/images/home.png|frame|alt=Blacklight home page]]
|
108
|
+
|
109
|
+
You should see the Blacklight interface with 30 MARC records for testing. Additional MARC records are available from the [[blacklight-data|https://github.com/projectblacklight/blacklight-data]] repository. These can be ingested into Solr using SolrMarc,
|
110
|
+
|
111
|
+
```bash
|
112
|
+
$ rake solr:marc:index MARC_FILE=(path to file)
|
113
|
+
```
|
114
|
+
|
115
|
+
See [[Configuring and Customizing Blacklight]] for information about how to customize the Blacklight user interface, search experience, and more.
|
data/doc/README_SOLR.md
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
#Solr in Blacklight
|
2
|
+
|
3
|
+
##Setting up Solr
|
4
|
+
|
5
|
+
Blacklight uses Solr as its "search engine".
|
6
|
+
More information about Solr is available at the Solr web site ( http://lucene.apache.org/solr/)
|
7
|
+
|
8
|
+
There are three sections to this document:
|
9
|
+
* Getting Solr
|
10
|
+
* Configuring Solr
|
11
|
+
* schema.xml
|
12
|
+
* solrconfig.xml
|
13
|
+
* SolrMARC
|
14
|
+
|
15
|
+
### Getting Solr
|
16
|
+
Blacklight distributes a pre-configured version of Solr (with the Jetty
|
17
|
+
container) as [[blacklight-jetty|https://github.com/projectblacklight/blacklight-jetty/tags]].
|
18
|
+
|
19
|
+
You can also use an existing Solr index (with some minor modifications).
|
20
|
+
If you want to start from a new version of Solr, follow the directions from the [[Solr tutorial|http://lucene.apache.org/solr/tutorial.html]]
|
21
|
+
|
22
|
+
You should now have a usable copy of Solr.
|
23
|
+
|
24
|
+
### Configuring Solr
|
25
|
+
####Solr Schema.xml
|
26
|
+
|
27
|
+
Between the `schema.xml` and `solrconfig.xml` you can change and tune the search behavior following directions from the [[Solr wiki|http://wiki.apache.org/solr/]]. Solr comes with example schema and solrconfig files, which you can use as a starting point for configuring your local Solr application.
|
28
|
+
|
29
|
+
Blacklight expects a uniqueKey field within your Solr index,
|
30
|
+
traditionally called `id`. The name of the unique key field can be
|
31
|
+
configured in your application's `SolrDocument`.
|
32
|
+
|
33
|
+
##### Blacklight community "best practices"
|
34
|
+
|
35
|
+
Solr uses a schema.xml file to define document fields (among other things). These fields store data for searching and for result display. You can find the example/solr/conf/schema.xml file in the Solr distribution you just downloaded and uncompressed.
|
36
|
+
|
37
|
+
Documentation about the Solr schema.xml file is available at (http://wiki.apache.org/solr/SchemaXml).
|
38
|
+
|
39
|
+
The default schema.xml file comes with some preset fields made to work with
|
40
|
+
the example data. If you don't already have a schema.xml setup, we
|
41
|
+
recommend using a simplified "fields" section like this:
|
42
|
+
```xml
|
43
|
+
<fields>
|
44
|
+
<field name="id" type="string" indexed="true" stored="true" required="true" />
|
45
|
+
<field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
|
46
|
+
<field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>
|
47
|
+
<field name="spell" type="textSpell" indexed="true" stored="true" multiValued="true"/>
|
48
|
+
<dynamicField name="*_i" type="sint" indexed="true" stored="true"/>
|
49
|
+
<dynamicField name="*_s" type="string" indexed="true" stored="true" multiValued="true"/>
|
50
|
+
<dynamicField name="*_l" type="slong" indexed="true" stored="true"/>
|
51
|
+
<dynamicField name="*_t" type="text" indexed="true" stored="true" multiValued="true"/>
|
52
|
+
<dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>
|
53
|
+
<dynamicField name="*_f" type="sfloat" indexed="true" stored="true"/>
|
54
|
+
<dynamicField name="*_d" type="sdouble" indexed="true" stored="true"/>
|
55
|
+
<dynamicField name="*_dt" type="date" indexed="true" stored="true"/>
|
56
|
+
<dynamicField name="random*" type="random" />
|
57
|
+
<dynamicField name="*_facet" type="string" indexed="true" stored="true" multiValued="true" />
|
58
|
+
<dynamicField name="*_display" type="string" indexed="false" stored="true" />
|
59
|
+
</fields>
|
60
|
+
```
|
61
|
+
|
62
|
+
Additionally, replace all of the tags after the "fields" section, and before
|
63
|
+
the `</schema>` tag with this:
|
64
|
+
|
65
|
+
```xml
|
66
|
+
<uniqueKey>id</uniqueKey>
|
67
|
+
<defaultSearchField>text</defaultSearchField>
|
68
|
+
<solrQueryParser defaultOperator="OR"/>
|
69
|
+
<copyField source="*_facet" dest="text"/>
|
70
|
+
```
|
71
|
+
|
72
|
+
Now you have a basic schema.xml file ready. Other fields can be specified, including a primary document title (`title_display`) and format (`format`), but these are easily configured in your application's `CatalogController`.
|
73
|
+
|
74
|
+
Fields that are "indexed" are searchable.
|
75
|
+
|
76
|
+
Fields that are "stored" are can be viewed/displayed from the Solr search
|
77
|
+
results.
|
78
|
+
|
79
|
+
The fields with asterisks ('*') in their names are "dynamic" fields. These
|
80
|
+
allow you to create arbitrary tags at index time.
|
81
|
+
|
82
|
+
The *_facet field can be used for creating your facets. When you index,
|
83
|
+
simply define a field with _facet on the end:
|
84
|
+
category_facet
|
85
|
+
|
86
|
+
The *_display field can be used for storing text that doesn't need to be
|
87
|
+
indexed. An example would be the raw MARC for a record's detail view:
|
88
|
+
raw_marc_display
|
89
|
+
|
90
|
+
For text that will be queried (and possibly displayed), use the *_t type
|
91
|
+
field for tokenized text (text broken into pieces/words) or the *_s type
|
92
|
+
for queries that should exactly match the field contents:
|
93
|
+
description_t
|
94
|
+
url_s
|
95
|
+
|
96
|
+
The Blacklight application is generic enough to work with any Solr schema, but to
|
97
|
+
manipulate the search results and single record displays, you'll need to know the
|
98
|
+
stored fields in your indexed documents.
|
99
|
+
|
100
|
+
For more information, refer to the Solr documentation:
|
101
|
+
http://wiki.apache.org/solr/SchemaXml
|
102
|
+
|
103
|
+
|
104
|
+
#####solrconfig.xml
|
105
|
+
|
106
|
+
Solr uses the solrconfig.xml file to define searching configurations, set cache options, etc.
|
107
|
+
You can find the examples/solr/conf/solrconfig.xml in the distribution directory you just uncompressed.
|
108
|
+
|
109
|
+
Documentation about the solrconfig.xml file is available at (http://wiki.apache.org/solr/SolrConfigXml).
|
110
|
+
|
111
|
+
Blacklight expects two request handlers to be defined -- one to handle
|
112
|
+
general search requests and one to handle single-document lookup. The
|
113
|
+
names of these request handlers are configurable, but are called
|
114
|
+
"search" and "document" respectively, out of the box.
|
115
|
+
|
116
|
+
|
117
|
+
#####Solr Search Request Handlers
|
118
|
+
|
119
|
+
When Blacklight does a collection search, it sends a request to a Solr
|
120
|
+
request handler named "search". The most important settings in this handler
|
121
|
+
definition are the "fl" param (field list) and the facet params.
|
122
|
+
|
123
|
+
The "fl" param specifies which fields are returned in a Solr response.
|
124
|
+
The facet related params set up the faceting mechanism.
|
125
|
+
|
126
|
+
Find out more about the basic params:
|
127
|
+
http://wiki.apache.org/solr/DisMaxRequestHandler
|
128
|
+
|
129
|
+
Find out more about the faceting params:
|
130
|
+
http://wiki.apache.org/solr/SimpleFacetParameters
|
131
|
+
|
132
|
+
|
133
|
+
######How the "fl" param works in Blacklight's request handlers
|
134
|
+
|
135
|
+
Blacklight comes with a set of "default" views for rendering each document
|
136
|
+
in a search results page. This view simply loops through all of the fields
|
137
|
+
returned in each document in the Solr response. The "fl" (field list) param
|
138
|
+
tells Solr which fields to include in the documents in the response ...
|
139
|
+
and these are the fields rendered in the Blacklight default views.
|
140
|
+
Thus, the fields you want rendered must be specified in "fl". Note that
|
141
|
+
only "stored" fields will be available; if you want a field to be rendered
|
142
|
+
in the result, it must be "stored" per the field definition in schema.xml.
|
143
|
+
|
144
|
+
The "fl" parameter definition in the "search" handler looks like this:
|
145
|
+
```xml
|
146
|
+
<str name="fl">id,score,author_display,(....lots of other fields)</str>
|
147
|
+
```
|
148
|
+
You may also use an asterisk plus "score":
|
149
|
+
```xml
|
150
|
+
<str name="fl">*,score</str>
|
151
|
+
```
|
152
|
+
|
153
|
+
######How the facet params work in Blacklight's request handlers
|
154
|
+
|
155
|
+
In the search results view, Blacklight will look into the Solr response for
|
156
|
+
facets. If you specify any facet.field params in your "search" handler,
|
157
|
+
they will automatically get displayed in the facets list:
|
158
|
+
```xml
|
159
|
+
<str name="facet.field">format</str>
|
160
|
+
<str name="facet.field">language_facet</str>
|
161
|
+
```
|
162
|
+
|
163
|
+
|
164
|
+
#####Blacklight's "search" request handler: for search results
|
165
|
+
|
166
|
+
When Blacklight displays a list of search results, it uses a Solr request
|
167
|
+
handler named "search." Thus, the field list (fl param) for the "search"
|
168
|
+
request handler should be tailored to what will be displayed in a search
|
169
|
+
results page. Generally, this will not include fields containing a large
|
170
|
+
quantity of text. The facet param should contain the facets to be
|
171
|
+
displayed with the search results.
|
172
|
+
```xml
|
173
|
+
|
174
|
+
<requestHandler name="search" class="solr.SearchHandler" >
|
175
|
+
<lst name="defaults">
|
176
|
+
<str name="defType">dismax</str>
|
177
|
+
<str name="echoParams">explicit</str>
|
178
|
+
<!-- list fields to be returned in the "fl" param -->
|
179
|
+
<str name="fl">*,score</str>
|
180
|
+
|
181
|
+
<str name="facet">on</str>
|
182
|
+
<str name="facet.mincount">1</str>
|
183
|
+
<str name="facet.limit">10</str>
|
184
|
+
|
185
|
+
<!-- list fields to be displayed as facets here. -->
|
186
|
+
<str name="facet.field">format</str>
|
187
|
+
<str name="facet.field">language_facet</str>
|
188
|
+
|
189
|
+
<str name="q.alt">*:*</str>
|
190
|
+
</lst>
|
191
|
+
</requestHandler>
|
192
|
+
```
|
193
|
+
|
194
|
+
#####Blacklight's "document" request handler: for a single record
|
195
|
+
|
196
|
+
When Blacklight displays a single record it uses a Solr request handler
|
197
|
+
named "document". The "document" handler doesn't necessarily need to be
|
198
|
+
different than the "search" handler, but it can be used to control which
|
199
|
+
fields are available to display a single document. In the example below,
|
200
|
+
there is no faceting set (facets are not displayed with a single record)
|
201
|
+
and the "rows" param is set to 1 (since there will only be a single record).
|
202
|
+
Also, the field list ("fl" param) could include fields containing large
|
203
|
+
text values if they are desired for record display. Is is acceptable to
|
204
|
+
include large amounts of data, because this handler should only be used
|
205
|
+
to query for one document:
|
206
|
+
|
207
|
+
<requestHandler name="document" class="solr.SearchHandler">
|
208
|
+
<lst name="defaults">
|
209
|
+
<str name="echoParams">explicit</str>
|
210
|
+
<str name="fl">*</str>
|
211
|
+
<str name="rows">1</str>
|
212
|
+
<str name="q">{!raw f=id v=$id}</str>
|
213
|
+
<!-- use id=blah instead of q=id:blah -->
|
214
|
+
</lst>
|
215
|
+
</requestHandler>
|
216
|
+
|
217
|
+
A Solr query for a single record might look like this:
|
218
|
+
http://(yourSolrBaseUrl)/solr/select?id=my_doc_id&qt=document
|
219
|
+
|
220
|
+
|
221
|
+
####Blacklight Solr Schema and Solrconfig File Templates
|
222
|
+
|
223
|
+
Blacklight provides schema.xml and solrconfig.xml files as starting points:
|
224
|
+
|
225
|
+
https://github.com/projectblacklight/blacklight-jetty/blob/master/solr/blacklight-core/conf/schema.xml
|
226
|
+
|
227
|
+
https://github.com/projectblacklight/blacklight-jetty/blob/master/solr/blacklight-core/conf/solrconfig.xml
|
228
|
+
|
229
|
+
#SolrMARC: from Marc data to Solr documents
|
230
|
+
|
231
|
+
The SolrMARC project is designed to create a Solr index from raw MARC data.
|
232
|
+
It can be configured easily and used with the basic parsing and indexing
|
233
|
+
supplied. It is also readily customized for a site's unique requirements.
|
234
|
+
|
235
|
+
The project software and documentation is available at [[http://code.google.com/p/solrmarc]]
|
236
|
+
|
237
|
+
Blacklight comes with an embedded SolrMarc, with some default config that matches the default Blacklight setup, and provides some rake tasks to easily index docs with SolrMarc according to your app's environment. There is no need to manually install/configure SolrMarc yourself. From your application's home directory simply run:
|
238
|
+
```bash
|
239
|
+
rake solr:marc:index:info
|
240
|
+
```
|
241
|
+
to see options. Run `rake solr:marc:index` to actually do indexing. Like all rake tasks, by default this will use your 'development' environment; add "RAILS_ENV=production" to instead index to the solr you've labelled production in your config/solr.yml file.
|
242
|
+
|
243
|
+
The solrmarc config files are in your app's config/SolrMarc directory, you can edit them there for local config.
|
244
|
+
|
245
|
+
If you'd like to use a different or more recent version of SolrMarc.jar, you can put it in your app at ./solr_marc/SolrMarc.jar, and the built-in rake tasks will use your local SolrMarc.jar instead of the one bundled with Blacklight.
|