The features described here refer to Rails Connector versions up to 6.9.1. If you wish to continue to use these features in a later version of the Rails Connector, you can find the corresponding source code in a Git repository.
The Rails Connector installs a search controller for sending search queries to the Search Server. By means of a view for this controller, the search results pages are formatted and the hits are linked. The supplied search page can be accessed using the /search
URL in your Rails application.
The Search Server (SES) can be used to search for CMS content. After having installed the Rails Connector into your Rails application, you should have a rails_connector.rb
file in your application's config/initializers
directory in which the search feature is turned on by default. To switch the search off, remove the :search
entry from the addons list in this file.
A SearchController, SearchHelper, and several views, including a search form and a results list, are provided by the addons gem and work out of the box.
You can choose to adjust the views according to your needs.
The Search Controller can be configured using the rails_connector.rb
config file. You can adjust the host and the port of the Search Server as well as the collection to be searched:
RailsConnector::Configuration.search_options = { :host => 'custom_host', :port => 3011, :collection => 'cm-contents-en' }
In order to further customize the search controller, you need to create your own search controller in your application:
class SearchController < RailsConnector::DefaultSearchController # Your custom code end
The search controller uses instances of the SearchRequest
class to form valid search queries from user input. Creating your own search controller lets you control all aspects of search processing, such as which documents are shown in search results, or how user input is sanitized:
class SearchRequest < RailsConnector::DefaultSearchRequest def self.sanitize(text) # Your implementation end def base_query # Define how `base_query_conditions` # are combined to form the VQL base query end def base_query_conditions super.merge( :custom_condition => 'VQL code' #, ... ) end end
Overwriting the search helpers works by a similar mechanism. To do so, create the app/helpers/search_helper.rb
file in your application and store the following in it:
module SearchHelper include RailsConnector::DefaultSearchHelper # Overwrite or define helpers end
For being able to perform searches, the Search Server as well as the indexes to be searched need to be made available to the rails application. For this, two approaches exist: