Enabling Searches Using the Search Server

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.

Customization

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

Making the Search Server and the indexes available

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:

  • The Search Server running on the editorial system is also used for searches on the live side. This solution is only recommended if the availability of the editorial system is not impaired by the additional load caused by searches on the live system. Even if the content database on the live system is kept up to date (for example by short replication cycles), discrepancies may arise between the indexes on the editorial system and the actual content on the live system (changed content might have been indexed before it shows up in the live database). If absolute synchronicity is required, this solution cannot be used.
  • The live side is provided with a dedicated Search Server, possibly on a dedicated machine if high load is an issue. This solution requires that the search indexes are replicated to the live server in the same intervals as the content database. This solution is recommended if the hardware used is sufficiently powerful.