Name: rails_solr_integration
Owner: NCSU Libraries
Description: A Rails design pattern for implementing Solr indexing and search
Created: 2017-06-26 14:36:45.0
Updated: 2017-06-28 18:53:02.0
Pushed: 2018-01-25 15:19:40.0
Homepage: null
Size: 14
Language: Ruby
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A Rails design pattern for implementing Solr indexing and search.
This project depends on the RSolr library. Include it in your Gemfile:
'rsolr'
You must have a running Solr instance that your Rails app can connect to. Generally, this will be a multi-core set up, with one core dedicated to your application.
To prepare to connect to your Solr core:
config/solr.yml
to your 'config' directory, and update with specific connection informationupdate YAML.load_file('config/solr.yml')[Rails.env] rescue {}
The rest of these instructions assume that you have a core and schema set up and that you know what fields are available in your schema.
This is an ActiveSupport::Concern that you will use to extend the models you need to index.
It provides some common class and instance methods that you can use on your models, the most important being solr_doc_data()
, which generates the record (a hash of field names/values) that is sent to Solr. It is important that the hash keys correspond to fields in your schema. Detailed instructions in code.
The Search model is used to execute queries against a Solr index. By default, searches will use the eDisMax query parser, which attempts to match the query term in one or more fields, giving different weight to matches in different fields according the parameters sent to Solr using the 'qf' (query fields) parameter. These values should be specified in this file (assigned to the @@query_fields
class variable). You can also specify default values for certain other query paramters here. Detailed instructions in code.
In each model you want to index and make searchable, add this at the top of the class definition:
ude SolrDoc
This will add the following instance methods to the model:
At a minimum, you will need a search controller with at least one action, and a route to enable that action to process HTTP requests.
This file provides a basic implementation of a search controller.
Include this line to provide a route to your Search controller:
'search(.:format)' => 'search#index', as: 'searches'
Provides a variety of helper methods for use in views.
Provides a very basic implementation of search form and results.
Add lib/tasks/search_index.rake
to your project to make these rake tasks available: