Skip to content

Islandora advanced search

Introduction

Advanced Search adds additional functionality beyond the basic Solr search. It enables the use of Ajax with search blocks, facets, and search results.

animated gif demonstrating advanced search in action

Requirements

Use composer to download the required libraries and modules.

composer require drupal/facets "^1.3"
composer require drupal/search_api_solr "^4.1"
composer require drupal/search_api "^1.5"

However, for reference, islandora_advanced_search requires the following drupal modules:

Installation

To download/enable just this module, use the following from the command line:

composer require drupal/advanced_search
drush en advanced_search

Configuration

You can set the following configuration at Administration >> Configuration >> Advanced Search Settings (admin/config/search/advanced):

screenshot of the advanced search setting page

Configuring Solr

Please review Configure Search before continuing. The following assumes you already have a working Solr and the Drupal Search API setup.

To support collection based searches you need to index the field_member_of for every repository item as well define a new field that captures the full hierarchy of field_member_of for each repository item.

Add a new Content solr field field_descendant_of to the solr index at admin/config/search/search-api/index/default_solr_index/fields.

screenshot of field_decent_of

Then under admin/config/search/search-api/index/default_solr_index/processors enable Index hierarchy and set up the new field to index the hierarchy.

screenshot of checked checkbox

screenshot of processor setting options

The field can now be used limit a search to all the descendants of a given object.

Re-Indexing

You may have to re-index to make sure the field is populated.

Configure views

The configuration of views is outside the scope of this document, please read the Drupal Documentation, as well as the Search API Documentation.

It will be typical that you require the following Relationships and Contextual Filters when setting up a search view to enable Collection Search searches.

screenshot of contexts configuration

Here a relationship is set up with Member Of field and we have two contextual filters:

  1. field_member_of (Direct descendants of the Entity)
  2. field_descendant_of (All descendants of the Entity)

Both of these filters are configured the exact same way.

screenshot of configuration settings

These filters are toggled by the Advanced Search block to allow the search to include all descendants or just direct descendants (documented below).

Paging

The paging options specified here can have an effect on the pager block (documented below).

screenshot of paging configuration settings

Sorting

Additionally, the fields listed as Sort Criteria as Exposed will be made available in the pager block (documented below).

screenshot of sort criteria

Configure facets

The facets can be configured at admin/config/search/facets. Facets are linked to a Source which is a Search API View Display so it will be typically to have to duplicate your configuration for a given facet across each of the displays where you want it to show up.

Include / exclude facets

To be able to display exclude facet links as well as include links in the facets block we have to duplicate the configuration for the facet like so.

screenshot of facet configurations

Both the include / exclude facets must use the widget List of links that allow the user to include / exclude facets

screenshot of list of configuration options for facets

The excluded facet also needs the following settings to appear and function correctly.

The URL alias must match the same value as the included facet except it must be prefixed with ~ character that is what links to the two facets to each other.

screenshot of url alias setting

And it must also explicitly be set to exclude:

screenshot of exclude checkbox

You may also want to enable Hide active items and Hide non-narrowing results for a cleaner presentation of facets.

Configure blocks

For each block type:

  • Facet
  • Pager
  • Advanced Search

There will be one block per View Display. The block should be limited to only appear when the view it was derived from is also being displayed on the same page.

This requires configuring the visibility of the block as appropriate. For collection based searches be sure to limit the display of the Facets block to the models you want to display the search on, e.g:

screenshot of block configuration

Advanced search block

For any valid search field, you can drag / drop and reorder the fields to display in the advanced search form on. The configuration resides on the block so this can differ across views / displays if need be. Additionally, if the View the block was derived from has multiple contextual filters you can choose which one corresponds to direct children, this will enable the recursive search checkbox.

screenshot of advanced search block configuration


Last update: September 25, 2024