Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

'Did you mean' functionality with AEM OOTB Search

Avatar

Level 2

I am trying to do a POC on did you mean functionality similar to google one using OOTB spellcheck feature. I have gone through the documentation mentioned below but I am not getting results. I have reindexed the content after these steps as well.

https://jackrabbit.apache.org/oak/docs/query/lucene.html#spellchecking 

 

My query -> "SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('tes') AND (ISDESCENDANTNODE('/content/myproject'))"

 

vignesh_bhat_0-1676979136196.png

 

vignesh_bhat_1-1676979243074.png

 

{
    "statement": "SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('tes') AND (ISDESCENDANTNODE('/content/myproject'))",
    "language": "JCR-SQL2",
    "explain": {
        "logs": [
            "Parsing JCR-SQL2 statement: explain SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('tes') AND (ISDESCENDANTNODE('/content/myproject'))\r\n",
            "cost using filter Filter(query=explain SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('tes') AND (ISDESCENDANTNODE('/content/myproject')), path=/content/myproject//*, property=[native*lucene=[suggest?term=tes]])\r\n",
            "cost for reference is Infinity\r\n",
            "cost for property is Infinity\r\n",
            "cost for nodeType is Infinity\r\n",
            "Applicable IndexingRule found IndexRule: nt:base\r\n",
            "Applicable IndexingRule found IndexRule: nt:base\r\n",
            "Applicable IndexingRule found IndexRule: cq:Page\r\n",
            "Applicable IndexingRule found IndexRule: cq:Page\r\n",
            "[/oak:index/cqPageLucene-custom-3] Copied 0 files totaling 0 B [took 8ms]\r\n",
            "[/oak:index/cqPageLucene-custom-3] Copied 0 files totaling 0 B [took 2ms]\r\n",
            "[/oak:index/cqPageLucene-custom-3] Closing NRTIndex [UNKNOWN]\r\n",
            "Applicable IndexingRule found IndexRule: nt:base\r\n",
            "Applicable IndexingRule found IndexRule: cq:Page\r\n",
            "[/oak:index/cqPageLucene] Copied 0 files totaling 0 B [took 7ms]\r\n",
            "[/oak:index/cqPageLucene] Copied 0 files totaling 0 B [took 3ms]\r\n",
            "[/oak:index/cqPageLucene] Closing NRTIndex [UNKNOWN]\r\n",
            "Applicable IndexingRule found IndexRule: cq:Page\r\n",
            "Applicable IndexingRule found IndexRule: nt:base\r\n",
            "Applicable IndexingRule found IndexRule: nt:base\r\n",
            "Applicable IndexingRule found IndexRule: nt:base\r\n",
            "Lucene46Codec is loaded: oakCodec\r\n",
            "Codec is loaded: Lucene46\r\n",
            "Applicable IndexingRule found IndexRule: nt:base\r\n",
            "cost for [/oak:index/cqPageLucene-custom-3] of type (lucene-property) with plan [lucene:cqPageLucene-custom-3(/oak:index/cqPageLucene-custom-3) *:*] is 2.00\r\n",
            "cost for [/oak:index/cqPageLucene] of type (lucene-property) with plan [lucene:cqPageLucene(/oak:index/cqPageLucene) *:*] is 2.00\r\n",
            "cost for lucene-property is Infinity\r\n",
            "minCost: 2.2 of index :aggregate lucene < best Cost: 2.0 from index: lucene-property. Further index evaluation will be skipped\r\n",
            "selected index org.apache.jackrabbit.oak.plugins.index.lucene.LucenePropertyIndex@33dfe2ac with plan /oak:index/cqPageLucene-custom-3 and org.apache.jackrabbit.oak.plugins.index.lucene.LucenePropertyIndex@33dfe2ac with plan /oak:index/cqPageLucene have similar costs 2.0 and 2.0 for query Filter(query=explain SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('tes') AND (ISDESCENDANTNODE('/content/myproject')), path=/content/myproject//*, property=[native*lucene=[suggest?term=tes]]) - check query explanation / index definitions\r\n",
            "cost for traverse is Infinity\r\n",
            "count:\t1\tquery:\texplain SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('x') AND (ISDESCENDANTNODE('x'))\r\n"
        ],
        "plan": "[cq:Page] as [cq:Page] /* lucene:cqPageLucene-custom-3(/oak:index/cqPageLucene-custom-3) *:* where (suggest([cq:Page], 'tes')) and (isdescendantnode([cq:Page], [/content/myproject])) */",
        "propertyIndexes": [
            "cqPageLucene-custom-3(/oak:index/cqPageLucene-custom-3)"
        ]
    },
    "heuristics": {
        "results": [
            "/",
            "/"
        ],
        "count": 2,
        "readPageTime": 5,
        "countTime": 5,
        "executionTime": 131,
        "getNodesTime": 5,
        "totalTime": 141
    }
}

 

Attaching the query explanation JSON. If anyone has tried spellcheck for similar use case please let me know.

1 Reply

Avatar

Community Advisor

Which AEM version you are using?