Setup Site-wide Searching

Requires Tripal 2.1

This tutorial it is under development. The functionality it demonstrated is in the most recent development version of Tripal 2.x.

This section of the user guide will show you how to create a single search box with which users can search all node content (regardless of type). For example, a user could enter Fruitfly and the Drosophila melanogaster organism would be included in the results, as well as, all features (genes, mRNA, etc.) associated with that organism -Really all content that is associated with that organism whether it is a feature, stock, library, etc.

Installing Drupal Search API

  • Search API: This module provides an interface for much more powerful, efficient searching than the Drupal core search module. Specifically, it allows you to use more powerful engines such as Elastic Search and Apache Solr, as well as, advanced features such as facets (for narrowing down search results based on fields or entity type), fuzzy search, etc.
  • Search API Database Service: This module provides a Search Backend/Server defining how your search index should be stored. Specifically, it just stores the index in your current drupal database.

Simply install the above to modules as you would any other Drupal module. For instructions reference the Tutorial.

Screenshot Modules enable page with Database Search, Search API and Search views enabled.

Define your Search Backend/Server

First up we need to tell the Search API where we want our index stored. This tutorial covers using a basic Drupal Database storage backend for your search. For large sites, you will want to look into using Elastic Search or Apache Solr. To get to the configuration page for the Search API you can simply click on the Configure link shown in the above screenshot on the enable modules page or Navigate to Configuration > Search API through the administrative toolbar. You should see the following screen:

Click on "Add Server". Since we are configuring a basic drupal database seach server we don't actually have to install any third-part software or set-up an external server. Instead we just fill out the following configuration form to tell the Search API to use it's own database to store the index we will create in the next step. Simply give this server a name ("Drupal Database") and select "Database service" for the "Service Class". I also always, enable "Search on parts of a word" since I feel that if the search is slow due ot this feature, it's time to upgrade to a different service class (ie: Elastic Search or Apache Solr). Click "Create Server" to finish configuring the Search backend.

Add Server Config form

You should see the following screen assuming all went well. Click on "Search API" at the top of the screen (circled) to get back to the main configuration screen.

Define a Search Index

Now that we've told the Search API where we want to store our index, we have to define the index itself :-). This is usually done by clicking on "Add Index" but in this case the Search API & Tripal have already created it for you. Simply click on "Edit" beside "Default Node Index".

This index will index all content types. In addition to the drupal node content, Tripal has added the name fields and all foreign keys for each of the chado content types. By default the "Default Node index" is disabled because it requires you to choose the server. Select the "Drupal database" server you created earlier and click "Save Settings". Next we want to enable the default node index so we click "Edit" again and select the checkbox beside "Enabled" before clicking "Save Settings".


Index your Content

As soon as you enable the index your content will have been scheduled for indexing! Depending upon the amount of content you have, this could take awhile as it will only index 50 pieces of Tripal content per Drupal Cron run. If you click on the view tab at the top of the index config page you can see the progress on the indexing process. You can get back to this screen from the main search api configuration page by clicking on the name of the index. Once the progress bar is complete, you can continue on to the next step.


Creating a Search Interface for your users

At this point you should have an index of your Tripal Content. However, you still haven't created any functionality for end users—the data might be indexed, but they can't search it, yet. Tripal created a default search view for you when you enabled your index. To enable the view go to Structure > Views on the Administration menu and find the view named "Search Nodes". Click "Enable" for that view in the listing.

This will create a page at [your tripal site]/search/data that has a single textfield for keyword entry. , as well as, a menu link "Search Content" in your Navigation toolbar. When you go to this page you will see a single search box that the user can enter keywords into. Try a selection of keywords you know will be present in either the name, organism, type or accession of multiple data types. Keep in mind that the results are a listing of nodes matching your search keyword(s) with the "Teaser" view module being displayed. Thus to alter the listing you can either change the template for each chado content type to include the information you want known in the search results or alter the "Search Nodes" view that you enabled.

Additionally, you can add a search block to your site by going to Structure > Blocks in the administrative toolbar and moving the "Tripal Search Block" into the region in your theme you would like it to appear.

In the previous screenshot I have added the Tripal Search Block to my left sidebar. This allows users to quickly search from any page on your site. Furthermore, if you decide to use a different view or even a custom page to display your search results, simply configure the Tripal Search Block through the Blocks administration page and set the "Search Page URL" to match that of your custom search results page. Just make sure your results page accesses the search terms through the "keywords" page arguement.