-
Notifications
You must be signed in to change notification settings - Fork 2
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
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.
Easiest to look at the info file for an initial workup:
- https://github.com/thinkshout/wriflagship/blob/master/profile_work/wri_sites/modules/wri_search/wri_search.info.yml
- https://www.drupal.org/project/facets - creates the filters at the top and side of search results pages.
- https://www.drupal.org/project/facets_pretty_paths - lets you make faceted search results pretty, like https://www.wri.org/resources/topic/economics-10510/region/africa-8911/region/north-america-8940 instead of https://www.wri.org/resources?topic=10510®ions=%5B8911%2C8940%5D
- https://www.drupal.org/project/facets_summary Creates the listing of chosen facets, with an X to clear, for pages like https://www.wri.org/resources/topic/10510
- https://www.drupal.org/project/search_api_autocomplete -- lets you use autocomplete in the search filters. I don’t believe we actually used this.
- https://www.drupal.org/project/search_api_exclude_entity -- Tell Search API not to index certain nodes.
- https://www.drupal.org/project/search_api_solr - Adds solr search compatibility
- https://www.drupal.org/project/search_api_pantheon -- required to use Solr on Pantheon.
There is also custom code within The WRI search module that accomplishes the following things.
- LimitToParentProcessor processor. This custom solr processor says that if you have a parent/child relationship between two facets, don't show results in the child that aren't children of the parent. For example: Searching for the Region Africa https://www.wri.org/resources/region/africa-8911 should only show Countries that are children of Africa. By default it shows all Countries on the search results, which might include countries from many regions.
- WriIsChildSelf "Is Child" calculated field. Returns the term if it's a child of another term. This is used to limit Countries to a given Region, and Resource Subtypes to a given parent Resource Type. See examples: https://www.wri.org/resources/type/news-30005/region/africa-8911
- WriTermParentOrSelf "Parent or self" calculated field. If the term has no value in its parent, show the term itself. This is used for the top-level facets, like All topics, Regions, and Resource Types.
- 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]®ion=[block_content:field_filter_by_region:entity:root:tid]&country=[block_content:field_filter_by_region:entity:non_orphan]
which would translate into something likeinternal:/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 propertynon_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.