Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 03-07-2024, 05:42 AM   #1
DrChiper
Bookish
DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.
 
DrChiper's Avatar
 
Posts: 907
Karma: 1803094
Join Date: Jun 2011
Device: PC, t1, t2, t3, aura 2 v1, clara HD, Libra 2, Nxtpaper 11
Question Template language questions

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?
DrChiper is offline   Reply With Quote
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,742
Karma: 6997045
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
Old 03-07-2024, 07:56 AM   #3
DrChiper
Bookish
DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.
 
DrChiper's Avatar
 
Posts: 907
Karma: 1803094
Join Date: Jun 2011
Device: PC, t1, t2, t3, aura 2 v1, clara HD, Libra 2, Nxtpaper 11
Thanks for this information, most enlightening

Quote:
Originally Posted by chaley View Post
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).
I had already some clue that string compare was used, but figured the 't' was used as a placeholder for 'true' (=yes). Oh well. However, I think it would be an user guide improvement to add there the above info. When you are in the know, you can figure out the 't', but is is not explicitly mentioned. Nor is the placeholder "#@#": it is shown, but not really explained.

Quote:
Originally Posted by chaley View Post
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.
It is definitely faster on my machine, that's why I wanted to grasp the difference so I could understand what was going on.

Last edited by DrChiper; 03-07-2024 at 08:11 AM.
DrChiper is offline   Reply With Quote
Old 03-07-2024, 08:15 AM   #4
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by DrChiper View Post
I had already some clue that string compare was used, but figured the 't' was used as a placeholder for 'true' (=yes). Oh well. However, I think it would be an user guide improvement to add there the above info. When you are in the know, you can figure out the 't', but is is not explicitly mentioned. Nor is the placeholder "#@#": it is shown, but not really explained.
In most cases template searches are built using the Advanced Search dialog, as the documentation suggests. That is what I do. The tooltips in that dialog explain much of what you can do.

You can use the "Copy the current search into the boxes" in that dialog to see what a search you found elsewhere, e.g., in a forum post, is doing. For example, here is what you see with for your 2nd template search.
Click image for larger version

Name:	Clipboard02.jpg
Views:	23
Size:	93.6 KB
ID:	206770

As for why it is faster, the 2nd template has a smaller, simpler program: it doesn't use an if/then/else. For smaller libraries or fewer data files, the time to execute the 'if' statement is a larger percentage of the total.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template language changes chaley Library Management 132 03-03-2024 06:34 PM
Template Language Question jvorzimmer Library Management 5 11-20-2021 01:26 PM
A few questions... (template language, mainly) Clem2605 Library Management 2 12-30-2020 03:25 AM
Template Language phossler Calibre 8 01-12-2016 04:37 PM
Help with template language Pepin33 Calibre 8 11-11-2012 08:32 AM


All times are GMT -4. The time now is 04:21 PM.


MobileRead.com is a privately owned, operated and funded community.