This test page shows a query for named subobjects in the style "Pagename#000, Pagename#001, Pagename#002, etc.". Is there a way to alter that order? So that the second column (Has subobject) could show a different order (descending, for example)? I could not figure out how to do it.
It looks like the |@sortkey parameter does not interact with the name of named subobjects. See the respective PR https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/225. So I believe that a helper property is needed to achieve what you would like to do.
Admittedly I have not fully understood what you are trying to do but ordering one column in a different one than the other is not even possible leaving subobjects aside. One sort order will take precedence over the other.
@kghbln, I want to have a way to control or, at least, to maintain the subobjects order in a fixed order. Did you realize that, when I created the page, the subobjects order was "001, 002, 003, 004", even if the order in the wikitext was different, and now the order is "004, 000, 003, 001, 002"? Did you have specified that order? I don't think so. So, the order is not consistent at all. It gets changing every time someone edits the subobjects.
That's why I put the Special:Browse over there: it shows that subobjects order in query results "respects", somehow, the subobjects stored order.
I want to have a way to control or, at least, to maintain the subobjects order in an fixed order.
That's easier for me to understand. :)
Did you realize that, when I create the page, the subobjects order was "001, 002, 003, 004"
Yes, but saving the subobjects to the page added the natural order as defined by the subobject's names. After reparsing or refreshing respectively the defined sortkey parameter comes into place as you can now see.
That's the expected behavior, no?
Yes, but saving the subobjects to the page added the natural order as defined by the subobject's names.
It doesn't. See:
The Special:Browse and the query result [0] show:
004, 000, 003, 001, 002
but, the wikitext order [1] is:
002, 004, 000, 001, 003
and, with the @sortkeys, I would expect to see:
000, 001, 002, 003, 004
(regardless the wikitext order, after all, it's a _named_ subject).
Maybe _anonymous_ subobjects order does not matter, but if I have named _and_ @sortkeys to specify the order, I would expect at least one of the two orders (name or sortkey) working.
Now, as you pointed, refreshing that page, I would expect to see:
000, 001, 002, 003, 004 (the order specified by the names or by the @sortkeys)
or even:
002, 004, 000, 001, 003 (the order in the wikitext)
not:
004, 000, 003, 001, 002
That order is not easily understood by users. Or I don't think it is documented anywhere.
PS.: Please do not edit the page 3, it would break the above example (but do refresh the page to test it).
[0] https://sandbox.semantic-mediawiki.org/wiki/Utilisateur:Jaideraf/Sandbox/3
[1] https://sandbox.semantic-mediawiki.org/w/index.php?title=Utilisateur:Jaideraf/Sandbox/3&action=edit
Well it seems that there is something in the water. Parsing can happen in an arbitrary order, so this is why we have the @deferred and @annotation query markers to somehow control this for other occasions. I would have thought that subobjects are indeed somehow reliably obeying @sortkey at least after rebuilding the data or conversely editing the page. This does not seem to be the case. Hmm, I am sure @mwjames can at least comment.
@mwjames can at least comment.
The Special:Browse and the query result
To clarify, the display in Special:Browse and the #ask query result cannot be compared because there are completely independent in how the data lookup is composed and executed.
When SMW stores data, it does so without any specific order in the table that holds the data since it does not matter whether [[Foo::123]] comes before [[Foo::345]] or after. It has no semantic relevance during the storage and with Special:Browse showing the "raw" data, the order in which 123, 345 appear depends more or less on when the row was added to the DB.
We don't order values for a specific property assignment in Special:Browse as it is not required (and you would get in trouble when trying to find an order for text containing [[Foo::123]] {{#set: Foo=345}} with MW processing #set first, meaning 345 would be stored before 123 even though the text says otherwise). It should be remembered that sorting results (when executing a DB query) is one of the most expensive operations therefore comparing the output of Special:Browse and #ask is going to fail.
If the subobject is used as subject entity (first column) then the @sortkey value comes into play since the result is sorted as part of the conditional execution during the #ask.
If the subobject is part of the result set in terms of a column (aka printout) representation, I suggest using things like |?Has subobject.A |+order=asc (see [0]) since the values are sorted based on the column order request.
Does this make sense? Did I miss something?
Thanks for looking into it @mwjames and @kghbln.
At [0], at the first query, we see
{{#ask: [[{{FULLPAGENAME}}]]
|?Has subobject
|?Has subobject.A
...
|sort=Has subobject
|order=descending
...
}}
The Has subobject column (a printout) shows #004, #000, #003, #001, #002 and I think this is the source of confusion. This still seems strange to me. |sort=Has subobject and |order=descending seem not to work.
But, happily you provided the |?Has subobject |+order=asc or |?Has subobject |+order=desc syntax, which did the trick.
So, I learned two things here:
1) It's better to use the subobjects as subject entities (first column) to make use of @sortkey, and
2) I can use the +order=asc in printouts columns.
I completely forgot about this syntax. @kghbln could you provide me the page where this syntax (+order=asc) is documented? I think this awesome syntax could be mentioned on page about sorting [1] or even on the page about displaying information [2].
Again: thank you guys, you are awsome!
You can close this issue if you want to.
[0] https://sandbox.semantic-mediawiki.org/wiki/Issue/2807
[1] https://www.semantic-mediawiki.org/wiki/Help:Sorting
[2] https://www.semantic-mediawiki.org/wiki/Help:Displaying_information
I completely forgot about this syntax. @kghbln could you provide me the page where this syntax (+order=asc) is documented?
Francly I did not have this in mind either. It is still hidden behind a "wikidocu missing" label (https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/2073).
Perhaps you could create a page like this one. I would fluff it up if necessary and create the connections on e.g. the pages mentioned [1,2]
Done. [0]
[0] https://www.semantic-mediawiki.org/wiki/Help:Ask_syntax/Printout_sorting_order
Done. [0]
Thanks a lot. I have just done some tweaking which still needs to be improved. Will test something tomorrow and further add to the page.
Finally put more fluff to the page @mwjames If you could have a peep.