Custom Element Examples

Here are example elements that use custom fields and nested fields in their contributed query clauses.

Using Custom Fields (Expando) in Elements

You can add custom fields to types that implement the expando framework (e.g., users, blogs entries, etc.). These fields are indexed according to the field mappings.

This custom element filters based on a custom integer field; the Blueprint creator can choose the integer 1,2, or 3, from a drop-down list per the element’s uiConfiguration:

{
  "description_i18n": {
    "en_US": "Filter by Custom Field Match (Integer)"
  },
  "elementDefinition": {
    "category": "boost",
    "configuration": {
      "queryConfiguration": {
        "queryEntries": [
          {
            "clauses": [
              {
                "context": "query",
                "occur": "filter",
                "query": {
                  "term": {
                    "expando__keyword__custom_fields__Requested number of pages_long.keyword": {
                      "value": "${configuration.pages}"
                    }
                  }
                }
              }
            ]
          }
        ]
      }
    },
    "uiConfiguration": {
      "fieldSets": [
        {
          "fields": [
            {
              "defaultValue": "1",
              "label": "pages",
              "name": "pages",
              "type": "select",
              "typeOptions": {
                "options": [
                  {
                    "label": "1",
                    "value": "1"
                  },
                  {
                    "label": "2",
                    "value": "2"
                  },
                  {
                    "label": "3",
                    "value": "3"
                  }
                ]
              }
            }
          ]
        }
      ]
    },
    "icon": "thumbs-up"
  },
  "externalReferenceCode": "FILTER_BY_EXPANDO_INTEGER_FIELD",
  "title_i18n": {
    "en_US": "Filter results by the expando field called Requested Number of Pages (Integer)"
  },
  "type": 0
}

Using Nested Fields in Elements

Object definition fields, web content structure fields, document type fields, and form fields are indexed as nested fields.

Objects Fields in Elements

Objects fields are indexed as nested fields under a parent field called nestedFieldArray.

"nestedFieldArray" : [
   {
     "fieldName" : "lastAcessed",
     "valueFieldName" : "value_date",
     "value_date" : "20230502000000"
   },
   {
     "fieldName" : "immunityType",
     "valueFieldName" : "value_keyword",
     "value_keyword" : "diplomatic"
   },
   {
     "fieldName" : "randomNumber",
     "valueFieldName" : "value_integer",
     "value_integer" : "19"
   }
],

This element filters by the objects date field using a date range query:

