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

  1. Add an object and some entries.

  2. Using the Search Options widget, enable empty search on the search page.

  3. Configure the Search Results widget to show results in document form.

  4. Reload the search page and confirm that your events are in the list of search results.

  5. 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.

  6. Add the custom facet to the page and open its configuration form.

  7. 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
  8. Save the configuration and reload the page.

    The 2024 date range doesn’t appear because there were no events in 2024.

    You can use date ranges in the custom facet.

Using the Range Aggregation with Objects Fields

  1. Add an object and some entries.

  2. Using the Search Options widget, enable empty search on the search page.

  3. Configure the Search Results widget to show results in document form.

  4. Reload the search page and confirm that your events are in the list of search results.

  5. 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.

  6. Add the custom facet to the page and open its configuration form.

  7. 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
  8. 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.

  9. Click Custom Range, set from: 60 and to: 105, and click Search. The event with 102 invitees is returned in the facet:

    You can use custom facets with objects integer field value ranges.

Using the Terms Aggregation with Web Content Structure Fields

  1. 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
  2. Add at least one News Article for each News Type option.

    Add a news article for each news type: weather, sports, and current events.

  3. On the search page, enable empty search in the Search Options widget.

  4. Configure the Search Results widget to show results in document form.

  5. Reload the search page and confirm that your News Articles appear in the list of search results.

  6. 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.

  7. Add the custom facet to the page and open its configuration form.

  8. 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
  9. Save the configuration and reload the page.

    You can create facets by web content structure fields.

Creating an Example Object

  1. Create a new site-scoped object called Event that’s accessible in the Content and Date menu. If needed see Creating and Managing Objects.

  2. Give the object these fields:

    • A Text field called Event Name
    • An Integer field called Number of Invitees
    • A Date field called Event Date
  3. Publish the object and go to the Events application in the site’s Content and Data menu.

  4. 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

Add Event entries to populate the system with data.

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy