XPath query ignoring the (sort by @jcr:score ) | Community
Skip to main content
Level 2
April 7, 2016
Solved

XPath query ignoring the (sort by @jcr:score )

  • April 7, 2016
  • 4 replies
  • 2524 views

5.6.1 upgraded to 6.1 environment.

We have the following XPath generated by QueryBuilder (some node names changed):

/jcr:root/content/company1/application1/en//element(*, cq:Page)[(jcr:content/@cq:template = '/apps/company1/templates/application1/exceptionpage' or jcr:content/@cq:template = '/apps/company1/templates/application1/manualpage' or jcr:content/@cq:template = '/apps/company1/templates/application1/guidelinepage' or jcr:content/@cq:template = '/apps/company1/templates/application1/formpage' or jcr:content/@cq:template = '/apps/company1/templates/application1/bulletinpage' or jcr:content/@cq:template = '/apps/company1/templates/application1/realstatepraticespage') and jcr:content/st-documentNode/@docExist = 'true' and (jcr:contains(jcr:content/st-documentNode/documentName, 'ALTA') or jcr:contains(., 'ALTA'))] order by @jcr:score descending

When the query is executed in AEM 6.1 CRX DE, it appears that the sort order does not have any effect on the order of returned records (nodes). Even when order by clause removed, the query produces records in the same order.

In the same query, executed in 5.6.1, change in the order by clause actually results in change of the result set records (nodes) order.

 

Any Ideas where I might be doing wrong?

Regards,

-N

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

With AEM 6.1 - Indexing plays a role that was not in 5.6.

https://docs.adobe.com/docs/en/aem/6-0/deploy/upgrade/queries-and-indexing.html

I recommend watching this GEMs session: 

http://dev.day.com/content/ddc/en/gems/oak-lucene-indexes.html

4 replies

smacdonald2008
smacdonald2008Accepted solution
Level 10
April 7, 2016

With AEM 6.1 - Indexing plays a role that was not in 5.6.

https://docs.adobe.com/docs/en/aem/6-0/deploy/upgrade/queries-and-indexing.html

I recommend watching this GEMs session: 

http://dev.day.com/content/ddc/en/gems/oak-lucene-indexes.html

Level 2
April 8, 2016

Thanks... I'll do that!

Regards,

-N

Level 2
April 14, 2016

Hi Scott,

Thanks for the good pointers, I did some reading on OAK indexes and came up with the following index definition:

/oak:index/vuDocumentsIndex (oak:QueryIndexDefinition) - compatVersion = 2 - type = "lucene" - async = "async" - evaluatePathRestrictions = true + indexRules (nt:unstructured) + cq:Page (nt:unstructured) + properties + template - propertyIndex = true - name = "jcr:content/cq:template" + docExists - propertyIndex = true - name = "jcr:content/st-documentNode/docExist" + docSusp - propertyIndex = true - name = "jcr:content/st-documentNode/susDisp" + docName - name = "jcr:content/st-documentNode/documentName" - analyzed = true + theNodeProps - name = ".*" - isRegexp = true - nodeScopeIndex = true

I was hoping to get the following XPath Query to use the index:

/jcr:root/content/st/vu/en//element(*, cq:Page)[(jcr:content/@cq:template = '/apps/st/templates/vu/exceptionpage' or jcr:content/@cq:template = '/apps/st/templates/vu/manualpage' or jcr:content/@cq:template = '/apps/st/templates/vu/guidelinepage' or jcr:content/@cq:template = '/apps/st/templates/vu/formpage' or jcr:content/@cq:template = '/apps/st/templates/vu/bulletinpage' or jcr:content/@cq:template = '/apps/st/templates/vu/realstatepraticespage') and jcr:content/st-documentNode/@docExist = 'true' and (jcr:contains(jcr:content/st-documentNode/documentName, 'ALTA') or jcr:contains(., 'ALTA'))] order by @jcr:score descending

Few challenges I have:

  1. The index never finishes building. When I go to http://localhost:4502/libs/granite/operations/content/diagnosis/tool.html/_granite_oakindexmanager# the reindex column shows "spinning rectangles" (even after instance restart). in a ~30 seconds a popup shows Reindex Checking time out for : vuDocumentsIndex.Page refresh shows "spinning rectangles" again and the message pops up again. It appears query never finished building.
  2. The query performance tool : (http://localhost:4502/libs/granite/operations/content/diagnosis/tool.html/_granite_queryperformance) shows in the Indexes Used section that "No index was used" and "A full text index was used". At this point I can attribute this to Issue number 1.

Where possible I'm going wrong? Any help is appreciated.

Regards.

-N

Level 2
April 14, 2016

Just an update:

Managed to create/reindex the query: 

/oak:index/vuDocumentsIndex

Here is the final version:

/oak:index/vuDocuments (oak:QueryIndexDefinition) - compatVersion = 2 - type = "lucene" - async = "async" - evaluatePathRestrictions = true - queryPaths = ["/content/st/vu/en"] - includedPaths = ["/content/st/vu/en"] + indexRules (nt:unstructured) + cq:Page (nt:unstructured) + properties + template - propertyIndex = true - name = "jcr:content/cq:template" + docExists - propertyIndex = true - name = "jcr:content/st-documentNode/docExist" + docSusp - propertyIndex = true - name = "jcr:content/st-documentNode/susDisp" + docName - name = "jcr:content/st-documentNode/documentName" - analyzed = true + theNodeProps - name = ".*" - isRegexp = true - nodeScopeIndex = true

 

It appears that the value of the async property had an extra space i.e. "async ". Fixing that, plus adding includePaths and queryPaths seems to resolve issue 1.

But I still have issue 2 - the query does not utilize the index. Any ideas?

Regards,

-N