Custom Facet Examples
The custom facet is a powerful aid to customizing your site’s search experience. When the out-of-the-box facets don’t meet your requirements, the custom facet fills the gap. Here are examples for each aggregation type supported by the custom facet:
If desired, you can create the sample content to follow the examples, or you can use them as a reference as you configure your own site.
Using the Date Range Aggregation with Objects Fields
-
Using the Search Options widget, enable empty search on the search page.
-
Configure the Search Results widget to show results in document form.
-
Reload the search page and confirm that your events are in the list of search results.
-
Inspect one of the events in document view to see how the integer Event Date field was indexed. Find the field’s indexed value in the
nestedFieldArray
parent field:{ "fieldName": "eventDate", "value_date": 20221230000000, "valueFieldName": "value_date" }
See Exploring Indexed Fields for more information.
-
Add the custom facet to the page and open its configuration form.
-
Use these values:
-
Aggregation Type: Date Range
-
Aggregation Field:
nestedFieldArray.eventDate.value_date
-
Display Template: Compact Layout (Multiselect)
-
Custom Heading: Event Date
-
Custom Parameter Name:
event_date
-
Order By: Ranges Configuration
-
Ranges Configuration: Delete all the existing ranges. Since your field’s dates are all more than 1 year old, they are not captured by the default ranges.
- Label: 2024
- Range:
[20240101000000 TO *]
- Label: 2023
- Range:
[20230101000000 TO 20240101000000]
- Label: 2022
- Range:
[20220101000000 TO 20230101000000]
- Label: 2021
- Range:
[20210101000000 TO 20220101000000]
- Show Input Range: Enabled
-
-
Save the configuration and reload the page.
The 2024 date range doesn’t appear because there were no events in 2024.
Using the Range Aggregation with Objects Fields
-
Using the Search Options widget, enable empty search on the search page.
-
Configure the Search Results widget to show results in document form.
-
Reload the search page and confirm that your events are in the list of search results.
-
Inspect one of the objects events in document view to see how the integer Number of Invitees field was indexed. Find the field’s indexed value in the
nestedFieldArray
parent field:{ "fieldName": "numberOfInvitees", "value_integer": 102, "valueFieldName": "value_integer" }
See Exploring Indexed Fields for more information.
-
Add the custom facet to the page and open its configuration form.
-
Use these values:
-
Aggregation Type: Range
-
Aggregation Field:
nestedFieldArray.numberOfInvitees.value_integer
-
Display Template: Checkbox Layout (Multiselect)
-
Custom Heading: Number of Invitees
-
Custom Parameter Name: invitees
-
Order By: Ranges Configuration
-
Ranges Configuration:
- Label: 0-50
- Range:
[0 TO 50]
- Label: 50-100
- Range:
[50 TO 100]
- Label: 100+
- Range:
[100 TO 10000]
- Show Input Range: Enabled
-
-
Save the configuration and reload the page.
The 0-50 range doesn’t appear because the event with 50 attendees is included in the 50-100 facet aggregation. The from value is included, but results matching the to value of the range are excluded.
-
Click Custom Range, set from: 60 and to: 105, and click Search. The event with 102 invitees is returned in the facet:
Using the Terms Aggregation with Web Content Structure Fields
-
Create a new web content structure called News Article. Give it these fields:
- A Text field called
Title
- A Rich Text field called
Content
- A Select from List field called
News Type
with these options:- Current Events
- Sports
- Weather
- A Text field called
-
Add at least one News Article for each News Type option.
-
On the search page, enable empty search in the Search Options widget.
-
Configure the Search Results widget to show results in document form.
-
Reload the search page and confirm that your News Articles appear in the list of search results.
-
Inspect one of the web contents in document view to see how the integer Number of Invitees field was indexed. Find the field’s indexed value in the
ddmFieldArray
parent field:{ "ddmFieldName": "ddm__keyword__36850__Select23449267_en_US", "ddmFieldValueKeyword_en_US": "Option71779647", "ddmFieldValueKeyword_en_US_String_sortable": "current events", "ddmValueFieldName": "ddmFieldValueKeyword_en_US", "ddmFieldValueKeyword_en_US_String": "Current Events" }
See Exploring Indexed Fields for more information. Note that your indexed values are likely to differ slightly from those used in this example.
-
Add the custom facet to the page and open its configuration form.
-
Use these values:
- Aggregation Type: Terms
- Aggregation Field:
ddmFieldArray.ddm__keyword__36850__Select23449267_en_US.ddmFieldValueKeyword_en_US_String
- Display Template: Default
- Custom Heading: News Type
- Custom Parameter Name:
news_type
- Order By: Frequency Descending
-
Save the configuration and reload the page.
Creating an Example Object
-
Create a new site-scoped object called
Event
that’s accessible in the Content and Date menu. If needed see Creating and Managing Objects. -
Give the object these fields:
- A Text field called
Event Name
- An Integer field called
Number of Invitees
- A Date field called
Event Date
- A Text field called
-
Publish the object and go to the Events application in the site’s Content and Data menu.
-
Add several events. Make sure that you have at least these three entries:
Event 1, End-of-year company shindig:
- Event Name: End-of-year shindig, 2022
- Number of Invitees: 50
- Event Date: December 30, 2022
Event 2, Sales kick-off webinar:
- Event Name: SKO Webinar, 2023
- Number of Invitees: 102
- Event Date: January 15, 2023
Event 3, Spring company picnic:
- Event Name: Spring picnic, 2021
- Number of Invitees: 236
- Event Date: April 19, 2021