Implementation of site-wide, keyword based Search using Search API

Modules:
Search API for Drupal 8

Functionality:
Based on the keyword entered in the search input box by the user, a site-wide full text search would be performed. The output of the search page would display, all the items matching the search keyword, with an excerpt from the article, highlighting the text matching the keyword.

Implementation:
Download and enable Search API(search_api) for drupal 8, enable Database search (search_api_db)

Adding Server:
Go to Admin->configuration->search and metadata->search API
Add server, use Database for Backend and check Enabled
Under Configure Database Backend, check Search on parts of a word and save

Adding Index:
Go to Admin->configuration->search and metadata->search API
Add an index
Under data sources, select ‘content’
Choose the server created above, under the servers section, check ‘enabled’
Under Index Options, choose ‘index items immediately’ and save

Configuring Index:
Under the fields tab, click on add fields
– select general and add Rendered HTML output
-select content, add Body and Title

Under the processors tab, check Content access, Highlight, HTML filter, Ignorecase, Node status, Transliteration. Ensure that the create excerpt option is checked, under the Highlight processor settings and save the index.

View to display search results:
Add a new view , select the index db created above under the show option in the view settings, check on create a page
Add the fields that are to be displayed in the search results, along with the excerpt field of the search API
Note: Since the excerpt field can sometimes return empty data, add the body field with a condition such that, body is displayed only when the excerpt field is null. This can be done using the rewrite results option on the body field settings.The code looks as below:
{% if search_api_excerpt %}
{% else %}
{{ body }}
{% endif %}
Use Fulltext Search for the filter criteria and Relevance under sort
Save the view

Once the data is indexed, the search results are displayed on the view page.

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/8/feed