auto complete suggest search | Community
Skip to main content
sreenu539
Level 7
May 6, 2023

auto complete suggest search

  • May 6, 2023
  • 9 replies
  • 2208 views

content structure: content fragment jcr:content, jcr:content/data/master nodes have properties such as jcr:title, tags. see below.

 

 

need to get suggestions based on jcr:title , tags.

if jcr:title or tags array contains search term text return a suggestion.

 

 

what I tried:

tried with below new oak index only on jcr:title

<testSuggestIndex jcr:primaryType="oak:QueryIndexDefinition" async="[async]" compatVersion="{Long}2" evaluatePathRestrictions="{Boolean}true" includedPaths="[/content/dam/sample]" reindex="{Boolean}false" reindexCount="{Long}20" seed="{Long}6707975003957838906" type="lucene"> <indexRules jcr:primaryType="nt:unstructured"> <dam:Asset jcr:primaryType="nt:unstructured"> <properties jcr:primaryType="nt:unstructured"> <jcrTitle jcr:primaryType="nt:unstructured" boost="{Double}2.0" name="jcr:content/jcr:title" nodeScopeIndex="{Boolean}true" propertyIndex="{Boolean}true" useInSpellcheck="{Boolean}true" useInSuggest="{Boolean}true"/> </properties> </dam:Asset> </indexRules> <suggest jcr:primaryType="nt:unstructured" suggestUpdateFrequencyMinutes="{Long}1"/> </testSuggestIndex>

 

1. contains query

2. rep:suggest query to get suggestions.

SELECT * FROM [dam:Asset] AS s WHERE ISDESCENDANTNODE([/content/dam/sample/faqs]) and CONTAINS(s.*, 'summit') SELECT [rep:suggest()] FROM [dam:Asset] WHERE SUGGEST('summit') AND ISDESCENDANTNODE('/content/dam/sample/faqs')

 

both above queries return same results.

 

But once I added "tags" to oak index definition (see below) , rep:suggest query ,  contains query returning different number of results. in fact, tags property not seeming to be picked by rep:suggest query.

 

<testSuggestIndex jcr:primaryType="oak:QueryIndexDefinition" async="[async]" compatVersion="{Long}2" evaluatePathRestrictions="{Boolean}true" includedPaths="[/content/dam/sample]" reindex="{Boolean}false" type="lucene"> <indexRules jcr:primaryType="nt:unstructured"> <dam:Asset jcr:primaryType="nt:unstructured"> <properties jcr:primaryType="nt:unstructured"> <jcrTitle jcr:primaryType="nt:unstructured" analyzed="{Boolean}true" boost="{Double}2.0" name="jcr:content/jcr:title" nodeScopeIndex="{Boolean}true" propertyIndex="{Boolean}true" useInSpellcheck="{Boolean}true" useInSuggest="{Boolean}true"/> <modelTags jcr:primaryType="nt:unstructured" analyzed="{Boolean}true" boost="{Double}2.0" name="jcr:content/data/master/tags" nodeScopeIndex="{Boolean}true" propertyIndex="{Boolean}true" useInSpellcheck="{Boolean}true" useInSuggest="{Boolean}true"/> </properties> </dam:Asset> </indexRules> <suggest jcr:primaryType="nt:unstructured" suggestUpdateFrequencyMinutes="{Long}1"/> </testSuggestIndex>

 

 at this time, I do not know what is wrong with my oak index definition. I need suggest on multiple properties one property is jcr:title is at jcr:content node level, another property tags is at jcr:content/data/master level as shown in screenshots.

 

any help is appreciated, I looked at several blogs and tried this but suggest not seeming to pick tags property on all nodes.

 

note: every time I changed index definition, reindex done as well.

 

Thanks,

Sri

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

9 replies

Community Advisor
May 6, 2023

@sreenu539 , make sure you have "path": "jcr:content/data/master" included in your index definition as shown below

 




sreenu539
sreenu539Author
Level 7
May 6, 2023

@shubhanshusi2 I added aggregates for "jcr:content", "jcr:content/data/master" no change in number of results for query rep:suggest.

Community Advisor
May 8, 2023

Can you share your query execution plan here? 

sreenu539
sreenu539Author
Level 7
May 8, 2023

 

seems like "includedPaths" , "ISDESCENDANTNODE" not working fine. why?

 

 

 

 

