Custom Drupal Search Built with Search API + Database Search + Views

Updated: 14 March, 2016 seen 8,343

Default Drupal search function is pretty much OK, but if you are looking for ways to control and extend search behavior  - you are stuck with out of box search. 

I'll show you how you can boost your search functionality, by using just two (OK, three modules)

Download following modules:

Download and extract them into sites/all/modules folder

Enable Database search,  Search API and Search views

Now we must add a search server and search index.

Let's start with Search server.

  • Go to admin/config/search/search_api

  • Click on Add server link

  • Give it a name - I prefer to call it as DB Server, if you wish, you can enter Server description. Under dropdown from Service class chose Database service. Click Create Server.

Now go back to admin/config/search/search_api - you should see - your newly created server as enabled, and index as disabled.

  • Click on the Edit button for Default node index.

  • You must click check box next to Enabled button, and under Server, you must choose our newly created Server which we called DB Search (if you called it other way - you should see that name under drop down box). Click Save settings.

We are almost there - before indexing items, as it will appear in next window, after you will click Save settings, let's add some fields to index.

  • Go to admin/config/search/search_api/index/default_node_index/fields

If you have made some custom changes to your Drupal site, like added custom fields, taxonomies e.t.c. and you would like them to be indexed in your search server - this is the place were to add fields to search index. If you are OK with default (Title and body) leave settings intact.

Now let's index our nodes. You should configure cron, so items are indexed automatically, but if you want manually index your search server, go to admin/config/search/search_api/index/default_node_index

  • Click on Index now button to index 50 items, repeat it, so all your content is indexed, if you have too many nodes, use cron job.

Now we are ready to build our Search page.

Create a new View

Admin > Structure > Views > Add new view

  1. View name: Search
  2. Show: [the name of the Search index] (in the case of Default node index the default is "Default node index")
  3. Create a page [tick]
  4. Page title: Search
  5. Path: search
  6. Display format: Unformatted list of Fields
  7. Items to display: 10, use pager

Continue & edit (the new View)

Format: Show: Fields | Settings

Fields: Title, Body

Filter criteria

  • Fulltext search: Expose this filter, Required, Remember the last selection, Use as: search keys
  • Indexed Node: Status: Operator: Is one of, Value: Published

Sort criteria

  • Search: Relevance, descending (if you don’t have an order with fuzzysearch you will get a PDO exception)

Page settings

  • Access: Permission: view published content


  • No results behavior: Global: Text area “No results matched your search.”

Exposed form

  • Exposed form in block: Yes
  • Exposed form style settings: Submit button text: Search

Save the View. Add the exposed form block to a region.
Note that you will only receive results for partial matches that are longer than the minimum word length specified in the Index configuration.

It's up to you now, how are you gone to format display of your views page. As extra you could add Facets to be displayed on sidebar as well.

Here is the final search results page  I made for this site: