Try to conduct a search for a published Job posting content type. You’ll notice that it appears differently to other content types:
This is because the search index isn’t configured to display the right View mode for the Job posting content type and it shows the same content as the full-page view.
Let’s change that, by activating Search view mode in the Job Posting content type and then configuring the search to use it.
Go to Structure → Content types → Job Posting → Manage display.
Under the Custom display settings, enable the Search view mode. Save the changes.
Click the Search link at the top (in the secondary tabs) to navigate to the Search view mode.
Under the Select a layout field, select Search and save the changes. You’ll notice that the fields table below now shows multiple regions, such as:
Title
Info
Summary
Tags
Disabled
Rearrange fields (drag-and-drop) to match the screenshot. Move the remaining fields into the disabled region. Focus on making the Title field a link and trimming the Job description down to 300 characters. Remember to Save your changes.
Now, as we created and customised the Job posting view mode for Search, let’s make the search page to use it. Our search page is made as a View, although it’s set to use the Search API functionality. We’ll explore how to create a Search API view later.
Go to Structure → Views and edit the Search view.
Under Format → Show, click on the Settings link:
Locate the “View mode for datasource Content, bundle Job Posting” and change it to use the Search view mode created earlier
Apply your changes and Save the view.
Repeat search for a job posting and confirm if the display looks similar to other content types.
You may return to the Search view mode in the Job posting content type and change it further, to test how your changes affect the search results display widget.
Standard page search results
Not configured Job posting search result
Search result for Job posting
Search result for News page
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.
Since the release of Drupal 7, the Search API module has helped thousands of site builders to add an amazing search experience to their sites. Along with its numerous add-on modules it offers great flexibility and a large range of powerful features – faceting, entity relationships, relevancy configuration, spellchecking, etc. – and its Views integration ensures that all aspects of the site's search page(s) can be configured in detail through a well-known interface.
For the Government Jobs portal, a faceted search tool will help job seekers find related content faster.
GovCMS provides a default search functionality which is fairly basic. For this scenario, let’s assume your website needs a more sophisticated keyword search tool with search facets, allowing to filter Jobs by a state, terms of employment and an agency.
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 or any other similar fields. A typical use of a Facet is to allow filtering the search results by a price range on a shopping cart website, or filtering jobs based on location.
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.
Facets module is already enabled in your training environment.
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.
Click the Add facet button.
Select View Jobs Search, display Page as the Facet Source.
Select State (field_jobstate) 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.
Operator: OR.
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.
Place the State/Territory block (category Facets) into the Content above region.
Restrict the visibility of the block to the Jobs Search page (/jobs-search).
Save blocks 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.
First, let’s see how the default search works.
Your website should have a search block in the header or footer. If not you can add a Search block by going to Structure → Block Layout and clicking Place Block in the region you wish to add Search. Then search for 'Search'.
The screenshot below shows what a default search result may look like. By default, the search will only find full words (so a search for “class” won't find “classroom”).
You can control this in Structure → Content types → (choose a content type) → Manage display. In this screen you can configure the view mode and field display for Search results.
Note that in the given example for the Standard Page content type, we use view mode Search and Search layout, to stay consistent with other content types in GovCMS. The view mode used in the search could be any other one available, as long as it’s configured to display in the search results (we’ll explore this later).
Add a new News and Media with a word you haven’t used before, such as “basketball”.
Once you’ve published the content, do a search for the word. You won’t get any results because the search doesn’t update instantly. This is because the search uses a cached index of content to speed up the results and decrease the performance impact on your website. However, the search will be updated the next time the cron job is run.
Try the search in a few minutes. Note: The search is case-sensitive.
Cron is a method for scheduling specific tasks to run on your site. Cron is scheduled to run every three hours by default and clears the site cache when you run it. You can schedule tasks using cron as often as you’d like.
Read more http://drupal.org/cron
In GovCMS we can setup and configure multiple searches, this includes setting up multiple Search Indices and configuring them individually (if required).
To use the Search API and to create a new search page, first, we have to create a search index. This index will ensure communications between the content of your website and end user.
Go to Configuration → Search and metadata → Search API and click the Add Index button.
Index name: Job Posting
Data sources: Content
Which bundles should be indexed?: Only those selected
Bundles: Job Posting
Server: Lagoon Solr
Enabled: Yes
Accept the remaining default settings and click the Save button.