Exercise 9.4: Add fields to the index
Before we can begin using our index, we have to add fields from the Job Posting index. To create the search page, we need to be able to use some fields, such as Content Type, and node status (whether this is a published node). To enable Facets, we need to add State/Territory, Agency and Terms of employment.
In addition, we need to add a fully rendered entity, as it is seen by Anonymous users, so that our index can display search results ordered by relevance.
From the Fields tab of the Job Posting search index, locate and add the following fields:
When you select Rendered HTML output you will receive a prompt. Make sure the Default is selected as the View mode for Content » Job Posting field.
Click Done and then Save changes.
Index all content
Before we can use search, all Job Posting content on the site needs to be reindexed.
Click the View tab at the top
Click the Index now button and wait for the batch process to complete.
Note. You will see that the index will be created during cron runs - During cron runs, 50 items will be indexed per batch..
Create Search API View Job Posting Search
Let’s utilise the newly created Search Index and create a View that would use the index as the datasource. Unlike the previous experiences of filtering and ordering the results using Views, we’ll now be using Search API.
Go to Structure → Views, click Add view button.
Description: Jobs search using Search API
Configure Job Posting Search results to look like the General site search
Under Format - click Fields.
Test Job Posting Search
Go to the frontend of the site and find the menu link Jobs Search.
Review the Jobs search result. What’s missing?
Add search field
Return to the View edit interface.
Under Filter Criteria, click Add.
Search for “Fulltext search” from the Search category.
Add relevance sorting
Return to the View editing interface.
Add Sort criteria → Relevance.