<testSuggestIndex jcr:primaryType="oak:QueryIndexDefinition" async="[async]" compatVersion="{Long}2" evaluatePathRestrictions="{Boolean}true" includedPaths="[/content/dam/sample]" reindex="{Boolean}false" type="lucene"> <aggregates jcr:primaryType="nt:unstructured"> <dam:Asset jcr:primaryType="nt:unstructured"> <include0 jcr:primaryType="nt:unstructured" path="jcr:content"/> <include8 jcr:primaryType="nt:unstructured" path="jcr:content/data/master"/> </dam:Asset> </aggregates> <indexRules jcr:primaryType="nt:unstructured"> <dam:Asset jcr:primaryType="nt:unstructured"> <properties jcr:primaryType="nt:unstructured"> <jcrTitle jcr:primaryType="nt:unstructured" analyzed="{Boolean}true" boost="{Double}2.0" name="jcr:content/jcr:title" nodeScopeIndex="{Boolean}true" propertyIndex="{Boolean}true" useInSpellcheck="{Boolean}true" useInSuggest="{Boolean}true"/> <modelTags jcr:primaryType="nt:unstructured" analyzed="{Boolean}true" boost="{Double}2.0" name="jcr:content/data/master/tags" nodeScopeIndex="{Boolean}true" propertyIndex="{Boolean}true" useInSpellcheck="{Boolean}true" useInSuggest="{Boolean}true"/> </properties> </dam:Asset> </indexRules> <suggest jcr:primaryType="nt:unstructured" suggestUpdateFrequencyMinutes="{Long}1"/> </testSuggestIndex>

 

 

 

 

 

 

above is modified testSuggestIndex at /oak:index node. Aggregators added for jcr:content, jcr:content/data/master

 

for word 'summit' returns some results

rep:suggest

 

for rmd there is some content tagged with tag sample:rmd

 

no results for rep:suggest

 

@shubhanshusi2 @arunpatidar @lukasz-m @veenavikraman

Community Advisor
May 9, 2023

Hi @sreenu539 ,

I created the index on a fresh AEM 6.5 installation and just updated  includedPaths property to point to we retail 

Index definition

 

// 20230509135521 // http://localhost:4502/oak%3Aindex/testSuggestIndex.-1.json { "jcr:primaryType": "nt:unstructured", "compatVersion": 2, "includedPaths": "/content/dam/we-retail/en/faqs/shipping-and-returns", "seed": 5486196388710534621, "type": "lucene", "async": [ "async" ], "evaluatePathRestrictions": true, "reindex": false, "reindexCount": 1, "aggregates": { "jcr:primaryType": "nt:unstructured", "dam:Asset": { "jcr:primaryType": "nt:unstructured", "include0": { "jcr:primaryType": "nt:unstructured", "path": "jcr:content" }, "include8": { "jcr:primaryType": "nt:unstructured", "path": "jcr:content/data/master" } } }, "suggest": { "jcr:primaryType": "nt:unstructured", "suggestUpdateFrequencyMinutes": 1 }, "indexRules": { "jcr:primaryType": "nt:unstructured", "dam:Asset": { "jcr:primaryType": "nt:unstructured", "properties": { "jcr:primaryType": "nt:unstructured", "jcrTitle": { "jcr:primaryType": "nt:unstructured", "nodeScopeIndex": true, "useInSuggest": true, "propertyIndex": true, "analyzed": true, "useInSpellcheck": true, "name": "jcr:content/jcr:title", "boost": 2 }, "modelTags": { "jcr:primaryType": "nt:unstructured", "nodeScopeIndex": true, "useInSuggest": true, "propertyIndex": true, "analyzed": true, "useInSpellcheck": true, "name": "jcr:content/data/master/tags", "boost": 2 } } } } }

 


Content


Query

 

SELECT [rep:suggest()] FROM [dam:Asset] WHERE SUGGEST('shipp') AND ISDESCENDANTNODE('/content/dam/we-retail/en/faqs/shipping-and-returns')

 


Execution Plan

Result

 

[ "Expedited Shipping", "Shipping Locations", "Shipping Methods", "Shipping Time", "we-retail:shipping" ]

 


As you can see above the query seems to be returning the results correctly after adding "jcr:content/data/master" in aggregates. 
For more info you can refer documentation : Jackrabbit Oak – Lucene Index (apache.org)

sreenu539
sreenu539Author
Level 7
May 9, 2023

@shubhanshusi2 For word "rmd" in my case, not returning any results.

It only returning results if I take out ISDESCENDANTNODE or includedPaths. 

 

Other than that, I see index you created is same as what I created.

Community Advisor
May 9, 2023

@sreenu539, the reason why your query with "rmd" is not returning any result is because - the subset is done by filtering the top 10 suggestions. So, it's possible to get no suggestions for a subtree query, if top 10 suggestions are not part of that subtree. For details look at OAK-3994 and related issues. It is mentioned in the Jackrabbit Oak documentation as a note.

Document: Jackrabbit Oak – Lucene Index (apache.org)
Reference: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-6-5-search-suggestion/td-p/374377

sreenu539
sreenu539Author
Level 7
May 10, 2023

@shubhanshusi2  sub tree mentioned in ISDESCENDANTNODE has tags, words which say "rmd" , It seems "includedPaths" is not supported, at the least for suggest.

Community Advisor
May 11, 2023

@sreenu539 The subtree might have the results but check this. 

From the query execution plan you can see - the suggest query first tries to get all the relevant suggestion - it takes the top 10 result and then apply your subtree filtering 

Now if the results under '/content/dam/sample/faqs' does not fall into the top 10 results you may get zero results.