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-11-2024, 10:52 AM   #1
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
Search for books with author notes and show one book per author

EDIT: See this post for an updated & generalized version of the following template search.

@Comfy.n asked me if there was a template search that for each author with a note would show one book by that author. It didn't matter which book. Here is that search.

Showing one book per author might not be possible if the author is a coauthor on several books. For example, consider these books where All of A, B, and C have notes:
  • Title 1, authors A & B
  • Title 2, authors C & B
Title 1 and Title 2 will both appear in the search results because there is no other way to show the authors A and C. This means that two books by author B will appear.

The search template gives priority to books with single authors. Extending the above example:
  • Title 1, authors A & B
  • Title 2, authors C & B
  • Title 3, author B
  • Title 4, author C
results in
  • Title 1 (only book with author A)
  • Title 3 (author B is sole author)
  • Title 4 (author C is sole author)
Title 3 is shown even though B is a coauthor of Title 1.

The template can easily be changed to check any field, for example series, tags, or some custom column.

The search respects virtual libraries.

Use the Advanced search / Template search to create the search.
Template value field: yes
Comparison type: Set/Not set
Template:
Spoiler:
Code:
python:
def evaluate(book, context):
	# Set this field to the lookup name of the desired field.
	field_name = 'authors'

	db = context.db.new_api
	# Check if we have already computed the necessary data
	book_ids = context.globals.get('book_ids', None)
	if book_ids is None:
		book_notes = {}
		all_notes = db.get_all_items_that_have_notes(field_name)
		for book_id in db.search(query=''): # restrict the search to the current VL
			item_values = db.field_for(field_name, book_id)
			if item_values is None:
				continue
			if isinstance(item_values, str):
				item_values = (item_values,)
			for item_val in item_values:
				item_id = db.get_item_id(field_name, item_val)
				if item_id in all_notes:
					if item_val not in book_notes or book_notes[item_val]['count'] > len(item_values):
						book_notes[item_val] = {'count': len(item_values), 'book_id': book_id}
		context.globals['book_ids'] = frozenset(bn['book_id'] for bn in book_notes.values())

	# Check if the current book is to be displayed
	book_ids = context.globals['book_ids']
	return '1' if book.id in book_ids else ''

Here is an image of the filled-in Advanced search dialog.
Attached Thumbnails
Click image for larger version

Name:	Clipboard01.jpg
Views:	62
Size:	71.8 KB
ID:	206858  

Last edited by chaley; 03-13-2024 at 04:55 PM. Reason: Improve template performance
chaley is offline   Reply With Quote
Old 03-11-2024, 11:34 AM   #2
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,002
Karma: 6422750
Join Date: Sep 2020
Device: Calibre E-book viewer
Thanks so much, chaley! One of the reasons for this odd search is that it makes it easier to preview distinct author notes in the Book Details pane, which I have on the right side of the UI.

Now I'm thinking I could use a trimmed Comments custom column to be displayed above the Bio. So I would need one more tip: what template should I use to display a trimmed comments field above the author bio in BD, displaying only the first 300 characters from the Comments built in column?

I gather from this thread that I could use something like:

{comments:shorten(300,...,0)}

Is that correct and also, would a PTM template be more suitable performace-wise?
Comfy.n is offline   Reply With Quote
Advert
Old 03-11-2024, 11:40 AM   #3
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 Comfy.n View Post
Thanks so much, chaley! One of the reasons for this odd search is that it makes it easier to preview distinct author notes in the Book Details pane, which I have on the right side of the UI.

Now I'm thinking I could use a trimmed Comments custom column to be displayed above the Bio. So I would need one more tip: what template should I use to display a trimmed comments field above the author bio in BD, displaying only the first 300 characters from the Comments built in column?

I gather from this thread that I could use something like:

{comments:shorten(300,...,0)}
Is that correct?
That works fine. You could also do it in GPM using
Code:
program: shorten($comments, 300, '...', 0)
I don't think that the performance of the two will be significantly different, especially if the shortened column is displayed only in book details.
Quote:

Would a PTM template be more suitable performace-wise?
Performance isn't an issue if the column is displayed only in book details. And in any event, for something this simple I don't think the difference between any of the modes will be significant.
chaley is offline   Reply With Quote
Old 03-11-2024, 12:04 PM   #4
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,002
Karma: 6422750
Join Date: Sep 2020
Device: Calibre E-book viewer
That works smoothly.

