Property Index in AEM - Continued

custom property index
This post illustrate the usage of supporting properties that are part of Oak Property Index with sample use case. 

Use case:
DAM assets have a property called "cq:parentPath" (jcr:content node of type - dam:AssetContent has this property which has the value to be its parent folder path)
Example /content/dam/we-retail/en/features/cart.png/jcr:content

DAM asset parent path

We will write a query to get all assets from we-retail/en locale which has cq:parentPath property 
  • path=/content/dam/we-retail/en
  • type=dam:AssetContent
  • 1_property=cq:parentPath
  • 1_property.operation=exists
  • p.limit=-1
Create Property Index for "cq:parentPath" with mandatory properties alone. 

Parent Path  Property Index

With this set up, this index will be picked for all queries involving this property constraint + any "path" predicate.
Now to make this index to be used/picked for only certain paths we can control using  includedPaths and/or excludedPaths

includedPaths:
  • Add below property in newly created index node - /oak:index/cqParentPath
  • NameTypeValue
    includedPathsString[]/content/dam/we-retail/en
  • Index will be picked if we use the path predicate to be - /content/dam/we-retail/en or anything under /content/dam/we-retail/en/*
  • Index will not be picked if we use any path other than - /content/dam/we-retail/en 
    • Example : /content/dam/we-retail or any other path altogether.
excludedPaths:
  • Add below property in newly created index node - /oak:index/cqParentPath
  • NameTypeValue
    excludedPathsString[]/content/dam/we-retail/en/products
  • Index will not be picked if we use the path predicate to be - /content/dam/we-retail/en/products
  • Index will be picked if we use the path other than the content hierarchy that is part of excludedPaths.
  • Example: 
  • Below paths will let the index gets picked
    • /content/dam/we-retail/en/.* or any other project dam path- /content/dam/learnings
  • But not the below (all 3 are part of excludedPaths)
    • /content/dam
    • /content/dam/we-retail
    • /content/dam/we-retail/en
Both together:
  • If below two properties are available in newly created index node - /oak:index/cqParentPath
  • NameTypeValue
    excludedPathsString[]/content/dam/we-retail/en/products
    includedPathsString[]/content/dam/we-retail/en
  • Index will get picked for all paths under /content/dam/we-retail/en/.* except products.
  • Not for the below (all 3 are part of excludedPaths)
    • /content/dam
    • /content/dam/we-retail
    • /content/dam/we-retail/en (Though this is available in includedPaths, when used together with excludedPaths like above where this hierarchy is a part -> index will not be selected)
Video Demo : 

valuePattern:
Use case : Get all assets which has cq:parentPath value to be - /content/dam/we-retail/en/stores
  • path=/content/dam/we-retail
  • type=dam:AssetContent
  • 1_property=cq:parentPath
  • 1_property.value=/content/dam/we-retail/en/stores
  • p.limit=-1
  • Observing the value of cq:parentPath, regex pattern can be framed as 
    • all lower case alphabets +  contains "/" + can have hyphen(-) which is [a-z/\\-]+
    NameTypeValue
    valuePatternString[a-b/\\-]+
Video Demo:

valueExcludedPrefixes and valueIncludedPrefixes:
Use case : 
In we-retail content, we have pages with jcr:title - "Experience" for Language master, CA and US locale (3 result set)
We will use the prefix "Exp" from this value for illustrating valueExcludedPrefixes and valueIncludedPrefixes

Query to get all pages with jcr:title - Experience
  • path=/content/we-retail
  • type=cq:Page
  • 1_property=@jcr:content/jcr:title
  • 1_property.value=Experience
  • p.limit=-1
Create Property Index for "jcr:title" with mandatory properties alone.

JCR Title Property Index

valueIncludedPrefixes:
  • Add below property in newly created index node - /oak:index/jcrTitle
  • NameTypeValue
    valueIncludedPrefixesString[]Exp
  • Index will be picked if the "property.value" predicate starts with "Exp"
  • Index will not be picked if the "property.value" predicate starts with anything other than "Exp"
valueExcludedPrefixes:
  • Add below property in newly created index node - /oak:index/jcrTitle
  • NameTypeValue
    valueExcludedPrefixesString[]Exp
  • Index will be picked if the "property.value" predicate starts with anything other than "Exp"
  • Index will not be picked if the "property.value" predicate starts with "Exp"
Video Demo: 

declaringNodeTypes and unique:
Usage is available OOB in below Property Index definitions. 
  • /oak:index/principalName
  • /oak:index/authorizableId
For illustrating purpose and easy follow along, have considered using existing properties part of sample content - we.retail (for framing queries)
Play around in your local instance with your custom use case.
In real time projects, choice of index type/mode and hence its supporting properties to be carefully arrived at considering the query predicates used for a specific functionality + content volume on a long run.

Comments

Popular posts from this blog

Embedding Third party dependency/OSGi bundle in AEM application hosted in AEMasCS

OSGI Factory Configuration implementation

Creation of Template Types for Editable templates