View Single Post
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: 12,449
Karma: 8012886
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