I'm using the GPM one, and after creating the column with the option "Show as HTML in BD" unchecked, it would display the text with the blue clickable option to "Search all books with..." Then I left "show as html.." checked and it displayed as plain text, like I wanted.
Comfy.n is offline   Reply With Quote
Old 03-11-2024, 06:03 PM   #5
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,002
Karma: 6422750
Join Date: Sep 2020
Device: Calibre E-book viewer
Quote:
Originally Posted by chaley View Post
@Comfy.n asked me if there was a template search that for each author with a note would show one book by that author. It didn't matter which book. Here is that search.
It takes a while to refresh the view if changing metadata while the query is active (whilst it's visible on the search bar, I mean), so I'm tagging temporarily the results as 'temp', then only changing metadata on the results after doing a new search for tag:temp.
Comfy.n is offline   Reply With Quote
Advert
Old 03-11-2024, 06:12 PM   #6
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 Comfy.n View Post
It takes a while to refresh the view...
That doesn't surprise me. The search looks at every book on the library to build an index of authors with notes, which requires multiple probes of the notes database. It is a very expensive compute- and disk-bound process.

Using a temporary tag is a good workaround.
chaley is offline   Reply With Quote
Old 03-11-2024, 06:32 PM   #7
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,002
Karma: 6422750
Join Date: Sep 2020
Device: Calibre E-book viewer
This is off-topic, but I think you may know something about this issue.

In 2022, I was able to somewhat style the scrollbar for the Dark Theme. It was not perfect at all, but provided good visibility for the handle. Nowadays I'm used to do just keyboard commands like 'home' in cover grid view, and just forget the scrollbar. Also, that only worked with the system default UI style.

With the recent addition of a more refined color customisation dialog, I've tried today two things:

1) try more combinations of colors in the dark theme for the currently customisable UI elements, but that didn't work well

2) I've tried runnning from source again and adding that code Kovid suggested in 2022, but the change wouldn't take. (that was args = sys.argv[:1] args += ['-stylesheet', 'test1.qss'])

Some Qt based programs have a different scrollbar style in dark theme, where the handle has more like a light gray tone and the rest is black, so I wonder if that could somehow be tweaked in Calibre, with the recent Qt update.

Last edited by Comfy.n; 03-11-2024 at 07:02 PM.
Comfy.n is offline   Reply With Quote
Old 03-11-2024, 06:34 PM   #8
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
Sorry, but I have no idea.
chaley is offline   Reply With Quote
Old 03-12-2024, 08:35 PM   #9
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,002
Karma: 6422750
Join Date: Sep 2020
Device: Calibre E-book viewer
Hi again,

Today I missed a way to restrict a search with the second part of this request. For example, a search for
Code:
tags:biography listing_restriction:one book per author.
Another one would be:
Code:
 languages:eng formats:epub listing_restriction:one book per author.
Can that second part be written as a separate query, so one could run it, say, on a VL?
Comfy.n is offline   Reply With Quote
Old 03-13-2024, 12:39 AM   #10
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 Comfy.n View Post
Hi again,

Today I missed a way to restrict a search with the second part of this request. For example, a search for
Code:
tags:biography listing_restriction:one book per author.
Another one would be:
Code:
 languages:eng formats:epub listing_restriction:one book per author.
Can that second part be written as a separate query, so one could run it, say, on a VL?
I don't understand. What does
Code:
listing_restriction:one book per author
mean?

The template search already respects the current VL. If you want it to respect some VL when no VL is currently applied, put that VL's search into the expression. For example, assuming the VL search expression is a saved search named "vl_search":
Code:
search:vl_search and tags:foo and search:one_book_per_author
Hmmmm ... it might be that the template search skips books because it selects a book outside the current VL to be displayed, then rejects it later when it isn't in the VL. Is this the problem you are describing?
chaley is offline   Reply With Quote
Old 03-13-2024, 12:47 AM   #11
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,002
Karma: 6422750
Join Date: Sep 2020
Device: Calibre E-book viewer
The original request included filtering titles with author notes.

