View Single Post
Old 03-13-2024, 04:51 PM   #21
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: 12,495
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Comfy.n View Post
Yes, that works perfectly! Also, surprisingly fast.

Running from source, I've just tested

template:"""program: get_one_book_per_field_value('authors')#@#:b:yes"" " tag:fantasy

template:"""program: get_one_book_per_field_value('authors')#@#:b:yes"" " tag:biography f:ep

Both return only one title per author.

Running from source, it would be significantly faster to have the get_one_book ... as the last expression in the search. Reason: the change I made to base calibre is to pass to the template the set of books matching the previous expressions, allowing the get_one_book... analysis to operate on only those books.

In addition, in some cases it is possible for the get_one_book ... to select a book for an author that won't match the rest of the search expression. Were this to happen, the answer would be missing that author. For example, imagine that Joe Blogs has two titles, A and B. Title A is tagged "Historical Fiction". Title B is tagged "Science Fiction". The get_one_book ... algorithm could pick either book as the "one title". If you combine it with a tags:... clause then the tag might match the other book, resulting in neither book being found. This won't happen if get_one_book ... is the last expression in the search and you are using the latest source.
Quote:
edit to add: it works also on latest preview version, by the way!
Yes, with a) significantly worse performance because it operates in the entire library and b) increased probability of selecting a "one title" that isn't matched by the rest of the search.
chaley is offline   Reply With Quote