Creating a search view
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
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
- View name: Search
- Show: [the name of the Search index] (in the case of fuzzysearch the default is "Default fuzzysearch index")
- Create a page [tick]
- Page title: Search
- Path: search
- Display format: Unformatted list of Rendered entity
- 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.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion