[MGNLREST-169] By default, items should have order that they have in Magnolia Created: 29/Jan/18  Updated: 27/Mar/18  Resolved: 11/Mar/18

Status: Closed
Project: Magnolia REST Framework
Component/s: delivery
Affects Version/s: None
Fix Version/s: 2.1

Type: Bug Priority: Major
Reporter: Christopher Zimmermann Assignee: Mikaël Geljić
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 0d
Time Spent: 0.5d
Original Estimate: Not Specified

Attachments: PNG File screenshot-1.png     PNG File screenshot-2.png    
Issue Links:
relation
is related to MGNLREST-173 Get ordered tree of content from conf... Closed
is related to DOCU-1349 How to get items in natural order wit... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Release notes required:
Yes
Documentation update required:
Yes
Date of First Response:
Sprint: Saigon 137
Story Points: 3

 Description   

Expected behaviour: If I don't specify a sort, that I expect the items to have the order that they have in Magnolia.
Actual behaviour: Items are sorted by name.



 Comments   
Comment by Christopher Zimmermann [ 29/Jan/18 ]

Until this is fixed, is there a workaround to get the items in the magnolia-stored order?

Comment by Mikaël Geljić [ 19/Feb/18 ]

czimmermann Yes, you get a sorted array of child-node names under the @nodes property. This is an inherent limitation of JSON btw iirc. May we close this issue then?

Comment by Christopher Zimmermann [ 19/Feb/18 ]

In this case - im referring to the query usage, I should have mentioned that. For example:
https://demopublic.magnolia-cms.com/.rest/delivery/tours/v1/
Gives me all the tours sorted by name. But I would expect the default sort order to be their order in Magnolia content app.
Im referring to an array - where order is preserved in JSON.

Comment by Mikaël Geljić [ 28/Feb/18 ]

As per our discussion yesterday morning:

I can confirm there is a default alphabetical sort on node names (ORDER BY LOWER(NAME(t)) statement in the JCR-SQL2 query), even when the orderBy param is not used. And I agree with you that queries should be "unsorted" by default.

This doesn't necessarily mean natural order. It depends:

  1. on the respectDocumentOrder property in JR workspace config (has been true in Magnolia's default config for years, but users may set it to false to improve query performance);
  2. on consistency of the index. Unfortunately it usually varies over time (say w/ move operations, activations, etc.).

As an alternative, one may run a simple "read" request to the parent node and get the naturally-ordered child-nodes like I suggested earlier.
—A good question is whether it works for the repository root. Probably not since it gets hard to disambiguate the query method-endpoint vs. reading root node then. And declaring rep:root in the endpoint config sounds quite dirty to me. Better pushing those nodes under a folder.

Comment by Christopher Zimmermann [ 28/Feb/18 ]

Thanks for research and detailed response!
As to the final point. I see putting things at the root in a folder as a workaround.
Since we support content at the root - and normal freemarker templating can get that content - we should support that in our REST api as well.
Also - a developer may want to get all of the folders at the ROOT level in order.
I created https://jira.magnolia-cms.com/browse/MGNLREST-173 to address this.

Comment by Christopher Zimmermann [ 27/Mar/18 ]

Depth only affects which "children" a specfic node result has. So, yes - each result has its immediate childrenincluded (the areas).

For me, what makes these results confusing - is that with the provided URL, I would somehow expect to be getting the NODE endpoint result of the ROOT node. But instead we get the QUERY endpoint result - and so it returns all of the pages - not just the pages at the root.

I dont think there is a way to use the NODE endpoint at the root. (Can you confirm that sang.ngo ?) I have created a ticket to address that: https://jira.magnolia-cms.com/browse/MGNLREST-173

Generated at Mon Feb 12 06:57:18 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.