I'm missing something

I have downloaded @TW_Tones’ Custom Search as a Phrase JSON after struggling with a simple search tiddler. It works well for my TW.

So, this is just for my education.

I have two tiddlers look_in and look_for whose text fields contain the name of a field to search in and the text to search for.

So, my filter is

<$list filter="[!is[system][search:{{look_in}}[{{look_for}}]]" />

This returns no results.

If I replace {{look_in}} by ‘text’ and {{look_for}} by ‘catalogue’, the search works OK.

I have tried various combinations of { and < with no success.

So my (continuing) issue is substitution/transclusion in filters. How to insert field values or tiddler transclusions.

can someone teach me please.

bobj

Are these in the current tiddler?, use one brace and !! for a field

Try this;

[!is[system]search:{!!look_in}{!!look_for}]

Notice how additional [ ] are abandoned when

  • Following on from the last eg; before search
  • When you have another bract of some kinf eg { } but also < >

Remember filters are as or more powerful that most query languages, the way you combine them is critical, note how this filter run opens and closed with [ and ] only if you have more than one filter run will you see ][ or ] [

See Filter Expression and Filter Run, one you start to understand filter great powers become yours :nerd_face:

@TW_Tones, no these are not fields in the current tiddler, they are each separate tiddlers.

So does that change your code to include the text fields from each of the tiddlers?

Bobj

Unless Bob’s using an alternate implementation of the search operator (in which case I’d love the link!) filter operators don’t generally use transclusions in their extended syntax. From the documentation:

field list: a comma delimited list of field names

  • defaults to tags, text and title if blank

So we’d expect something like search:caption,modified,modifier{!!look_for} to work, but search:{!!look_in} won’t substitute a list from the “look_in” field.

  • Instead, since search:{!!look_in} isn’t a proper construction, the operator will treat the field list as blank and fall back on the default behavior—so it will search for the space-separated contents of the “look_in” field within tags,text,title.
  • However—you won’t actually see the results of this search, since the search is immediately followed by {!!look_for}. In the absence of any intervening operator to explain what to do with this transcluded content, the filter will simply replace all previous output with {!!look_for}, so we’d expect the final output to be equivalent to [{!!look_for}].

@Bob_Jansen, does this work for you?

\function field-list() [enlist{look_in}join[,]]
\define field-search() [!is[system]search:$(field-list)${look_for}]

<$list filter=<<field-search>> />

If so, you may want to look into macro placeholders, which are still, IIRC, the easiest way to dynamically construct a filter operator.

1 Like

@etardiff,

thanks for your contribution. I’m sorry I cant try out your example right now as I’ve had to focus on something money earning rather than intellectually challenging. Bills and all that…

bobj

I have come across a very informative book, The Book of TiddlyWiki. This sets out quite clearly what brackets should be used when. It also lays out in a simple fashion, filters and macros.

I am not sure if it refers to TWClassic or TW5 but I assume many of the concepts carry across.

I can not recommend it highly enough. The style is simple and explicit. It assumes you know nothing about TW and leads you sequentially through the various concepts. This makes it easier to read than the TW documentation which is really aimed at knowledgeable coders as a reminder of how to do something. The TW highly interlinked style makes it more difficult for a novice to follow.

1 Like

I think your problem is/was the filter syntax and the transclusion in filters. The doc is heavy if you don’t know how is the filter syntax and its parts, and how you can find it in the doc. I don’t have backgroud about how tw classic works. If your problem is the filter syntax maybe can help if you understand how with filter step(s) you can create a filter run(s) and then you create the final filter expression. It is important how are joined the steps to build your filter run/expression.