Skip to content

Latest commit

 

History

History
279 lines (144 loc) · 8.92 KB

collection_search.md

File metadata and controls

279 lines (144 loc) · 8.92 KB

Collection Search

How do I search only a certain collection or a collection and all sub-collections?

Ingredients

  • Drupal 8
  • Islandora
  • Islandora Defaults (for some expected settings)

Instructions

Creating shallow search

This is a simple view following the member_of relationship, though it could follow any parent child relationship.

Creating required search fields

To create the search fields go to Admin -> Configuration -> Search and Metadata -> Search API

Search API screenshot

Then choose Edit operation on the Index (Default Solr content index) line.

Then choose the Fields tab.

Click the Add Fields button.

In the overlay that appears, in the General section choose to Add an Aggregated field.

On the next screen, under Aggregation type select Concatenation.

Under Contained Fields select all the fields you would like to search at once.

If you do not see a field displayed you might need to add it as a Solr field first (TODO: describe the steps)

Choose Save

You are returned to the Add fields screen, click Done.

You should see a You have unsaved changes. message.

At the top in the General section you should now see a field with name Aggregated Field.

Change the type of this field to Fulltext.

Scroll to the bottom and click the Save changes button.

You should now see this message.

Need to reindex screenshot

Click the reindexing link and travel to the following page.

Index status screenshot

Click the Index now button to re-index your data.

If you create or have a Repository item you should see an aggregated field in your Solr record.

This will get you the first 20 records from Solr.

http://localhost:8983/solr/ISLANDORA/select?q=*:*

The id field contains a hash and then the path and language.

i.e. 44w7xh-default_solr_index-entity:node/4:en == node/4 == http://localhost:8000/node/4

The tm_aggregated_field will contain the concatenation of the fields you selected.

i.e. ["1933-05-13\n\nWinnipeg Tribune - May 13, 1933 - Page 3\n\n1"]


Create the Shallow Search View Block

Now go to Admin -> Structure -> Views

Click the Add View button.

Give your view a name, ie. “Collection Search”

Under View Settings, change the Show dropdown to Index Default Solr content index.

Check the Create a block checkbox.

Your page should look something like this (assuming you used the same view names).

Views settings screenshot

Scroll to the bottom and click the Save and edit button.

Now you are editing the view.

Under Fields you will see Index Default Solr content index: Aggregated field (indexed field), click that link

Aggregated field remove

Click the Remove link at the bottom.

Now click the Add button to the right of Fields.

In the popup window, type Title in the Search field and check the Title field. This is the field that will be displayed as the search result.

Click Add and configure fields.

On the next screen, under Render settings check Link to the Content.

Render settings screenshot

Finally click Apply

Now click the Add button to the right of Filters.

Search for Publish and check Publishing status.

DO NOT CLICK Add and configure fields yet!!!

Search for your aggregated field name and select it. If you did not change the field name from the default, then search for Agg and check Aggregated field.

Now click Add and configure fields

First we configure the publishing status filter, select True and click Apply and continue

Publishing status screenshot

Next we are editing the aggregated field filter.

Check Expose this filter to visitors,....

Change the label from Aggregated Field (or whatever) to what you want to appear beside this field. (ie. “Search”)

Aggregated Field settings

Click Apply.

Back in the View display, on the right hand side expand the Advanced section.

Click Add to the right of Contextual Filters

Search for Member and check the Member of field

Click Add and configure contextual filters

Change the When the filter value is NOT available drop down to Content ID from URL

Contextual Filter screenshot

Click Apply

Still in the Advanced section change the Use AJAX setting to Yes. To do this click the little No link, check the Use AJAX checkbox and click Apply.

Lastly under Block settings, change the Block name to something recognizable. This will be what you look for when we place the block.

Now back at the View display, click Save

You can now place this block


Creating a Deep Search Block

This assumes you have done the above steps. It creates a new Solr field to index the member_of hierarchy.

Creating required search fields

Go to Admin -> Configuration -> Search and Metadata -> Search API

Search API screenshot

Then choose Edit operation on the Index (Default Solr content index) line.

Then choose the Fields tab.

Click the Add Fields button.

Under Content find the Member of field and Add it.

Click Done

Under Content you will have two Member of fields. Look for the one with the Machine name field_member_of_1.

Change the Label of this field to Ancestors and change the Machine name to field_ancestors.

Scroll to the bottom and click Save changes

Click the Processors tab at the top.

In the Enabled area ensure that Index hierarchy is checked.

Scroll down to Processor settings, select Index hierarchy.

Select the Ancestors field.

Click Save

Index hierarchy settings screenshot

You should now see this message.

Need to reindex screenshot

Click the reindexing link and travel to the following page.

Index status screenshot

Click the Index now button to re-index your data.

If you check your solr records should now contain an mt_ancestors_ field which will contain the parent chain following the Member Of relationship.


Create the Deep Search block

Go to Admin -> Structure -> Views and find the view you made previously and Edit it.

This view should contain just the one block so on the right hand side select the Duplicate Block button.

Duplicate block button screenshot

This will duplicate all the settings to a new Block.

On the right in the Advanced section.

Add a new Contextual Filter

Change For from All Displays to This block (override)

Search for Ancestors and check it.

Add ancestors screenshot

Click Apply (this display)

Change the When the filter value is NOT available drop down to Content ID from URL

Ancestors Contextual Filter settings

Click Apply (this display)

Next in the Advanced -> Contextual Filter section, click on Content datasource: Member of

Ensure the For at the top is set to This block (override)

Then click the Remove link at the bottom.

Under Block settings, change the Block name to something different that indicates it is a deep search.

Click Save


Adding a search block to your collection (if you are using Islandora Defaults)

Go to Admin -> Structure -> Context

Context screenshot

Find the Collection context and click the Edit button on its line.

Scroll to the Reactions section and you should see:

Collection context reaction

Click the Place Block button.

Locate your block name (it should have a Type of "List (Views)"), click its Place block button.

Change the Region to what you like, we are using Sidebar second.

Place block settings

Click Add Block

Scroll to the bottom of the page and click Save and continue.

View a collection and see the search block.

Notes

This recipe was researched, tested and written as part of IslandoraCon 2019's Use-a-thon.