Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IDEA] add second optional reverse operand to sort, nsort and sortcs operators #6423

Open
saqimtiaz opened this issue Jan 25, 2022 · 12 comments

Comments

@saqimtiaz
Copy link
Contributor

While the sort[], nsort[] and sortcs[] operators support use of the ! prefix to reverse the sort order, this cannot be assigned from a variable and requires string concatenation to construct the filter.

It is proposed to introduce a second optional operand that is the equivalent of using the ! prefix. The following two filter expressions would be equivalent:

[all[tiddler]sort[modified],[reverse]]
[all[tiddlers]!sort[modified]]

@Jermolene
Copy link
Owner

Thanks @saqimtiaz that makes complete sense, but would prevent us from using multiple operands to support multiple sort fields – it sometimes seems like it would be handy to be able to things like [all[tiddlers]sort[type],[modified]]. Of course, the same problem would crop up: it wouldn't be possible to reverse the sort of individual fields in the list.

@Jermolene
Copy link
Owner

Perhaps a :sort[] filter run prefix would be helpful?

@pmario
Copy link
Contributor

pmario commented Jan 25, 2022

I think, there are even more "sort" operators, that would benefit. eg: sortby doesn't support ! atm, but imo it should.

  • sortsub Operator
  • sortcs Operator
  • sortby Operator
  • sortan Operator
  • sort Operator
  • nsortcs Operator
  • nsort Operator

Should it be an optional second operator or should it be a flag: eg: [sort:reverse[modified]] ??

@saqimtiaz
Copy link
Contributor Author

Perhaps a :sort[] filter run prefix would be helpful?

@Jermolene We do have a :sort filter run prefix, but it does not accommodate the use case of assigning the reverse argument from a variable or text reference. It can however with some creativity be used to sort by multiple fields.

Should it be an optional second operator or should it be a flag: eg: [sort:reverse[modified]]

@pmario that does not meet the need for specifying a reverse sort using a variable or text reference.

@Jermolene
Copy link
Owner

@Jermolene We do have a :sort filter run prefix, but it does not accommodate the use case of assigning the reverse argument from a variable or text reference. It can however with some creativity be used to sort by multiple fields.

Doh! Of course, thank you.

@pmario that does not meet the need for specifying a reverse sort using a variable or text reference.

As a strawman, we could extend parseFilterOperation() to recognise alternate forms of the prefix. Along with the existing !, we could support <!var> as a way to indicate that the prefix should be taken from the specified variable.

So, we'd have:

[<!myvar>sort[modified]]

Or:

[<!myvar>sort<anothervar>]

@saqimtiaz
Copy link
Contributor Author

As a strawman, we could extend parseFilterOperation() to recognise alternate forms of the prefix. Along with the existing !, we could support <!var> as a way to indicate that the prefix should be taken from the specified variable.

That could be an option. I am also considering the viability of extending filter suffixes to support variables, though we need to consider whether that might get too confusing:

[all[tiddlers]sort:<sortvar>[modified]]

@saqimtiaz
Copy link
Contributor Author

The advantage of an alternative form of ! that can be specified by a variable is that all operators that already support the prefix can take advantage of it. I wonder if we can find a more intuitive syntax though, <!var> could be confused with title<!var>.

@kookma
Copy link
Contributor

kookma commented Jan 26, 2022

[all[tiddlers]sort:<sortvar>[modified]]

This seems more native in comparison to other suggested forms!

@joshuafontany
Copy link
Contributor

joshuafontany commented Jan 30, 2022

Would it make sense to extend the reverse[] Operator & call that out in the docs?

reverse<var>,<condition> or reverse{!!reverse-list},[yes]?

@Jermolene
Copy link
Owner

Would it make sense to extend the reverse[] Operator & call that out in the docs?

reverse<var>,<condition> or reverse{!!reverse-list},[yes]?

Hi @joshuafontany is the goal to be able to turn on or off reversing via a variable/transclusion?

@joshuafontany
Copy link
Contributor

Would it make sense to extend the reverse[] Operator & call that out in the docs?
reverse<var>,<condition> or reverse{!!reverse-list},[yes]?

Hi @joshuafontany is the goal to be able to turn on or off reversing via a variable/transclusion?

By my reading of @saqimtiaz 's post, yes. It is desirable to control sort order reversal via a contextual reference (var, transclusion). It makes more sense to me to use the reverse operator (which currently has no parameters).

@saqimtiaz
Copy link
Contributor Author

saqimtiaz commented Feb 2, 2022

@joshuafontany that is a good idea and worth considering as another improvement.

However, having a way to trigger the ! prefix for a filter operator via a variable/transclusion is still desirable as well. Adding such a possibility to the filter syntax would mean that all operators that support the ! flag would be able to trigger it via variable/transclusion.

Consider also that in the case of sorting large lists, performance is better to sort in the correct order, as opposed to sorting and then reversing the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants