Does the indexes operator sort the output? Why?
Test
- goto https://tiddler.wiki.com
- create a dictionary tiddler called test as below
jane: mother
loo : father
ana: dauhther
kian: son
- create another tiddler to test with below content
<$list filter="[[test]indexes[]]" variable=link>
* my name: <<link>>
</$list>
It produces
-
my name: ana
-
my name: jane
-
my name: kian
-
my name: loo
But I do not want to sort output internally!
EDIT: I know I can sort using sortby, to retain the original order, but this is infeasible for large data.
EDIT ii: See the workaround for this case: The Indexes Operator - #8 by Mohammad
Speculation but indexing/indexes is usually sorted to support locating the index value.
Workaround, especially with dictionary tiddlers parse the text field directly;
<ul>
<$list filter="[[Data]get[text]splitregexp[\n]]" variable=each-line>
<li> {{{ [<each-line>split[:]first[]] }}}</li>
</$list>
</ul>
Produces
Thank you Tony! Good workaround!
See: $:/core/modules/filters/indexes.js
/*\
title: $:/core/modules/filters/indexes.js
type: application/javascript
module-type: filteroperator
Filter operator for returning the indexes of a data tiddler
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.indexes = function(source,operator,options) {
var results = [];
source(function(tiddler,title) {
var data = options.wiki.getTiddlerDataCached(title);
if(data) {
$tw.utils.pushTop(results,Object.keys(data));
}
});
results.sort();
return results;
};
})();
Note to results.sort();
FYI: I removed results.sort(); from $:/core/modules/filters/indexes.js saved and reloaded and it worked with your test data and did not sort.
As just a script kiddie I tried to make my own operator rawindexes but it only returns the data tiddler?
rawindexes.json (812 Bytes)
<$list filter="[[Data]rawindexes[]]" variable=link>
* my name: <<link>>
</$list>
So it needs something else
done!
The original order cannot be guaranteed because internally the dictionary tiddler is implemented as a JSON object. See:
pmario
6
I’ve updated the docs for the indexes operator to note the sorting behaviour:
Thank you all!
I understood there is a technical reason for sorting the output from indexes.
Workaround
For my use case where I need the original order, I used the solution by @TW_Tones and it works for me
<$list filter="[[test]get[text]splitregexp[\n]] :map[split[:]trim[]]" variable=link>
* my name: <<link>>
</$list>