How do I search only a certain collection or a collection and all sub-collections?
- Drupal 8
- Islandora
- Islandora Defaults (for some expected settings)
This is a simple view following the member_of
relationship, though it could follow any parent child relationship.
To create the search fields go to Admin -> Configuration -> Search and Metadata -> Search API
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.
Click the reindexing link and travel to the following page.
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"]
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).
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
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.
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
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”)
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
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
This assumes you have done the above steps. It creates a new Solr field to index the member_of
hierarchy.
Go to Admin -> Configuration -> Search and Metadata -> Search API
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
You should now see this message.
Click the reindexing link and travel to the following page.
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.
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.
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.
Click Apply (this display)
Change the When the filter value is NOT available drop down to Content ID from URL
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
Go to Admin -> Structure -> Context
Find the Collection context and click the Edit button on its line.
Scroll to the Reactions section and you should see:
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.
Click Add Block
Scroll to the bottom of the page and click Save and continue.
View a collection and see the search block.
This recipe was researched, tested and written as part of IslandoraCon 2019's Use-a-thon.