Tinderbox Forum

Unable to restrict agent to a path

I’m using the following query

inside(/“Eventos”) & $Text.contains(“Carlão” )| $Name.contains(“Carlão”)

but the agent gather all the notes in the document with the word Carlão. I just want the notes inside events.

What I’m missing?

OK, this is likely because your query is being interpreted this pseudo-logic:

inside(/"Eventos") & $Text.contains("Carlão")
OR
$Name.contains("Carlão")

Which could be written in normal query form as:.

(inside(/"Eventos") & $Text.contains("Carlão")) | $Name.contains("Carlão")

Now if we transpose those two ‘OR’ parts:

$Name.contains("Carlão") | (inside(/"Eventos") & $Text.contains("Carlão"))

It is clearly why the inside() filter is not working as expected. It probably also doesn’t help that you’ve put the path quotes wrongly in the inside() operator. You want "/Eventos" and not /"Eventos".

So, you want to find Carlão in either the $Text or $Name of notes but only if the notes are inside() a root level container ‘Eventos’. If so, try this:

inside("/Eventos") & ($Name.contains("Carlão") | $Text.contains("Carlão"))

Now, parsing from left to right, Tinderbox first finds notes ‘in’ ‘Eventos’ before checking only those notes for whether their $Text or $Name case-sensitively contains the sub-string ‘Carlão’.

Sorry for the long post, but it seems useful for the long term to explain why such a simple change in the query should have such noticeable results.

1 Like

Mark

After reading your post it becomes obvious! I must confess that it’s difficult for me to learn how to write long queries.

Thanks a lot!

Roberto

Apart from for people with a coding background, I’m not sure they are initially easy for most people. :open_mouth: But, at some point in the process, what we think we meant has to be turned into unambiguous true/false statements the program can understand.

A few points to remember:

  • Any query is interpreted by the program by reading it from left to right.
  • An AND join, i.e. &, will always reduce (or equal) the existing number of matches from the previous part of the query.
  • An OR join, i.e. |, will always increase (or equal) the existing number of matches from the previous part of the query.
  • Use parentheses ( and ), as above to indicate to the program anything that needs to deviate from left/right order. The way the parentheses work is similar to a equations in a spreadsheet (e.g. Excel, Numbers, etc.).
1 Like

:+1:

I´ll die trying!

1 Like

Long queries are a sign that you might be making life too hard for yourself.

First: if you have a long query and it’s not doing what you expect, start with some small part of the query — something so small that it couldn’t possibly be wrong! Try it. Check that the results are correct, or at any rate plausible.

Then, add some more complexity. Check again! Eventually, you’ll find the problem.

Also: it might be easier to split your complicated agent into several parts. For example, if you have a query like

$DueDate<date("today") & $Text.contains("important") | $Text.contains("urgent") } .....

Consider breaking this up into two agents: one that finds overdue notes and the other that finds important notes and urgent notes and other emergencies.

Then, your long query becomes short!

inside(/agents/Overdue) & inside(/agents/Important)

1 Like

OK! It’s an easier path.