In order for Drupal to work with Apache Solr, we need to add the Search API module. This module provides a generic interface for search backends, including Solr. Furthermore, it adds several features to search without the need for custom code.
In this tutorial, we'll:
- Describe why Search API is necessary to use Solr with Drupal
- Identify a Search API server
By the end of this tutorial you should be able to install the Search API and Search API Solr modules, and create the Search API server configuration required to connect Drupal and Solr.
When developing a Drupal site, it is best practice to maintain multiple environments: A production environment for your live site, a stage environment for “next version” development, and your local environment for debugging and creating new features. Solr adds further complexity as we should have a separate Solr server for each.
In this tutorial, we'll:
- Describe why different Solr servers should be used for each environment
- Explain why Config Split is not a solution for multiple environments
- Describe how to use config overrides for each environment
By the end of this tutorial you should be able to override your Search API server configuration with environment-specific settings.
While Solr compartmentalizes settings into cores, Search API organizes things into indexes. Each Search API index can have a unique set of settings and crawl a specified list of content types. Search API indexes can be created in the Search API admin interface.
In this tutorial, we'll:
- Identify a Search API index
- Describe how an index is related to a Solr core
By the end of this tutorial you should be able to create a new Search API Index connected to a Solr backend.
Creating an index alone is not enough. To populate the index, we need to specify the fields necessary to populate the index. Selecting the fields is accomplished in the Search API admin UI.
In this tutorial, we'll:
- Explain how to select what populates a search index
- Describe a field boost, and how it is used to customize results
By the end of this tutorial you should be able to add fields to a Search API Index so their content is available for searching, and then instruct Search API to index the content of your site.
Reference field types, such as taxonomy term fields, paragraph fields, or plain entity reference fields, refer to a completely separate entity within the site. This makes search configuration complicated as the typical scope of a search crawl is on a per-node (really a per-entity) basis. Fortunately there are known strategies to index these fields with ease.
In this tutorial, we'll:
- Describe why reference types pose a particular challenge to indexing
- Discuss the importance of display modes in indexing
- Highlight how the Rendered HTML Output field can be used to index paragraphs
By the end of this tutorial you should be able to add reference fields to your Search API Index and allow users to search their contents in the correct context.
One of Search API’s key advantages is that custom search pages can be created using Views. This allows a high degree of customization, while relying on a familiar toolset.
In this tutorial, we'll:
- Describe how to use Views to create a search page
- Explain search page best practices, including requiring input and no-results text
By the end of this tutorial you should be able to create a page that users can use to search your site's content using the Solr search backend.
Drupal has the ability to support multiple Search API indexes within a single installation. While adding a new index is easy, we must understand the implications of creating and using multiple Search API indexes.
In this tutorial, we'll:
- Identify when to create multiple indexes in Search API
- Define virtual indexes, and their performance implications
Processors allow you to augment your search indexes by performing additional operations before or after the index operation. This can make your search more flexible.
In this tutorial, we'll:
- Identify what a processor is, and when it can be employed in the search pipeline.
- List useful processors provided by Search API.
- Describe how to apply a processor to an index, and why reindexing is necessary.
Excerpts are brief snippets of text displayed in search results. They give context to how the search terms relate to the result. Search API provides support for excerpts out of the box.
In this tutorial, we'll:
- Identify how to apply excerpts to a search index
- Describe how to add excerpt display to the search view
By the end of this tutorial you should be able to use the Highlight search processor to add excerpts to search results.
Autocomplete provides a brief and quick list of results to the user while typing. While this functionality isn’t available out of the box, it’s easy to add using an additional contributed module, Search API Autocomplete.
In this tutorial, we'll:
- Describe how to add autocomplete functionality to an existing index
By the end of this tutorial you should be able to add an autocomplete feature to the search query text field.
One of the key advantages of custom search is to do more than provide a single, global search box. Filtering allows you to divide results to a subset.
In this tutorial, we'll:
- Describe how to configure filtering through use of a taxonomy field
- Explain the disadvantages of this approach, including how it relies on Views to reduce results rather than Solr
Filtering results allows us to divide up the result set along one or more dimensions. It’s built in to Search API, but often we need a slightly different approach. Drill-down search or faceted searching allows us to constrain (rather than divide) our result set to one or more dimensions. The contributed Facets module provides this functionality.
In this tutorial, we'll:
- Describe how facets constrains results to preconfigured dimensions
- Demonstrate how use of a facet also constrains the possible selections for other facets
- List the steps for installing Facets module
- Describe the field types best used for creating facets
By the end of this tutorial you should be able to explain what facets are and how they work in the context of searching a Drupal site's content.
Creating a facet in Drupal is rather different from using Facets API in Drupal 7. In the new module, we first create a search view, and then configure facets against target fields in the index. Once created, we must configure the facet UI to appear on target pages using the Blocks UI.
In this tutorial, we'll:
- List the steps necessary to create a facet using a non-reference field (i.e. boolean, or text list)
- Explain why facets are displayed using blocks
- Describe the various facet display modes and uses for each
By the end of this tutorial you should be able to add a facet based on a text list field and allow users to filter search results using the values in the list field.
A powerful facet combination is to create a search Facet on a taxonomy field. This brings several advantages to how your search can be configured and displayed.
In this tutorial, we'll:
- Describe the additional complexities for using a reference field for a facet
- Show how to use taxonomy weights to control facet option order
By the end of this tutorial you should be able to add a facet that allows users to filter search result based on taxonomy terms.
When running tests with PHPUnit we need to specify a phpunit.xml file that contains the configuration that we want to use. Often times (and in much of the existing documentation) the recommendation is to copy the core/phpunit.xml.dist file to core/phpunit.xml and make your changes there. And this works fine, until something like a composer install
or composer update
ends up deleting your modified file. Instead, you should copy the file to a different location in your project and commit it to your version control repository.
In this tutorial we'll:
- Learn how to move, and modify, the phpunit.xml.dist file provided by Drupal core
- Understand the benefits of doing so
- Demonstrate how to run
phpunit
with an alternative configuration file
By the end of this tutorial you should be able to commit your phpunit.xml configuration file to your project's Git repository and ensure it doesn't get accidentally deleted.
Every theme can contain an optional THEMENAME.theme file. This file contains additional business logic written in PHP and is primarily used for manipulation of the variables available for a template file, and suggesting alternative candidate template file names. Themes can also use this file to implement some, but not all, of the hooks invoked by Drupal modules.
In this tutorial we'll learn:
- The use case for THEMENAME.theme files, and where to find them
- The different types of functions and hooks you can implement in a THEMENAME.theme file
By the end of this tutorial you should be able to know how to start adding PHP logic to your custom theme.
Themes and modules can alter the list of theme hook suggestions in order to add new ones, remove existing ones, or reorder the list. This powerful feature allows for the definition of custom logic in your application that can tell Drupal to use different templates based on your own unique needs. You might for example; use a different page template for authenticated users, or a custom block template for someone's birthday.
In this tutorial we'll cover:
- Adding new theme hook suggestions from a theme using
hook_theme_suggestions_HOOK_alter()
- Altering the list of theme hook suggestions
- Removing theme hook suggestions
- Reordering the list of theme hook suggestions
Underscore.js is a very small library which provides several utility functions and helpers to make working with JavaScript a little bit easier. In this tutorial we'll take a look at a part of the library, learn where the full library is documented, and see how we can make use of Underscore.js in a custom block on our Drupal site.
Make your theme a subtheme of a base theme, allowing it to inherit all the base theme's templates and other properties. When creating Drupal themes it is common to use the Classy theme provided with Drupal core as a base theme to jumpstart your development.
In this tutorial we'll learn how to:
- Use the
base theme
key in our theme's THEMENAME.info.yml file - Make our Ice Cream theme inherit from the Classy theme, or any other theme
By the end of this tutorial you should be able to tell Drupal that your theme is a child of another theme and should inherit all of the parent theme's features.
In Drupal, whenever we output markup it's best practice to use a Twig template or a theme function. But whenever you need to output DOM elements within JavaScript the best practice is to use the Drupal.theme
function. This function ensures that the output can be overridden just like the HTML output by Twig. This tutorial covers how to use the Drupal.theme
function in your JavaScript when inserting DOM elements, as well as how to replace the markup output by other JavaScript code that is using the Drupal.theme
function.