diff --git a/core/modules/filters/has.js b/core/modules/filters/has.js index de24ab67b..192daac70 100644 --- a/core/modules/filters/has.js +++ b/core/modules/filters/has.js @@ -3,7 +3,7 @@ title: $:/core/modules/filters/has.js type: application/javascript module-type: filteroperator -Filter operator for checking if a tiddler has the specified field +Filter operator for checking if a tiddler has the specified field or index \*/ (function(){ @@ -33,7 +33,23 @@ exports.has = function(source,operator,options) { } }); } - } else { + } + else if(operator.suffix === "index") { + if(invert) { + source(function(tiddler,title) { + if(!tiddler || (tiddler && (!$tw.utils.hop($tw.wiki.getTiddlerDataCached(tiddler,Object.create(null)),operator.operand)))) { + results.push(title); + } + }); + } else { + source(function(tiddler,title) { + if(tiddler && $tw.utils.hop($tw.wiki.getTiddlerDataCached(tiddler,Object.create(null)),operator.operand)) { + results.push(title); + } + }); + } + } + else { if(invert) { source(function(tiddler,title) { if(!tiddler || !$tw.utils.hop(tiddler.fields,operator.operand) || (tiddler.fields[operator.operand] === "")) { diff --git a/editions/tw5.com/tiddlers/filters/examples/has.tid b/editions/tw5.com/tiddlers/filters/examples/has.tid index 57941bd94..4f9654bd1 100644 --- a/editions/tw5.com/tiddlers/filters/examples/has.tid +++ b/editions/tw5.com/tiddlers/filters/examples/has.tid @@ -8,4 +8,6 @@ type: text/vnd.tiddlywiki <<.operator-example 1 "[has[color]]">> <<.operator-example 2 "[tag[Concepts]!has[modified]]">> <<.operator-example 3 "[has:field[emptyfield]]">> -<<.operator-example 4 "[all[current]!has:field[doesntexist]]">> \ No newline at end of file +<<.operator-example 4 "[all[current]!has:field[doesntexist]]">> +<<.operator-example 5 "[all[tiddlers+shadows]has:index[foreground]]">> +<<.operator-example 6 "[all[current]!has:index[doesntexist]]">> \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/filters/has.tid b/editions/tw5.com/tiddlers/filters/has.tid index ed9a536d1..cccb152ae 100644 --- a/editions/tw5.com/tiddlers/filters/has.tid +++ b/editions/tw5.com/tiddlers/filters/has.tid @@ -2,12 +2,13 @@ caption: has created: 20140410103123179 modified: 20190518145446047 op-input: a [[selection of titles|Title Selection]] -op-neg-output: ''without suffix''
» those input tiddlers in which field <<.place F>> does <<.em not>> exist or has an empty value
''suffix `field`''
» those input tiddlers in which field <<.place F>> does <<.em not>> exist +op-neg-output: ''without suffix''
» those input tiddlers in which field <<.place F>> does <<.em not>> exist or has an empty value
''suffix `field`''
» those input tiddlers in which field <<.place F>> does <<.em not>> exist
''suffix `index`''
» those input tiddlers in which index <<.place F>> does <<.em not>> exist op-output: ''without suffix''
» those input tiddlers in which field <<.place F>> has a non-empty value
''suffix `field`''
» those input tiddlers in which field <<.place F>> exists -op-parameter: the name of a [[field|TiddlerFields]] +op-parameter: the name of a [[field|TiddlerFields]]
''suffix `index`''
» those input tiddlers in which index <<.place F>> exists +op-parameter: the name of a [[field|TiddlerFields]] or, optionally an [[index|TextReference]] op-parameter-name: F op-purpose: filter the input by field existence -op-suffix: <<.from-version "5.1.14">> optionally, the keyword `field` +op-suffix: <<.from-version "5.1.14">> optionally, the keyword `field` or <<.from-version "5.1.22">> optionally, the keyword `index` op-suffix-name: S tags: [[Filter Operators]] [[Common Operators]] [[Field Operators]] [[Negatable Operators]] title: has Operator