The Search Views module is distributed with the Search API module. This module integrates the Search API module with the Views module and gives us the ability to use the power of Views for filtering, sorting and most importantly displaying search results.
In this video, I will show you how to install and enable the Views module and create a view that will display the search results. In the process we will add an exposed filter which will provide the search functionality.
Install Modules
Enable Modules
- Go to "Modules" (admin/modules) and enable:
- Chaos tools
- Search views
- Views
- Views UI
- (Save Configuration)
Now that we have installed and enabled Views and the other required modules, let's create our new view.
Create the search results view
- Go to "Structure => Views => Add new view" (admin/structure/views/add)
- View name: Search View
- Show: Node index (This is the name of the search index that we created in video 6.)
- [x] Create a page
- Page title: Search
- Display format: Unformatted list
- of: Rendered entity
- (Continue & edit)
Format
- Show
- Click "Settings"
- View mode: Search result
- (Apply(all displays))
Filter Criteria
- Click "Add"
- [x] Search: Fulltext search
- (Apply (all displays))
- [x] Expose this filter to visitors, to allow them to change it
- Label: Search
- Operator: [x] Contains any of these words
- (Apply (all displays))
Advance Settings
- No results Behavior
- Click "Add"
- [x] Global: Text area
- (Apply (all displays))
- Enter "No results matched your search." in the text area
- (Apply (all displays))
- Exposed form
- Exposed form in block
- Click "No"
- Exposed form in block: [x] Yes (This will allow the exposed filter to appear in a block instead of displaying the exposed filter in the content area of the view. Which means that we can place the search block in any region, on any page, instead of just on the search results page.)
- (Apply)
- Exposed form style
- Click "Settings"
- Submit button text: Search
- (Apply (all displays))
- Exposed form in block
- (Save) (Save view)
Let’s display the exposed filter block in the sidebar.
Expose the form in a block
- Go to "Structure => Blocks" (admin/structure/block)
- Scroll down to Disabled
- Block: Exposed form: search_view-page
- Region: Choose "Sidebar first"
- Scroll up to "Sidebar first"
- Rearrange blocks: drag the "Exposed form: search_view-page" to the top of the "Sidebar first" section.
- Remove "Search form" and "Search block: Search" by setting them to "- None -"
- (Save blocks)
Now, when we go home we'll see the search block, and we can try our new search view by entering an article title in the text box and clicking "Search".