AEM 6.5 Search Suggestion

berkayf70599426

12-08-2020

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 ? 

 

 

Accepted Solutions (1)

Accepted Solutions (1)

berkayf70599426

12-08-2020

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 ?

Answers (4)

Answers (4)

SundeepKatepally

12-08-2020

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,

Vijayalakshmi_S

MVP

12-08-2020

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

berliant

Employee

12-08-2020

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