Tinderbox Forum

Agent to find notes with particular words

I want to create an agent that finds notes that have the word “transcript” in the $Name. How do I do that?

And, if wanted notes that had “transcript” in the either the $Name or $Text or both?

I know this is basic but the answer will unlock a whole lot of other things that I might like to do.



An agent that finds notes that have the word “transcript” in the $Name

Query: $Name.contains("transcript")

An agent that finds notes that had “transcript” in the either the $Name or $Text

Query: $Name.contains("transcript") | Text.contains("transcript")

Further to the above, if you want the comparison to be case-insensitive, use .icontains() instead of .contains(). So:


will match “transcript”, “Transcript”, as well as “tranSCript” or any other case combination for that word.

See more: for .contains() and .icontains().

Thank you all for the valuable information.
it was possible to organize search in any TBX-file

  1. by creating attribute findName in agent and writing query in agent:
  1. By creating a rule in the prototype for all notes:

[I’ve added formatting to the last post to make it easier to read to code (using Admin’s access)]

Although Text.icontains... works for legacy support reasons the correct syntax here is $Text.icontains....

Your #2 does nothing except add load to the rule processing. The code evaluates a query as true or false. But in a rule that outcome is pointless as you aren’t doing anything with the output. Instead, you are running 3 computationally expensive query terms in every note button no effect. I would suggest removing that rule.

Also, though findAgent is a valid attribute name, if re-using this code I’d suggest using FindAgent as being more consistent with Tinderbox attribute naming convention (N.B. attributes are case-sensitive). Why? because it is easy for most typists to make case errors and they are easier to spot for things like attributes if one uses a consistent naming method. When I see $findAgent I immediately think is that a typo or a deliberate name!

1 Like

It really worked, and when you delete the rules under point 2
But for some reason I do not react to the case of letters in the command icontains
I’ll take your comment about naming attributes into account in the future

What is the string (exact case please) that you can’t match, and in what attribute?

If the target attribute is $Name don’t forget that on screen, in the view, you are seeing $DisplayName not $Name and the two strings may differ from $Name if you are using a Display Expression. So, you might be trying to match characters that aren’t actually in $Name but only in $DisplayName.

it turns out that this is not the case:
If the notes or names are in English, everything works, but if it’s not in Latin, it doesn’t work!

That sounds odd. Words in Latin should not be an issue:

$Text.icontains("gaius julius caesar")

Will still match “Gaius Julius Ceasar”.

So, an example of text (in $Name, $Text or $FullName) that you think doesn’t work would help us to help you. :slight_smile:

Now try this:
Γάιος Ιούλιος Καίσαρας
γάιος ιούλιος καίσαρας
and it won’t work

Ah, you meant a non-Roman text. :slight_smile: That possibility occurred just after I’d posted. I can confirm your problem with the (I’m using OS 10.14.6 in case that is pertinent, and my locale is ‘en-gb’).

Checking further, I can use the capitalised version of the text with .lowercase' and get the lowercase example string. I can do the reverse with the lower-case example and .uppercasebut not.capitalize`.

Well, this is a workaround for now. For me, with a note holding one of the two examples in the $Text of two different notes, this agent matches both notes:

$Text.lowercase.icontains("γάιος ιούλιος καίσαρας")

Note that this query doesn’t affect the source $text, but instead tests an all-lowercase version of the source.

Here’s my test file: Greek-test.tbx (87.9 KB)

It may work as a stop-gap. I’ve only tested the examples given but the file should allow you to test a bit more.

This will be addressed in Tinderbox 9; .contains and .icontains don’t have all the Unicode support one could wish.

1 Like