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')
HI
ReplyDeleteThanks 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
Hi,
DeleteThanks 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.
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
ReplyDeleteCan 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"
}
}
}
}
}
@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.
ReplyDeleteHi Harwinder,
ReplyDeleteI 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???
Hi Deepthi,
Deleteyou 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.
This comment has been removed by the author.
DeleteHi, i am using AEM 6.0. How do i upgrade the oak to 1.1.6?
ReplyDeleteYou need to check with adobe for an oak patch for 1.1.6 or upgrade to AEM 6.1
DeleteHi 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?
ReplyDeleteI seems to got the suggestion working in AEM 6.1.
ReplyDeleteBut 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?
I have created this but nothing seems to be suggested. its returning 0 results from
ReplyDelete"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
}
}
}
}
},
This comment has been removed by the author.
ReplyDeletehttp://screencast.com/t/3w1YbBWKQb8
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteit works only for 1 word search.
ReplyDeleteOAK-3407
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!
ReplyDeleteRegards adobe cq5 training in hyderabad
Predictive search for AEM 6.2 using eclipse Servlet?? Any Idea?
ReplyDeleteCan you please elaborate your use case. The mentioned approach is applicable for AEM 6.2 as well provided you meet the prerequisites.
DeleteThis comment has been removed by the author.
ReplyDeleteVery good write-up. I definitely appreciate this website. Continue the good work! Adobe Experience Manager Training
ReplyDeleteCheck AEM Tutorial for Beginners
Hi Harwinder,
ReplyDeleteThanks 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?
Personally I think overjoyed I discovered the blogs. witchcraft spells
ReplyDelete