I implement a custom search suggestion servlet. In servlet i use query like this "SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('tes') AND (ISDESCENDANTNODE('/content/myproject/tr'))".
In advance, i need to add template filter to results. So far i tried to add another where clause like [jcr:content/cq:template] <> '/conf/myproject/settings/wcm/templates/experience-fragment-web-variation-template' but that didn't work, query return 0 result. Then tried to exlude path that contains unwanted pages like this NOT ISDESCENDANTNODE('content/myproject/tr/somepath') that also didn't work. Do you guys have any suggestions for how to achieve what i want to do ?
Thanks for answers, I already modified cqPageLucene index for suggestion purposes and mostly it works fine. My queries return results e.g this query returns 3 nodes "SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('tes') AND (ISDESCENDANTNODE('/content/myproject/tr'))". When i checked results only 1 page's template is correct. Whenever i try to add another where clause like "AND NOT ISDESCENDANTNODE('/content/myproject/tr/unwantedpath'))" or "AND [jcr:content/cq:template] <> 'some-template-name' " there is always no result returns.
As far as i understand, only ISDESCENDANTNODE clause can be used with SUGGEST(), other constraints are not allowed to use in SUGGEST(), am i right ?
In suggestion there is a drawback. What happens is first it brings the top 10 results(before executing template condition) and then it will apply your template condition , So what happens is on the top 10 suggestion results from path /content/myproject/tr, if it has any record matching your template condition then it will return. Looks like your getting 0 results as top 10 records are not matching with template condition.
We have same issue in our project hence we started using typical query builder query and not suggestion,
Support for path check via "ISDESCENDANTNODE" is introduced since Oak 1.3.16/1.2.14 (Oak version of AEM 6.2 is 1.4.1. So should be available in all recent versions)
To respect ISDESCENDANTNODE, evaluatePathRestrictions should be set to true in index definition. (which is available in OOB cqPageLucene)
Suggestion results are top 10 filtered suggestions from Indexed content(will always be <= 10 and not greater than 10).
Below query will return suggestion results only if any of the filtered suggestions are part of the path (mentioned in ISDESCENDANTNODE). Otherwise it will be 0.
In other words, It is not like "get all the suggestions under the path 'content/myproject/tr' ". Suggestions are returned/evaluated and then path is respected.
SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('tes') AND (ISDESCENDANTNODE('/content/myproject/tr'))"
Now for debugging, I suggest you to
Cross check all the above and then
Execute the query in "Explain Query"(Tools -> Operations -> Diagnosis -> Query Performance -> Explain Query - Check "Include Node Count") without path restriction first - SELECT [rep:suggest()] FROM [cq:Page] WHERE SUGGEST('tes') and then observe the behavior with path.
Play around in your local instance with different suggest term/ paths to arrive at an above understanding