Query multiple fields

My use case is a music player for ripped CDs (mostly classical music). The music (FLAC files) is not stored in my wiki but resides in a files folder. The tiddlers for the movements/tracks (a separate tiddler for each movement/track) contain only metadata, which lets me search the music using a dozen different search fields. But besides playing music, after a while I also felt the need to interrogate the metadata, for which I needed a (general use-case independent) way to query multiple fields. My implementation is as follows:

\define getField(field)
{{{ [<currentTiddler>get[$field$]else[-]] }}}
\end

\define addSeparator(isLast)
{{{ $isLast$ +[match[no]search-replace[no],[,]] }}}
\end

\procedure query()
<$list filter={{!!_query-from}}>
  <$list filter=[{Query!!_query-fields}split[,]trim[]] variable="field" counter="i">
    <<getField $(field)$>><<addSeparator $(i-last)$>>
  </$list><br>
</$list>
\end

from:
<$edit-text tag=textarea class="query-from" autoHeight="no" field="_query-from"/>
fields:
<$edit-text tag=textarea class="query-fields" autoHeight="no" field="_query-fields"/>

<div class="query-result">
<<query>>
</div>

(CSS not shown).

Two textareas are used, one for the from clause and another one for the fields to be queried. The clauses are stored in the _query-from and _query-fields fields respectively

The from clause must be a filter that returns tiddler titles. The fields clause must be a comma separated list of field names. There is no limitation on the number of fields that can be queried. White space can be used freely. To make this clearer an example is shown.

So far my queries have been very helpful, not in the least to help me find errors and omissions in the metadata.

May, I hope, or may not be useful.

2 Likes

If desired, navigation to the parent tiddlers is possible by adding the title field to the list of fields.

Thanks for sharing you approach with the community @Jan

You maybe able to simplify it further with some functions that can be used to simplify the query.

In the updated version below when no fields are specified, the procedure returns whatever the filter in the from field returns, as a link if it can be linked to (i.e., <<currentTiddler>> is not always the title of a tiddler, but can e.g. also be number (e.g. count[])). (It then is similar to Advanced Search - Filter.)

\procedure select()
<$list filter={{!!_select-from}} emptyMessage="∅">
  <$list filter=[{Select!!_select-fields}!is[blank]split[,]] variable="field" counter="i" emptyMessage="""<$link/>""">
    <<getField $(field)$>><<addSeparator $(i-last)$>>
  </$list><br>
</$list>
\end