- 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
- https://github.com/skycatchfire/fire-modules/tree/master/fire_search
drush en fire_search
- Update
$valid_bundles
array on line 31 offire_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
- Add a Search Aggregate field (Text, (plain, long))
- Help Text: Automatically populated when saving a node. Used for search.
- 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.
- 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
Click Add Server button
-
- Save
Navigate to Search API page
/admin/config/search/search-api
Click Add Index button
-
-
-
- Choose which server the indexes should use
Navigate to Fields tab for datasource
- /admin/config/search/search-api/index/content/fields
-
- Click Add fields
- Add the fields that should be indexed
- Configure Type
-
- Click Save changes
Click Processors tab
- /admin/config/search/search-api/index/content/processors
- Enable HTML filter and Ignore case processors
Click View tab
- Click the Index now button
Create a view
- Name it Search
-
-
- Click Save and edit
Once on the Search View page, add fields to display and configure
-
Update Filter/Sort Criteria
Create templates, output selected fields, style 😃