arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

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.

hashtag
Add fields

From the Fields tab of the Job Posting search index, locate and add the following fields:

  1. Authored on (created)

  2. Agency (field_agencyref)

  3. Content type (type)

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.

hashtag
Index all content

Before we can use search, all Job Posting content on the site needs to be reindexed.

  1. Click the View tab at the top

  2. 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..

hashtag
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.

  1. Go to Structure → Views, click Add view button.

    • View name: Jobs Search

    • Description: Jobs search using Search API

hashtag
Configure Job Posting Search results to look like the General site search

  1. Clear site cache.

  2. Under Format - click Fields.

  3. Select Rendered entity.

hashtag
Test Job Posting Search

  1. Go to the frontend of the site and find the menu link Jobs Search.

  2. Review the Jobs search result. What’s missing?

hashtag
Add search field

  1. Return to the View edit interface.

  2. Under Filter Criteria, click Add.

  3. Search for “Fulltext search” from the Search category.

hashtag
Add relevance sorting

  1. Return to the View editing interface.

  2. Add Sort criteria → Relevance.

  3. Test it out.

State (field_state)
  • Job description (body)

  • Published (status)

  • Terms of employment (field_jobterms)

  • Title (title)

  • Rendered HTML output (rendered_item)

  • 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.

  • Apply the settings.

  • Select Search view mode,

  • Apply the settings.

  • Save the view.

  • 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.

  • Image of Add fields to Search index
    Image of Edit field Rendered HTML output
    Image of Edit field Rendered HTML output
    Image of contextual link
    Image of Index now
    Image of contextual link
    Image of contextual link