Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

AEM 6.5 Search Suggestion

Avatar

Level 2

Hi,

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 ? 

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

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 ?

View solution in original post

6 Replies

Avatar

Employee

You can try a query similar to:

fulltext=English
path=/content/we-retail

group.p.or=true
group.1_group.type=cq:Page


group.2_group.property=jcr:content/cq:template
group.2_group.property.value=/conf/we-retail/settings/wcm/templates/hero-page
p.limit=-1

 

And test it in Querry builder Debbuger: http://localhost:4502/libs/cq/search/content/querydebug.html

 

You can translate it to SQL syntax by evaluating it in Query Explanation tool at http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html

 

Avatar

Community Advisor

Hi @berkayf70599426 ,

 

To implement suggestions you would need to also have the required index created. Please refer the below link for how your index definition should look like -

 

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

 

Avatar

Community Advisor

Hi @berkayf70599426,

Jackrabbit Oak supports search suggestions when using Lucene/Solr Index. 

Given this understanding, your query should be using cqPageLucene index - /oak:index/cqPageLucene 

For suggestion to work, 

  • "useInSuggest" should be set to true. (OOB cqPageLucene has this for properties jcrTitle and jcrDescription, navTitle, pageTitle, nodeName)
    • /oak:index/cqPageLucene/indexRules/cq:Page/properties/jcrTitle
    • /oak:index/cqPageLucene/indexRules/cq:Page/properties/jcrDescription
  • 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:

  • 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

Avatar

Community Advisor

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,

Avatar

Correct answer by
Level 2

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 ?

Avatar

Community Advisor

Hi @berkayf70599426,

There is no explicit mention in the official documentation about the support of other clause.

However, given the fact that ISDESCENDANTNODE support is included as an enhancement/update to suggestion + from the way suggestion results work, it makes sense to conclude that it supports one ISDESCENDANTNODE alone.