Skip to content

Search customizations

Maria Fisher edited this page May 11, 2021 · 6 revisions

Details the customizations done to search results found at /resources, /events, /search, and /experts.

This work is primarily done in The WRI search module

The basics

These views are Page displays of Solr-generated listings, filterable by facets and exposed filters. Generally they work with the configuration you get out of the box from contrib modules, but we did customize some plugins and add some patches to get things working the way they do. Those are noted below.

What modules support this?

Easiest to look at the info file for an initial workup:

Customizations - Search

There is also custom code within The WRI search module that accomplishes the following things.

Customizations related to Search

  • The WRI taxonomy module contains code to alter the canonical url for a Taxonomy term and redirect some terms to the /resources page. This is also described in the Content Editor's Guide
  • Several blocks have links to the Resources page based on the fields used to filter the results of the blocks. These values are passed as tokens to the block, then translated into the pretty-path solr value for the same filters. Code for that is found in the WRI Resource link field formatter. For example, if you create a listing block as detailed in the content editor's guide the default value of the More Link field is internal:/resources?all_topics=[block_content:field_tag:entity:root:tid]&within_this_topic=[block_content:field_tag:entity:non_orphan]&type_of_resource=[block_content:field_filter_by_resource_type:entity:root:tid]&subtype=[block_content:field_filter_by_resource_type:entity:non_orphan]&tags=[block_content:field_filter_by_tag:target_id]&region=[block_content:field_filter_by_region:entity:root:tid]&country=[block_content:field_filter_by_region:entity:non_orphan] which would translate into something like internal:/resources?all_topics=123&within_this_topic=456&type_of_resource=789 etc. The code in the "WRI Resource link field formatter" uses the Pretty Path Helper service to turn connect the facet name "all_topics" to the pretty path you'd get if you selected that value for "all_topics".
  • The advanced token format seen above, for things like block_content:field_tag:entity:non_orphan is made possible by the patch at https://www.drupal.org/project/token/issues/3115486 AND by the custom token property non_orphan in the Search module.
  • We needed to add some custom alter hooks to get the Pretty Facets module to work with exposed filters due to this issue: https://www.drupal.org/project/facets_pretty_paths/issues/3041314.
  • The facets for these pages were generally added through the twig templates instead of using the block system. See the Resources example.