Syntax question about keeping duplicates within a field

The following code was a solution for a previous questions about keeping duplicates within a field.

<table>
<$list filter="[each[myField]get[myField]]
  :filter[all[tiddlers]myField<currentTiddler>count[]compare:number:gt[1]]">
<tr>
<td><<currentTiddler>></td>
<td>{{{ [myField<currentTiddler>] }}}</td>
</tr>
</$list>
</table>

<table>
<$list filter="[has[myField]get[myField]unique[]sort[]]" variable="fieldvalue"> 
<$list filter="[myField<fieldvalue>count[]compare:number:gt[1]]">
<tr><td><<fieldvalue>> </td>
<td>{{{ [myField<fieldvalue>] }}} </td>
</tr>
</$list>
</$list>

For the second solution, I think that the first filter should be simplified to

[has[myField]get[myField]sort[]]

because has assure that each title kept provides a unique value for the field. Am I right?

And for its second filter, how can a filter name (myField) be used as a filter operator? If I understand the intent, [myField<fieldvalue>] would be equivalent to [get[myField]enlist-input[raw]match<fieldValue>]. Am I right in the latter and what is happening with the first syntax, which I can’t make working with tw5.3.1.

The official documentation states that " The syntax of a filter step treats any unrecognised filter operator as if it was the suffix to the field operator., so [myField<fieldvalue>] is a shortcut for [field:myField<fieldvalue>].
See field Operator and field Operator (Examples).

This doesn’t explain why it doesn’t work for you in tw5.3.1 though.

Fred

1 Like

I suspect a lot of this is addressed in your other thread Only partially removing duplicates in list now.

My correction was wrong. My coding should have been:

[each[myField]get[myField]sort[]]

That is, using eeach instead of has. But this has a downside: it produces an empty value for the first tiddler not having the “myfield” field. So to keep the exact functionnality of the original code we should write:

[each[myField]has[myfield]get[myField]sort[]]

and this not any simpler and the intent is less clear. So it’s best to keep the original code.

@tw-FRed It didn’t work for me because I was not looking for the right result.

Your explanations was appreciated, thank you indeed! I’ve tested it and it works. hint: I was looking for a field value instead of a tiddler title! And as for my coding guess, it should have been (along my logic – your code equivalent is way better):

:select[get[myField]enlist-input[raw]match<fieldValue>]

or should it be the simpler code below? From my reading of the “field” operator doc, it should.

:select[get[myField]match<fieldValue>]

myField being a litteral, get[myField] it could be written as {!!myField}.

The conclusion: looking for the solution to my puzzling in the doc was a hard task. That’s given in the “filter step”, and not with emphasis. IMHO, it should be more apprent. And Perhaps we should have entries for common errors.

Many thank to all of you for your help.

One subtle difference between get[myField] and {!!myField}…

  • get[myField] will only produce output if myField exists and has a non-empty value
  • {!!myField} will always produce output, even if myField does not exist or exists but has no value

Thus, the equivalent usage would be get[myField] vs. {!!myField}!match[]

-e

1 Like

@EricShulman Thank you. I think that {!!myField}!is[blank] is also a strict equivalent, isn’t it?