I can't use that to restrict a search for titles in my library that contain the tag:biography but don't contain author notes.

I'm running the Extract People Metadata plugin on my libraries, which requires a lot of tweaking to get translators, original titles etc. and restricting any search to only one book per author would make it easier to spot the troublesome books for extracting that info...

edit to add:

As I see my original question, this is what it meant:

a + b

being

a = has author notes
b = restrict results to only one title per author

And it does exactly that, however it does it in a way that B depends on A (or would it be A depending on B to list the results? I can't tell)

Now, in my mind, if B could be run "independently", then I could do b + c, b + d, b + e etc. c, d and e being any other search. Maybe not possible, I suspect.

Last edited by Comfy.n; 03-13-2024 at 01:22 AM.
Comfy.n is offline   Reply With Quote
Old 03-13-2024, 05:44 AM   #12
Katja_hbg
Groupie
Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.Katja_hbg can grok the meaning of the universe.
 
Posts: 167
Karma: 158116
Join Date: Oct 2015
Device: Kobo Glo HD (landscape), Kobo Aura One
Forme it sounds that you are looking for

b = restrict results to only one title per author (without any further filter)
and in addition - optional i.e. can be switched on/off:
a = has author notes (which is in fact a subset of "b")
Katja_hbg is offline   Reply With Quote
Old 03-13-2024, 05:45 AM   #13
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
I think you are asking that the template pay no attention to notes. Instead it takes a set of books and reduces that set to one book per author.

If true, then this pseudo search would do the same as the original template:
Code:
search:has_author_notes and search:one_book_per_author
You could also do things like
Code:
not tag:foobar and search:one_book_per_author
producing a list of one book per author where the books don't have the foobar tag.

Do I have this right?
chaley is offline   Reply With Quote
Old 03-13-2024, 06:17 AM   #14
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
Try this to see if I understand you correctly.
  1. Create a VL using the search you want. A temporary VL (current search) works.
  2. Run this template in the template search
    Spoiler:
    Code:
    python:
    def evaluate(book, context):
    	# Set this field to the lookup name of the desired field.
    	field_name = 'authors'
    
    	db = context.db.new_api
    	# Check if we have already computed the necessary data
    	book_ids = context.globals.get('book_ids', None)
    	if book_ids is None:
    		books = {}
    		# all_notes = db.get_all_items_that_have_notes(field_name)
    		for book_id in db.search(query=''): # restrict the search to the current VL
    			item_values = db.field_for(field_name, book_id)
    			if item_values is None:
    				continue
    			if isinstance(item_values, str):
    				item_values = (item_values,)
    			for item_val in item_values:
    				item_id = db.get_item_id(field_name, item_val)
    				if item_val not in books or books[item_val]['count'] > len(item_values):
    					books[item_val] = {'count': len(item_values), 'book_id': book_id}
    		context.globals['book_ids'] = frozenset(bn['book_id'] for bn in books.values())
    
    	# Check if the current book is to be displayed
    	book_ids = context.globals['book_ids']
    	return '1' if book.id in book_ids else ''
It should produce a list of one book per author where the books are limited to those in the VL.

If this is what you want then I will look at ways to eliminate the temporary VL.
chaley is offline   Reply With Quote
Old 03-13-2024, 12:24 PM   #15
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,002
Karma: 6422750
Join Date: Sep 2020
Device: Calibre E-book viewer
Quote:
Originally Posted by Katja_hbg View Post
Forme it sounds that you are looking for

b = restrict results to only one title per author (without any further filter)
and in addition - optional i.e. can be switched on/off:
a = has author notes (which is in fact a subset of "b")
yes, and this reminds me that occasionally I might want to run just B on a whole library...
Comfy.n is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Books sent to Amazon show with my email as ther author Robmonster Calibre 9 11-05-2020 01:17 PM
Show Books from Only 1 Author RiffRaffAK Library Management 2 06-04-2020 10:26 AM
Expanded search option for "Show books by the same author as the current book" ALT+A Sisela Library Management 1 11-28-2015 09:54 AM
author search in book details panel mobic Library Management 3 11-26-2015 10:50 AM
To show author and author sort as same? pinky62 Library Management 5 03-18-2014 12:55 PM


All times are GMT -4. The time now is 03:55 PM.


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