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-13-2024, 12:27 PM   #16
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
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?
Exactly. I haven't used the 'and' connector in my posts because that's how I always do the searches, given they behave the same when 'and' is omitted
Comfy.n is online now   Reply With Quote
Old 03-13-2024, 12:32 PM   #17
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
Try this to see if I understand you correctly.
Should I use the same settings as with the previous one, I mean

Template value field: yes
Comparison type: Set/Not set

I've tried that way and it's running indefinitely on a small VL
Comfy.n is online now   Reply With Quote
Advert
Old 03-13-2024, 01:16 PM   #18
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
By the way, I find Calibre search amazing. It can even understand parentheses syntax, as in:

l:en (f:ep or f:az or f:mob) tag:non

where l is my short search alias for languages, f is for formats.

ep is my 'epub' lazy form
Comfy.n is online now   Reply With Quote
Old 03-13-2024, 02:37 PM   #19
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 may have confused things, but lets put that aside.

I have an implementation that doesn't require the temporary VL but respects the current VL. It is a bit more complicated because I wanted to generalize it to any field, not just authors. To use what I describe below you must be running calibre 7.7 or later.

To use it, make a stored template named whatever you want -- I use "get_one_book_per_field_value". The template itself is:
Spoiler:
Code:
python:
def evaluate(book, context):
	field_name = context.arguments[0] if len(context.arguments) == 1 else None
	if field_name is None:
		raise NameError("The argument 'field' wasn't provided")

	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:
		candidates = context.globals.get('_candidates', db.all_book_ids())
		books = {}
		for book_id in db.search(query=''): # restrict the search to the current VL
			if book_id not in candidates:
				continue
			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:
				if item_val not in books or books[item_val]['count'] > len(item_values):
					books.pop(item_val, None)
					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 ''
This template takes one argument, the field (column) you are interested in (authors).

Next, make this template search:
Code:
template:"""program: get_one_book_per_field_value('authors')#@#:b:yes"""
It calls the above stored template with the argument "authors". I recommend you create a saved search with it. I did and named it "one_book_per_author". You now have @Katja_hbg's B.

You also need @Katja_hbg's A. To get it, put this in a stored template named what you want. I named it "item_has_notes". The template is
Spoiler:
Code:
python:
def evaluate(book, context):
	field_name = context.arguments[0] if len(context.arguments) == 1 else None
	if field_name is None:
		raise NameError("The argument for the field name wasn't provided")

	db = context.db.new_api
	items_with_notes = context.globals.get('items_with_notes')
	if items_with_notes is None:
		items_with_notes = db.get_all_items_that_have_notes(field_name)
		context.globals['items_with_notes'] = items_with_notes
		context.globals['item_name_map'] = db.get_item_name_map(field_name)
	item_name_map = context.globals['item_name_map']

	vals = book.get(field_name)
	if vals is None:
		return ''
	if isinstance(vals, str):
		vals = tuple((vals,))
	for val in vals:
		if item_name_map.get(val) in items_with_notes:
			return '1'
	return ''

This template also takes 1 argument, the field (column) name.

Now make another template search
Code:
template:"""program: item_has_notes('authors')#@#:b:yes"""
This calles the stored template with the field name "authors". Again, I recommend you save it as a search. I did that, naming it "author has notes".

You can now do searches like:
  • search:author has notes and search:one_book_per_author
  • formats:epub and tags:foobar and search:one_book_per_author
  • search:one_book_per_author

All of this works for me. I hope it works for you.

Last edited by chaley; 03-15-2024 at 07:52 PM. Reason: disabled smilies in text
chaley is offline   Reply With Quote
Old 03-13-2024, 02:53 PM   #20
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

All of this works for me. I hope it works for you.
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.



edit to add: it works also on latest preview version, by the way!

Last edited by Comfy.n; 03-13-2024 at 03:11 PM.
Comfy.n is online now   Reply With Quote
Advert
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: 11,742
Karma: 6997045
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
Old 03-14-2024, 07:09 AM   #22
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
The calibre change mentioned above is in release 7.7, released today.
chaley is offline   Reply With Quote
Old 03-15-2024, 08:01 PM   #23
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
Inspired by this question, today I decided to use publisher instead of authors:

Code:
template:"""program: get_one_book_per_field_value('publisher')#@#:b:yes"""
This suggested me an interesting possibility, as I have the Goodreads Metadata plugin: to sort a library by most voted titles, getting only one book by publisher...

In my mind, what followed was: what if I could display only like 5 or 10 titles per publisher? Then I would be able to see filtered in a library a list of the top voted books by publisher!

Last edited by Comfy.n; 03-15-2024 at 08:39 PM.
Comfy.n is online now   Reply With Quote
Old 03-16-2024, 09:15 AM   #24
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
Inspired by this question, today I decided to use publisher instead of authors:

