Exercise 9.4: Add fields to the index
Last updated
Last updated
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:
Authored on (created)
Agency (field_agencyref)
Content type (type)
State (field_state)
Job description (body)
Published (status)
Terms of employment (field_jobterms)
Title (title)
Rendered HTML output (rendered_item)
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.
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..
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.
View name: Jobs Search
Description: Jobs search using Search API
Show: Index Job Posting
Create a page.
Page Title: Jobs Search
Page display settings: Display format: Unformatted list of: Fields.
Create a menu link in the Main navigation menu.
Save and edit.
Clear site cache.
Under Format - click Fields.
Select Rendered entity.
Apply the settings.
Select Search view mode,
Apply the settings.
Save the view.
Go to the frontend of the site and find the menu link Jobs Search.
Review the Jobs search result. What’s missing?
Return to the View edit interface.
Under Filter Criteria, click Add.
Search for “Fulltext search” from the Search category.
Click Add and configure the filter.
Toggle on - Expose this filter to visitors, to allow them to change it.
Label: empty
Apply the changes and Save the view.
Test it out.
Return to the View editing interface.
Add Sort criteria → Relevance.
Test it out.