Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

auto complete suggest search

Avatar

Level 7

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

 

Screenshot from 2023-05-05 21-02-45.pngScreenshot from 2023-05-05 21-02-16.png

 

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

9 Replies

Avatar

Community Advisor

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

shubhanshu_singh_0-1683372212453.png

 




Avatar

Level 7

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

Avatar

Community Advisor

Can you share your query execution plan here? 

Avatar

Level 7

 

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

summit-suggest-query-explanation.png

 

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

rmd-cf.png

 

no results for rep:suggest

rmd-search-term-no-results.png

 

@shubhanshu_singh @arunpatidar @lukasz-m @VeenaVikraman

Avatar

Community Advisor

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

shubhanshu_singh_0-1683620996187.png


Query

 

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

 


Execution Plan

shubhanshu_singh_1-1683621075484.pngResult

 

[
"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)

Avatar

Level 7

@shubhanshu_singh 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.

Avatar

Community Advisor

@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/...

Avatar

Level 7

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

Avatar

Community Advisor

@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.