{count:ids:delimiter}

Description

Counts the parts of a delimiter-separated string - typically a list of item IDs. It splits ids on the delimiter and returns how many non-empty parts remain, as a string. Counting an ID list this way is much faster than aggregate count, because it never reads the items from the database; feed it the output of the ids command and it simply counts. Empty input returns 0. Parts that are empty or whitespace-only are skipped, so a doubled delimiter does not inflate the total. The delimiter defaults to a single dash and is not trimmed, so it may itself contain spaces.

Parameters

ids optional

The list to count, written as parts joined by the delimiter. Usually item IDs in dash-separated form (the output of the ids command), but any delimited string works. Empty or whitespace-only input returns 0.

delimiter optional default - (a single dash)

The separator between parts. May be any string, including one that contains spaces (this parameter is not trimmed). Only non-empty parts are counted.

Examples

test{count:abc123-def456-ghi789}
Expected3
Actual3
Counts the number of dash-separated IDs in the string. Returns 3 for this 3-element list.
test{count:{ids:9e1d2b9f88e3d6c3bf0eb967378610d6}}
Expected10
Actual10
Counts how many active items exist in the AA Test Data - Stable slice. The ids command returns their IDs and count counts them. The Stable slice is frozen, so this stays 10.
test{count:}
Expected0
Actual0
Returns 0 when the input is empty - safe to use on fields that may have no IDs.
test{count:apple, pear, plum:, }
Expected3
Actual3
Counts parts split on a custom delimiter - here a comma followed by a space. The delimiter is not trimmed, so the space is part of it. Returns 3.
virtual{count:{ids:SLICE_ID:d-category........-=-{_#CATEGORY}}}
Expected(count of related items)
Actual0
Real-world pattern: count items in another slice that share the current item's category, to show a number like N related articles. Replace SLICE_ID with your slice. Illustrative - the number depends on your data.
test{count:a--b-c}
Expected3
Actual3
Empty parts are not counted, so a doubled delimiter does not inflate the total. The four split parts are a, (empty), b, c - the empty one is dropped, giving 3. A part whose only content is the digit 0 is also dropped.