Code:
template:"""program: get_one_book_per_field_value('publisher')#@#:b:yes"""
This suggested me an interesting possibility, as I have the Goodreads Metadata plugin: to sort a library by most voted titles, getting only one book by publisher...

In my mind, what followed was: what if I could display only like 5 or 10 titles per publisher? Then I would be able to see filtered in a library a list of the top voted books by publisher!
This has become a game of whack-a-Mole. The number of variants one can make on this theme is unbounded. Why not show 2 books per series where the author has the letter 'Q' in the name and it doesn't have the tag "mumble"? Or two publishers filtered in reverse alphabetical order when the books have ratings > 4? Or the last 3 books by date from an author with notes?

Other templates I have already written are further variants. Example, show the last book in a series and show the first book in a series.

At first blush I don't want to go here. However, I do have an idea that might work and be of general use -- iterate through the displayed books (the current book list) in order, showing N books per field. To use it, one would search for the books of interest and make a temp VL of that search. Then sort the booklist in the order you want the filtering. Then run the filter. This could do all of the above, but does take some thought and planning to make work. I need to think about this.
chaley is offline   Reply With Quote
Old 03-16-2024, 10:33 AM   #25
Wiggo
Leftutti
Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.
 
Wiggo's Avatar
 
Posts: 400
Karma: 1121267
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
Unfortunately, the one in post #19 does not work for me.
Both templates already show the same error (Calibre 7.7)

Click image for larger version

Name:	calibre_YWF2XJBBqZ.jpg
Views:	30
Size:	266.6 KB
ID:	206929

But my feeling tells me that the problem is in front of the computer.
Wiggo is offline   Reply With Quote
Old 03-16-2024, 11:14 AM   #26
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 Wiggo View Post
Unfortunately, the one in post #19 does not work for me.
Both templates already show the same error (Calibre 7.7)

But my feeling tells me that the problem is in front of the computer.
Those stored templates won't work in the template tester because they require an argument, the column name. That is why I supplied the template searches, which provide the needed argument to the stored templates.

You can also test the stored templates using the "Test" button in the Stored template dialog, but it isn't much of a test as it looks at only the currently selected books. For example, it you press the Test button and enter
Code:
get_one_book_per_field_value('authors')
you will see a 1 or an empty string for each book.
chaley is offline   Reply With Quote
Old 03-16-2024, 01:42 PM   #27
Wiggo
Leftutti
Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.
 
Wiggo's Avatar
 
Posts: 400
Karma: 1121267
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
I have already tried that template searches

Click image for larger version

Name:	calibre_GXaoXR0k2Q.jpg
Views:	38
Size:	66.3 KB
ID:	206931
Click image for larger version

Name:	xHbUnPOevo.jpg
Views:	28
Size:	67.2 KB
ID:	206932

The same happens with
Code:
template:"""program: get_one_book_per_field_value('authors')#@#:b:yes"""

Last edited by Wiggo; 03-16-2024 at 01:51 PM.
Wiggo is offline   Reply With Quote
Old 03-16-2024, 01:52 PM   #28
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 Wiggo View Post
Unfortunately, the one in post #19 does not work for me.
Both templates already show the same error (Calibre 7.7)
Hi! The stored templates looked the same here, in the template tester. I just ignored that message. I've attached my Action Chains menu items for these searches, but they will only work if the stored templates are already present with the same names @chaley suggested: item_has_notes or get_one_book_per_field_value
Attached Files
File Type: zip Chains - one per author and has notes.zip (41.9 KB, 28 views)

Last edited by Comfy.n; 03-16-2024 at 02:23 PM.
Comfy.n is online now   Reply With Quote
Old 03-16-2024, 01:54 PM   #29
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 Wiggo View Post
I have already tried that template searches

Attachment 206931
Attachment 206932
I assume you are saying they didn't work. What did they do?

Here are my stored templates. They show up in the stored templates dialog, like this:
Click image for larger version

Name:	Clipboard01.jpg
Views:	23
Size:	159.3 KB
ID:	206933

This is my saved search, using the stored template:
Click image for larger version

Name:	Clipboard02.jpg
Views:	42
Size:	57.4 KB
ID:	206934

The names must be spelled exactly the same in the stored templates and the saved searches.
chaley is offline   Reply With Quote
Old 03-16-2024, 02:01 PM   #30
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! The stored templates looked the same here, in the template tester. I just ignored that message. I've attached my Action Chains menu items for these searches, but they will only work if the stored templates are already present with the same names @chaley suggested: item_has_notes or get_one_book_per_field_value
@Comfy.n: in your chain "One + Has Bio" you should put the "item_has_notes" search term before the "get_one_book_per_field_value" search term. The way you have it the search can miss results for the reasons explained in post 21.
chaley 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 05:16 AM.


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