May 3, 2020
Estimated Post Reading Time ~

Predictive Search and Spell check in AEM

Search is a very important feature when it comes to any CMS solution. AEM offers a lot of cool search features that you can use. I will briefly touch base on the following two search features that I am working off late.
  1. Predictive Search
  2. Spell Check
Predictive Search
Prerequisites:
You need to have at least OAK 1.1.6 to enable a predictive search in AEM.
AEM 6.1 ships with a higher OAK version, so in a way, this feature is available in OOTB installation. However, if your application runs on AEM 6.0, you might want to check the OAK version and bring it up to at least 1.1.6

Configuration:
Predictive search can be configured in AEM 6.x using the following simple steps:
  • Configure a lucene index for word suggestions
If you are using lucene, then following index configuration is applicable
/oak:index/lucene-suggest
  - jcr:primaryType = "oak:QueryIndexDefinition"
  - compatVersion = 2
  - type = "lucene"
  - async = "async"
  - suggestUpdateFrequencyMinutes = 60
  + indexRules
    - jcr:primaryType = "nt:unstructured"
    + nt:base
      + properties
        - jcr:primaryType = "nt:unstructured"
        + jcr:description
          - propertyIndex = true
          - analyzed = true
          - useInSuggest = true

you can add other properties like jcr:title depending upon the requirement.
  • Using property rep:suggest() to retrieve word suggestions.
OAK 1.1.6 introduces support for rep:suggest() property to enable word suggestions following query can be used:

SELECT [rep:suggest()] FROM nt:base WHERE [jcr:path] = '/' AND SUGGEST('keyword')

Spell Check Support
Enabling spell check requires the same steps as that of predictive search. You need OAK 1.1.6 to get this working.

Configuration:
The following lucene index needs to be created first

/oak:index/lucene-spellcheck
  - jcr:primaryType = "oak:QueryIndexDefinition"
  - compatVersion = 2
  - type = "lucene"
  - async = "async"
  + indexRules
    - jcr:primaryType = "nt:unstructured"
    + nt:base
      + properties
        - jcr:primaryType = "nt:unstructured"
        + jcr:title
          - propertyIndex = true
          - analyzed = true
          - useInSpellcheck = true

rep:spellcheck() can be used for getting spell suggestions as used in the following query :

SELECT [rep:spellcheck()] FROM nt:base WHERE [jcr:path] = '/' AND SPELLCHECK('keyword').



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.