Using vanilla Drupal search is good. It searches full words and for the most part, it works pretty well, and is generally sufficient for most sites we build. But, as search becomes more important for our clients, with organizations placing greater emphasis on developing good content from a solid content strategy, we look for ways to improve the default Drupal search function.
Being able to search for partial words in search is one improvement our client’s wanted. Here is a little walkthrough on how to set up some quick improvements within Drupal7 search. For this, we used the following contributed Drupal modules: search API, Search API Database, and search API Pages.
First, we installed
search_api_page. These can all be download directly from drupal.org, or installed in your site at
sites/all/modules/contrib using drush. Using drush automatically installs the module in the proper folder. You can do this if you have already installed drush by typing in the terminal in the root of your site:
~ drush en –y search_api search_api_db search_api_page
Once installed, there’s just a few more steps.
1. Set up the search API module.
- Click “Add server” and give it a simple name like “search server”. Make sure it's enabled and then assign a service class.
- The search DB module provides a “Database Service” option, which is what you should select.
- For ‘More options’ set the minimum word search to 3 as this will set the minimum number of characters a word must consist of to be indexed.
- Check the box entitled “Search on parts of a word”, to find keywords within parts of a word as well (e.g., find results with "database" when searching for "base"). Caution: This can make searches much slower on large sites! Although, it would have to be pretty large to have a noticeable impact.
- Click on the “Add index” button and give it a simple name like “search index”.
- From the dropdown select the entities you want to search - like individual nodes or taxonomy terms.
- Select your server and the one you created earlier, “search server”, will be available. Note: there are a few more settings available, but usually don’t bother with them. Once you’ve created your index, you’ll be redirected to select fields to index. If the site is pretty simple you can just search the fields you want like, “Title” or “Body”, but you can also “ADD RELATED FIELDS”, which then provide “Node”. There are also more granular options available like, “Node » The main body text » Text”, which you will need to select in order to enable full text fields, which then can be indexed.
- Then add any full text fields you want to search that are either custom or, for example, “descriptions on taxonomy terms”. Once you save that you will be directed to set configuration on filters.
- At this point, keep it simple. Under data alterations only check “Bundle Filter” and leave that default. Then for processors, check “Highlighting” and also leave that default.
Now you have a “Server” and an “Index”. Be sure to index the content by clicking on the index name from the Search API overview page.
2. Next, set up the Search Page module.
- Click on the tab “Search pages” from the Search API overview page.
- Select the search index you want to use, which will most likely be the one you created in the steps above.
- Create the path like “search/index”. Select “Query Type” -> Multiple Items.
- Now you have a Search block in structure -> blocks. Use this block instead of the standard Drupal form. You can also go to the path you assigned to the search page to display the results. That page will have a search field that you can test and configure more to refine your search results.
That’s it. There’s lots of documentation on how to do this out there and it’s just a matter of setting up the config properly for your site, as well as some trial and error. This is for Drupal 7 but there’s a very similar setup for Drupal 8 as most of these modules have D8 releases.
It’s also worth mentioning that with the end of life for Google Search Appliance in April 2018, Solr is now becoming the Drupal preferred search interface. Solr is a best in class search platform that is already fully integrated into Drupal, only requiring configuration to enable it.
We’ve developed quite a bit of expertise in Solr search and are currently developing a commercial offering of Solr. We can configure and install Solr for almost any Drupal 7 or 8 website, and of course offer Canadian hosting of the searched indexes.
For more information on our Solr and Drupal integration you can contact us here.