I’m looking for a filter operator that, it seems, probably doesn’t exist.
You can think of it as the inverse of a contains
operator. contains
takes as input a list of items and has a parameter. If any one of the items matches the parameter, then contains
succeeds.
I want one that takes a single item a input (likely used in a :filter
call) and has a parameter that captures a list of values. It should succeed if that parameter matches any on of the items. Perhaps it might be called contained-in
or some such.
Does this operator exist?
Context:
I have a small wiki populated with voter information for my small town. The main point of it is to be able to collect email lists to plug into the “To” box of an email client. I have an <<email>>
macro that does this based upon a filter string supplied. For example, these are working queries:
- All Democrats:
<<email "[tag[Person]tag[Democratic]]">>
- Democratic Women:
<<email "[tag[Person]tag[Democratic]gender[Female]]">>
- Everyone 75 and Above:
<<email "[tag[Person]] :filter[get[age]compare:number:gteq[75]]">>
- Unaffiliated Women on Boston Hill:
<<email "[tag[Person]party[Unaffiliated]gender[Female]street[Boston Hill]]">>
They use this macro:
\define email(query)
<$let by-last ="[{!!last-name}] [{!!first-name}] +[join[, ]]">
<$vars txt="""<$list filter="$query$ :filter[has[email]] +[sortsub:string<by-last>]" counter="counter">{{!!title}} <$text text={{{ [[<]] [<currentTiddler>get[email]] [[>]] +[join[]] }}} /><$text text={{{ [<counter-last>!match[yes]then[, ]]}}} /></$list>""">
<$wikify name="cliptxt" output="formattedtext" text=<<txt>>>
<$macrocall $name="copy-to-clipboard" src={{{ [<cliptxt>trim[]] }}}/><br/>
<h4>Found: <$text text={{{ $query$ :filter[has[email]] +[count[]] }}} /></h4>
<$list filter="$query$ :filter[has[email]] +[sortsub:string<by-last>]" counter="counter">
<$link /> <<a href={{{ [[mailto:]] [<currentTiddler>get[title]] [[<]] [<currentTiddler>get[email]] [[>]] +[join[]] }}}><$text text={{{ [<currentTiddler>get[email]] }}} /></a>><$text text={{{ [<counter-last>!match[yes]then[, ]]}}} /><br/>
</$list>
</$wikify>
\end
It will yield something output like this:
Found: 3
Yogi Bear <yogi@jellystone.gov>,
Fred Flintstone <fred@bedrock.com>,
Scooby Doo <scoob@mysteryinc.org>,
where the copy-to-clipboard
link will put this in the system clipboard:
Yogi Bear <yogi@jellystone.gov>, Fred Flintstone <fred@bedrock.com>, Scooby Doo <scoob@mysteryinc.org>
.
The goal now is to make a query generator to customize such lists. I think I know how to do most of this, but I’m stuck at trying to offer the choice of multiple parties or multiple streets. I can do the former because party
will start my query, and this will work:
- Democrats and Unaffiliated Under 30:
<<email "[tag[Person]tag[Democratic]] [tag[Person]tag[Unaffiliated]] :filter[get[age]compare:number:lt[30]]">>
,
by starting with multiple filter expressions for the different (exclusive) tags. But the multiple streets will be a problem. If I had a filter operator like “contained-in”, then I might be able to write something like:
- All Women on Jurovaty, Townsend or Gilead:
<<email "[tag[Person]gender[Female] :filter[get[street]contained-in:Jurovaty,Townsend,Gilead[]]" >>
Am I missing an existing filter? Is this something I will have to write myself? If so, are there other filters with an indefinite number of parameters I could use for a model?
Or at a higher level, are there other suggestions for how to do this? I want users to be able to generate and save queries, but there are probably many ways to do this. Other suggestions?