Zac's Garden
Published on

Create a Search page using Search API in Drupal 8

Using Drupal 8's Search API, we'll quickly run through the steps for building a search page.

Grab and enable the Fire Search module

  1. https://github.com/skycatchfire/fire-modules/tree/master/fire_search
  2. drush en fire_search
  3. Update $valid_bundles array on line 31 of fire_search.module to the content types you want to add the Search aggregate field to

Create a Search Keywords taxonomy

Add new fields to content types you will be indexing

  1. Add a Search Aggregate field (Text, (plain, long))
  • Help Text: Automatically populated when saving a node. Used for search.
  1. Add a Search Keywords field (Entity reference) that pull from the Search Keywords taxonomy that you added to each content types that you
  • Should be autocomplete
  • Should allow multiple values
  • Reference Type: Search Keywords
  • Check Create referenced entities if they don't already exist
  • Help Text: A comma-separated list of keywords that will make this content appear in search form suggestions.
  1. Add a Search Description field (Text (formatted, long))
    • This will be displayed on the search page for each result
    • Help Text: Displayed on the search results page.

Enable Database Search and Search API modules

enable modules

Click Add Server button

add server
  1. fill in fields
  2. Save

/admin/config/search/search-api

Click Add Index button

  1. add index
  2. select datasources
  3. datasources
  4. Choose which server the indexes should use
server index
save
  1. /admin/config/search/search-api/index/content/fields
  2. navigate to fields tab
  3. Click Add fields
    1. Add the fields that should be indexed
    2. Configure Type
    3. configure boost
  4. Click Save changes

Click Processors tab

  1. /admin/config/search/search-api/index/content/processors
  2. Enable HTML filter and Ignore case processors
enable filters
filters
update processor settings for ignore case

Click View tab

  1. Click the Index now button
start indexing

Create a view

  1. Name it Search
  2. view settings
  3. create a page
  4. Click Save and edit

Once on the Search View page, add fields to display and configure

  1. view setup

    Update Filter/Sort Criteria

    setup filter and sort criteria

    Create templates, output selected fields, style 😃