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 search index, locate and add the following fields to the Search Index:
Authored on (created)
Content type (type)
Job description (body)
Terms of employment (field_jobterms)
Rendered HTML output (rendered_item)
Click Done and then Save changes
Edit the Rendered HTML output (rendered_item). Make sure the Default is selected as the View mode for Content » Job Posting field.
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
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
View name: Jobs Search
Description: Jobs search using Search API
Show: Index Job Posting
Create a page
Create a menu link in the Main navigation menu
Save and edit
Configure Job Posting Search results to look like the General site search
Clear site cache
Under Format - click Fields and select Rendered entity, Apply the settings
Select Search view mode, Apply the settings
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 it and configure the filter
Expose this filter to visitors, to allow them to change it
Save the changes and save the view.
Test it out.
Add relevance sorting
Return to the View editing interface
Add Sort criteria, Relevance.
Test it out.
Facets is a great tool to improve search UI by adding filtering options that the end user can use to filter the search results by category, price, location and any other field. A typical use of a Facet is to allow filtering the search results by a price range on a shopping cart website.
Our Job posting content type provides fields such as Terms of employment, State/Territory and Agency. Let’s add them as facets and see if that improves our search.
Ensure the Facets module is enabled
Navigate to the Extend page
Filter modules by keyword facets
Make sure the Facets module is enabled. If it isn’t already enabled, enable it and save the page.
Check permissions. Click the Facets module description to expand it and open Permissions in a new tab/window.
Ensure the “Administer Facets” permission is given to the right user roles.
Go to Administration → Configuration → Search and metadata → Facets. This page has a few facet sources available. These facets were created for you by the Facets module from each of the Views in your site. As you may expand your site with more Views that use a Search API index, they all become available here.
Locate our Job search in the Facet source, and click configure:
Enter a unique filter key. This key will be used in the query string to identify the facet source, which avoids errors when using multiple facets. We could leave this configuration empty; in which case the Facets will use an internally generated string.
Add State/Territory facet
Click the Add facet button.
Select View Jobs Search, display Page as the Facet Source.
Select State/Territory as the Field.
Enter State/Territory in the Name field. This will be used as the facet header.
Save the configuration and configure the facet.
Widget: List of checkboxes
Show the amount of results: selected
List item label: selected
Transform entity ID to label: selected
URL alias: state
Empty facet behaviour: Do not display facet
Sort by active state: not selected
Sort by count: not selected
Sort by display value: selected
Sort order: Ascending
The “Sort by display value: Ascending” will ensure the taxonomy terms for the State/Territory will be listed alphabetically.
Alternatively, we may enable the weight-based ordering of the facet filters to replicate the term sorting in the taxonomy vocabulary.
For this to work, you unselect the “Sort by display value” above and select the “Sort by taxonomy term weight” checkbox.
For now, leave the “Sort by display value” selected.
Save the configuration. This will create a block, which we have to place into the Content top region, so it appears to the end user.
Navigate to the Structure → Block Layout page.
Place the State/Territory block (category Facets) into the Content top region.
Save the block layout page.
Test your facet by navigating to the Jobs Search page.
Use your experience from the previous step and create a facet for the Agency field. Place it as a block in the Content Top region.