Creating a search view

Last updated on
24 March 2017

This documentation is based on D7 with Search API 7.x-1.1 and Views 3.

Getting started

First create a Search server and Search index as per the directions in the previous section. In the index make sure that you enable the status field in order to allow Views to filter on the Published status.

Enable the search_api_views submodule.
admin/modules

Set up a display mode (optional)

I'm going to use the 'Search results' display mode–this means that I won't be using Views to configure which fields are displayed. This is of course at your own personal preference. If you want to use views you probably know what you are doing and you'll have to amend the following steps somewhat.

Structure > Content types > [node type] > Manage display > Custom display settings
Enable “search results”
Configure display fields.

Create a new View

Admin > Structure > Views > Add new view
admin/structure/views/add

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

Continue & edit (the new View)

Format: Show: Rendered entity | Settings

  • View mode: Search results

Filter criteria

  • Fulltext search: Expose this filter, Required, Remember the last selection, Use as: search keys

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

Advanced

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

Exposed form

  • Exposed form in block: Yes (This option will only show up on Page displays.)
  • 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.