{
  "description_i18n": {
    "en_US": "Filter by objects field (date) using a range query"
  },
  "elementDefinition": {
    "category": "filter",
    "configuration": {
      "queryConfiguration": {
        "queryEntries": [
          {
            "clauses": [
              {
                "context": "query",
                "occur": "filter",
                "query": {
                  "nested": {
                    "path": "nestedFieldArray",
                    "query": {
                      "bool": {
                        "filter": {
                          "term": {
                            "nestedFieldArray.fieldName": "lastFactChecked"
                          }
                        },
                        "must": {
                          "range": {
                            "nestedFieldArray.value_date": {
                              "from": "${configuration.start_date}",
                              "include_lower": true,
                              "include_upper": true,
                              "to": "${configuration.end_date}"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        ]
      }
    },
    "icon": "filter",
    "uiConfiguration": {
      "fieldSets": [
        {
          "fields": [
            {
              "label": "Last fact checked, start",
              "name": "start_date",
              "type": "date",
              "typeOptions": {
                "format": "YYYYMMDDHHMMSS"
              }
            },
            {
              "label": "Last fact checked, end",
              "name": "end_date",
              "type": "date",
              "typeOptions": {
                "format": "YYYYMMDDHHMMSS"
              }
            }
          ]
        }
      ]
    }
  },
  "externalReferenceCode": "FILTER_BY_OBJECTS_FIELD_DATE",
  "title_i18n": {
    "en_US": "Filter by Ojects Field (Date)"
  }
}

Web Content Structure Fields in Elements

Liferay entities that use the Dynamic Data Mapping framework are indexed similarly. Because of their shared backend, web content structure fields, document type fields, and form fields are indexed as nested fields under a parent field called ddmFieldArray.

[
   {
      ddmFieldName=ddm__keyword__32963__Select49369461_en_US, ddmFieldValueKeyword_en_US=Option08094628, ddmFieldValueKeyword_en_US_String_sortable=world news, ddmValueFieldName=ddmFieldValueKeyword_en_US
   },
   {
      ddmFieldName=ddm__keyword__32963__Text84613904_en_US, ddmFieldValueKeyword_en_US=We should get this right, so we can wait a couple days to publish if it needs lots of review and fact checking, ddmFieldValueKeyword_en_US_String_sortable=we should get this right, so we can wait a couple days to publish if it needs lots of review and fact checking, ddmValueFieldName=ddmFieldValueKeyword_en_US
   },
   {
      ddmFieldName=ddm__text__32963__Image01971053_en_US, ddmFieldValueText_en_US_String_sortable={"groupid":"20117","alt":"","name":"masters_hierarchy.png","width":"630","description":"","title":"masters_hierarchy.png","type":"document","uuid":"bc058267-d02b-051b-71e3-bfe04d721148","fileentryid":"33037","resourceprimkey":"33051","url":"/documents/d/g, ddmValueFieldName=ddmFieldValueText_en_US, ddmFieldValueText_en_US={"groupId":"20117","alt":"","name":"masters_hierarchy.png","width":"630","description":"","title":"masters_hierarchy.png","type":"document","uuid":"bc058267-d02b-051b-71e3-bfe04d721148","fileEntryId":"33037","resourcePrimKey":"33051","url":"/documents/d/guest/masters_hierarchy-png","height":"787"}
   },
   {
      ddmFieldName=ddm__keyword__32963__Date84390794_en_US, ddmFieldValueKeyword_en_US=2024-10-25, ddmFieldValueKeyword_en_US_String_sortable=2024-10-25, ddmValueFieldName=ddmFieldValueKeyword_en_US, ddmFieldValueKeyword_en_US_date=20241025000000, ddmFieldValueKeyword_en_US_date_sortable=1729814400000
   },
   {
      ddmFieldName=ddm__text__32963__RichText44628986_en_US, ddmFieldValueText_en_US_String_sortable=donec ut viverra urna. mauris suscipit quam tincidunt auctor accumsan. in ante nisi, consequat in risus at, faucibus pretium nulla. aenean finibus elit ac suscipit tincidunt. pellentesque vehicula mi sit amet posuere maximus. vivamus vulputate ante et con, ddmValueFieldName=ddmFieldValueText_en_US, ddmFieldValueText_en_US=Donec ut viverra urna. Mauris suscipit quam tincidunt auctor accumsan. In ante nisi, consequat in risus at, faucibus pretium nulla. Aenean finibus elit ac suscipit tincidunt. Pellentesque vehicula mi sit amet posuere maximus. Vivamus vulputate ante et consequat dignissim. Aenean vulputate ex sit amet lectus lacinia iaculis. Integer efficitur scelerisque turpis quis imperdiet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Fusce mollis nulla eu euismod tincidunt. Nulla facilisi. Curabitur vestibulum luctus sem, sed feugiat metus lacinia sed. Nam dui justo, auctor id aliquam vitae, sollicitudin sit amet mauris. Nunc in faucibus massa, quis tincidunt orci. Mauris viverra sem leo, sed lobortis nibh scelerisque iaculis. Nulla facilisi. Aenean vitae viverra leo, quis laoreet neque. Vestibulum vel ex accumsan, mattis felis a, faucibus ex. Nunc eu vulputate velit. Curabitur in interdum sem, eu vehicula ipsum. Donec at consectetur ipsum. Integer pellentesque lectus in risus egestas ullamcorper vitae nec velit. Fusce euismod lacinia fringilla. Nunc eu dolor enim. Nam fermentum lacinia lobortis. Praesent tortor eros, tempor eget luctus eu, molestie at metus. Integer mollis, augue sed facilisis volutpat, libero nisi fringilla tortor, maximus ornare urna quam ut dui. Maecenas ut mi ultricies, hendrerit orci et, efficitur nisi. Curabitur sit amet tempus nibh. Sed nec mauris eget felis porttitor pharetra a ultricies arcu.
   },
   {
      ddmFieldName=ddm__keyword__32963__Grid03475490_en_US, ddmFieldValueKeyword_en_US={"Option10114052":"Option99280913","Option18600029":"Option56717127"}, ddmFieldValueKeyword_en_US_String_sortable={"option10114052":"option99280913","option18600029":"option56717127"},ddmValueFieldName=ddmFieldValueKeyword_en_US
   },
   {
      ddmFieldName=ddm__keyword__32963__Text36506759_en_US, ddmFieldValueKeyword_en_US=United Republic of Whoville to seek entrance into League of Harmonic Countries, ddmFieldValueKeyword_en_US_String_sortable=united republic of whoville to seek entrance into league of harmonic countries, ddmValueFieldName=ddmFieldValueKeyword_en_US
   }
]

A select from list field’s indexed data looks like this:

{
   ddmFieldName=ddm__keyword__32963__Select49369461_en_US,
   ddmFieldValueKeyword_en_US=Option08094628,
   ddmFieldValueKeyword_en_US_String_sortable=world news,
   ddmValueFieldName=ddmFieldValueKeyword_en_US
}

This element filters by the web content select from list field:

{
  "description_i18n": {
    "en_US": "Filter by DDM field (select from list)"
  },
  "elementDefinition": {
    "category": "filter",
    "configuration": {
      "queryConfiguration": {
        "queryEntries": [
          {
            "clauses": [
              {
                "context": "query",
                "occur": "filter",
                "query": {
                  "nested": {
                    "path": "ddmFieldArray",
                    "query": {
                      "bool": {
                        "filter": {
                          "match": {
                            "ddmFieldArray.ddmFieldName": "ddm__keyword__32963__Select49369461_en_US"
                          }
                        },
                        "must": {
                          "term": {
                            "ddmFieldArray.ddmFieldValueKeyword_en_US": "${configuration.option}"
                          }
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        ]
      }
    },
    "icon": "filter",
    "uiConfiguration": {
      "fieldSets": [
        {
          "fields": [
            {
              "label": "Option to filter by:",
              "name": "option",
              "type": "select",
              "typeOptions": {
                "options": [
                  {
                    "label": "World News",
                    "value": "Option08094628"
                  },
                  {
                    "label": "Local News",
                    "value": "Option23258977"
                  },
                  {
                    "label": "Regional News",
                    "value": "Option53535414"
                  }
                ]
              }
            }
          ]
        }
      ]
    }
  },
  "externalReferenceCode": "FILTER_BY_DDM_FIELD_SELECT",
  "title_i18n": {
    "en_US": "Filter by DDM Field (Select from List)"
  }
}

This approach also applies to Forms fields and Document Type fields.

Capabilities

Product

Education

Contact Us

Connect

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