View Single Post
Old 03-07-2024, 07:31 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,772
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by DrChiper View Post
Due to some noticed template magic in this thread , I have a question to understand some detail. I tried to locate this in the calibre user manual, but was lost.

I have a query for finding books with extra files which works well:
Code:
template:"""program: if has_extra_files() then 'yes' else 'no' fi#@#:t:yes"""
In the above mentioned thread, I saw another template query for the same:
Code:
template:"""program: has_extra_files()#@#:b:yes"""
In my first example a "t" is used, while the 2nd uses a "b". I do understand that "b" is meant for "boolean", but what is the meaning of the "t"? And when using "b" instead of "t" in my first query template it does not work. Why?
The 't' means 'text compare'. The first template returns either the string 'yes' or the string 'no'. The text test in the template search checks for the value 'yes'. For completeness, the other search types are 'b' (boolean, set/not set), 'n' (numeric), and 'd' (date).

As for 'b', the General Program Mode documentation says:
  • In a logical context, any non-empty value is True
  • In a logical context, the empty value is False
The 'b' test (boolean, or set/not set) is a logical context.

You can't use 'b' in the first template because both 'yes' and 'no' are non-empty thus True. The check always succeeds.

The second template returns the value of has_extra_files(), which is either the string '1' or the empty string. As said above, the empty string is False in the logical context so the 'b' test works.

FWIW: the second template is somewhat faster. Not much because the performance difference is swamped by the time required to check the library for data files.
chaley is offline   Reply With Quote