Deduplicating Lists from Filters

Hi, all —

I have a wiki where many of the tiddlers have a phone number field (stored as ten digits, no spaces). Most often, there’s a single value in the field. But some tiddlers have two or three values in [[1234567890]] [[0987654321]] format. I’m using <$list filter...> to pull the values, then using <$wikify> to render the resulting list as a variable, which I can pass to an inner filter — with the aim of removing duplicate entries via enlist.

This is what my effort looks like:

<ol>
<$list filter=<<filter>> variable="phone_history_numbers">
	<$wikify text=<<phone_history_numbers>> name="phone_history_numbers_wikified">
  	<$list filter="[enlist<phone_history_numbers_wikified>]">
    	<li>{{!!title}}</li>
    </$list>
  </$wikify>
</$list>
</ol>

Except — I still have duplicates in the resulting list. :confused:

Am I using the enlist operator incorrectly?

Shouldn’t I also be able to accomplish my aim with something like <$list filter="[<phone_history_numbers_wikified>unique[]]? Because that doesn’t seem to work for me, either.

I think I’m missing something that’s staring me in the face … .

One (possibly) relevant detail: The reason I wikified <<phone_history_numbers>> was to turn the list of, say:

  1. 1234567890
  2. [[2345678901]] [[3456789012]]
  3. [[2345678901]] [[4567890123]]
  4. 2345678901

… into a list more like:

  1. 1234567890
  2. 2345678901
  3. 3456789012
  4. 2345678901
  5. 4567890123
  6. 2345678901

… which, of course, I’d like to ultimately look like this:

  1. 1234567890
  2. 2345678901
  3. 3456789012
  4. 4567890123

You can only do the deduplication within a filter run, and typically when you have access to all the things to deduplicate, however the each[] operator can be used for fields, commonly each[fieldname]get[fieldname]

  • Can you do it in your <<filter>>?

I can give more help later

Hmm. The <<filter>> is:

[tag[CN80s]!tag[reports]!has[draft.of]] +[get[phone_history]]

… where I’m getting my first list from the phone_history field of all the tiddlers that match [tag[CN80s]!tag[reports]!has[draft.of]].

I wonder if my use of get is complicating things more than I realize.

But, heck, I may be fundamentally misunderstanding the <$filter> widget, as I’d think my use of [enlist[]] is within the filter run. :thinking:

If you have any insights to share at your leisure, @TW_Tones, they’ll be appreciated. I’ll likely have to step away for a bit and may not make it back tonight (which might be a good thing!).

Try this:
[tag[CN80s]!tag[reports]!has[draft.of]] +[get[phone_history]enlist-input[]unique[]]

It worked for me on a basic example…

Fred

2 Likes

The enlist operator also has a dedupe suffix to eliminate duplicates.
You don’t need to use the square brackets if the phone numbers contain no spaces.
You can eliminate the outer list and $wikify by using a $let like so:

<$let phone_history_numbers={{{ [subfilter<filter>join[ ]] }}}>
<$list filter="[enlist:dedupe<phone_history_numbers>]">
...

The join[ ] (with space) will collect all numbers into a single space-separated list that then gets enlisted and deduped.

1 Like

Thank you Fred I’ve been ruminating for a week on how to take lists of words within a field keywords and show them in a de-duplicated list so I could have a list of all the keywords I’ve used and this worked beautifully. No telling how many times I searched enlist on tiddlywiki.com and just looked right over enlist-input.

1 Like