AEM 6.X - Predictive Search and Spell check

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.
  • Predictive Search
  • Spell Check

Predictive Search

Prerequisites:

You need to have atleast OAK 1.1.6 to enable 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 atleast 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 suggestionsThe 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')

Comments

  1. HI
    Thanks for your valuable post.Am using query builder API to retrieve the search.Will it will be able to handle it by defaults.Can u please share a piece of code by using query builder

    ReplyDelete
    Replies
    1. Hi,

      Thanks for the feedback. You can use something like this :


      String query = "SELECT [rep:suggest()] FROM nt:base WHERE [jcr:path] = '/' AND SUGGEST('keyword')";
      Query searchQuery = qm.createQuery(query, Query.SQL);

      List list = new ArrayList();
      RowIterator it = searchQuery.execute().getRows();
      while (it.hasNext()) {
      Row row = it.nextRow();
      list.add(row.getValue("rep:suggest()").getString());
      }

      Each item in the list gives you a word suggestion and the corresponding weight for the suggestion item.

      Hope this helps.

      Delete
  2. Hi, I am trying to do the spell check in my application. I have configured spellcheck node as mentioned above and trying to execute the query the one mentioned below node structure. When I am executing query in CRX sql console which is "select [rep:spellcheck] from nt:base where jcr:path like '/content/gsam/%' and SPELLCHECK('incme')" its not giving me any result

    Can you please help me with this

    lucene-spellcheck: {
    jcr:primaryType: "oak:QueryIndexDefinition",
    compatVersion: 2,
    type: "lucene",
    async: "async",
    reindex: false,
    reindexCount: 3,
    indexRules: {
    jcr:primaryType: "nt:unstructured",
    nt:base: {
    jcr:primaryType: "nt:unstructured",
    properties: {
    jcr:primaryType: "nt:unstructured",
    jcr:title: {
    jcr:primaryType: "nt:unstructured",
    propertyIndex: true,
    analyzed: true,
    useInSpellcheck: true,
    name: "jcr:title",
    type: "String"
    }
    }
    }
    }
    }

    ReplyDelete
  3. @Amandeep , did you try running it using the querybuilder code that i have pasted above? The crx console might not return composite object collections. Also, please keep in mind that the for predictive search, the use case 'abc def ' will not work as against 'abcdef'. please let me know if it works for you.

    ReplyDelete
  4. Hi Harwinder,

    I am trying to create an index for suggest. However, I am getting errors like "at least one suggestion must exist" and "No full-text index was found that can process the condition suggest". When I could finally get rid of the errors, I am able to get a single node as output with this query /jcr:root[rep:suggest('geom')]/(rep:suggest()). That node is simply displayed as "/" (this might be the root node or something with no data) How can I verify whether indexing has been successful and the suggest dictionary has been created???

    ReplyDelete
    Replies
    1. Hi Deepthi,

      you can do the following:

      1. check the logs if the indexing is triggered when you create the suggestion index or else manually trigger it.
      2. check if you have the search keyword available in the any of the indexed properties.

      if still you are not able to figure out, then please share the code snippet and relevant screenshots.

      Delete
    2. This comment has been removed by the author.

      Delete
  5. Hi, i am using AEM 6.0. How do i upgrade the oak to 1.1.6?

    ReplyDelete
    Replies
    1. You need to check with adobe for an oak patch for 1.1.6 or upgrade to AEM 6.1

      Delete
  6. Hi Harwinder, can you please tell me whether it is possible to set the interval for lucene-indexing? I mean, just like the suggestUpdateFrequencyMinutes for suggest, is there any property for normal lucene indexing as well?

    ReplyDelete
  7. I seems to got the suggestion working in AEM 6.1.

    But i couldn't get the spellchecker to work at all. It keeps returning empty result.

    The oak:index/lucene-spellchecker configuration is very much similar to what AMANDEEP SINGH has posted.

    Did you manage to get the spellchecker working?

    ReplyDelete
  8. I have created this but nothing seems to be suggested. its returning 0 results from

    "lucene-spellcheck": {
    "jcr:primaryType": "oak:QueryIndexDefinition",
    "compatVersion": 2,
    "type": "lucene",
    "async": "async",
    "reindex": false,
    "reindexCount": 12,
    "indexRules": {
    "jcr:primaryType": "nt:unstructured",
    "nt:base": {
    "jcr:primaryType": "nt:unstructured",
    "properties": {
    "jcr:primaryType": "nt:unstructured",
    "jcr:title": {
    "jcr:primaryType": "nt:unstructured",
    "propertyIndex": true,
    "analyzed": true,
    "useInSpellcheck": true
    }
    }
    }
    }
    },

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. http://screencast.com/t/3w1YbBWKQb8

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. it works only for 1 word search.
    OAK-3407

    ReplyDelete
  13. Really cool post, highly informative and professionally written and I am glad to be a visitor of this perfect blog, thank you for this rare info!
    Regards adobe cq5 training in hyderabad

    ReplyDelete
  14. Predictive search for AEM 6.2 using eclipse Servlet?? Any Idea?

    ReplyDelete
    Replies
    1. Can you please elaborate your use case. The mentioned approach is applicable for AEM 6.2 as well provided you meet the prerequisites.

      Delete
  15. This comment has been removed by the author.

    ReplyDelete
  16. Very useful post, You can learn AEM / Adobe CQ5 by watching videos in below youtube channel Shrinivas AEM Online Training. For Live AEM/Adobe CQ5 Online Training contact us at ibmitsolutions@gmail.com, India : +91-9642373173, USA : +1-845-915-8712

    ReplyDelete
  17. Very good write-up. I definitely appreciate this website. Continue the good work! Adobe Experience Manager Training
    Check AEM Tutorial for Beginners

    ReplyDelete
  18. Hi Harwinder,
    Thanks for the above post, it is very informative. I am trying to implement spellcheck in my application and using AEM 6.4. Could you please help in providing the above code using Query builder?

    ReplyDelete
  19. Personally I think overjoyed I discovered the blogs. witchcraft spells

    ReplyDelete

Post a comment