Today, 04:31 AM | #1021 | |
want to learn what I want
Posts: 1,121
Karma: 6426808
Join Date: Sep 2020
Device: Calibre E-book viewer
|
Quote:
Currently the way I see to do it is using the Notes Browser with its FTS-like search syntax, like this: In that example I've searched for authors born in 9/11. Default shortcut is Ctrl + Shift + N. However I can't tell how to bring all results from that search into "main Calibre", so that I could bulk add the "Born in 9/11" tag, for instance. |
|
Today, 06:49 AM | #1022 | |
Grand Sorcerer
Posts: 11,921
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
You can search a note using a template like this one, suitably modified. Code:
program: first_author = sublist($authors, 0, 1, '&'); note = get_note('authors', first_author, '1'); if 'something' in note then ans = 'Yes' else ans = 'No' fi; ans
Depending on what you want to do, there are two ways to proceed.
Last edited by chaley; Today at 07:25 AM. |
|
Today, 07:16 AM | #1023 | |
want to learn what I want
Posts: 1,121
Karma: 6426808
Join Date: Sep 2020
Device: Calibre E-book viewer
|
Quote:
I get "EXCEPTION: string indices must be integers, not 'str'" in the Template Editor. I'm trying with: Comparison type - Text, and pasting the code in field Template, while leaving the field Template Value empty. |
|
Today, 07:24 AM | #1024 | |
Grand Sorcerer
Posts: 11,921
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
get_note('authors', first_author, '') |
|
Today, 07:54 AM | #1025 | |
Grand Sorcerer
Posts: 11,921
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
get_note('authors', first_author, 1) |
|
Today, 08:29 AM | #1026 |
want to learn what I want
Posts: 1,121
Karma: 6426808
Join Date: Sep 2020
Device: Calibre E-book viewer
|
It works in the template editor, showing "Yes" for a given value when a book whose author's notes contain the string is currently selected.
However when I paste the template in the search bar, it returns no results, so I must be doing something the wrong way Last edited by Comfy.n; Today at 08:32 AM. |
Today, 08:42 AM | #1027 | |
Grand Sorcerer
Posts: 11,921
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Template: Code:
program: first_author = sublist($authors, 0, 1, '&'); note = get_note('authors', first_author, '1'); if 'a' in note then ans = 'Yes' else ans = '' fi; ans Note that the template search generated by the dialog contains more than just the template. Last edited by chaley; Today at 08:44 AM. |
|
Today, 09:45 AM | #1028 | |
want to learn what I want
Posts: 1,121
Karma: 6426808
Join Date: Sep 2020
Device: Calibre E-book viewer
|
Quote:
Now I'm trying to fix my advanced search issue, hopefully I can come up later with more detailed info. I think my notes database has grown too much lately, and when I do the search as indicated in your screenshot for Advanced Search, Calibre enters some seemingly infinite database lookup. This has happened other times and I solved it by recreating my Bio column. (deleting it, then re-adding). Today this didn't seem to solve the issue. Process Monitor shows this: |
|
Today, 05:53 PM | #1029 | |
Grand Sorcerer
Posts: 11,921
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
This python template is optimized for the search problem. When it is first called (the first book) it gets all the note values and caches them using more optimized API calls. Then for each subsequent book it checks the cache, not the database. It would be best done as a stored template so the field and value could be passed as arguments. I didn't bother to do that because I don't know if this solves your problem. The template: Code:
python: def evaluate(book, context): # Set these to what you want field_name = 'authors' search_value = 'aaa' db = context.db.new_api # check if we have already cached the notes note_items = context.globals.get('items_with_notes', None) if note_items is not None: # We have. Get the cached note values note_values = context.globals['note_values'] else: # We haven't. Cache the note item ids and their values # First get all the item ids with notes and cache the result note_items = db.get_all_items_that_have_notes(field_name) context.globals['items_with_notes'] = note_items # Now get the note values for each item id with a note note_values = {} for note_item in note_items: note = db.notes_data_for(field_name, note_item) if note: # Get the plain text of the note note = note['searchable_text'].partition('\n')[2] # Put the value of the note into the cache. note_values[note_item] = note # Write the cached values to the globals context.globals['note_values'] = note_values # Check if this book is a match -- the field has a note containing the right text # get the item_id for the value of the desired field fv = book.get(field_name) # if the field is multi-valued, use the first value if isinstance(fv, list): fv = fv[0] # Now get the internal ID of the value in field_name item_id = db.get_item_id(field_name, fv) # Return the empty string if the item doesn't have a note if item_id not in note_items: return '' # Get the note value from the cache val = note_values.get(item_id, None) if val is None: # This shouldn't happen, but ... return '' # use a case insensitive compare to check if the search value is in the note from calibre.utils.icu import primary_contains return 'Yes' if primary_contains(search_value, val) else '' |
|
Today, 07:34 PM | #1030 | |
want to learn what I want
Posts: 1,121
Karma: 6426808
Join Date: Sep 2020
Device: Calibre E-book viewer
|
Quote:
Thanks for taking your time to try and help! I had thought of asking for a stored template like "item_has_notes", but I think this is not the case at the moment. |
|
Tags |
custom column, tag, tags |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
custom column i need a little help | shinken | Calibre | 3 | 09-15-2010 03:41 AM |
Using Custom Metadata in Save Template | EJvdH | Calibre | 1 | 07-02-2010 06:06 AM |
Accessories Decalgirl Kindle 2 custom skin template | srmalloy | Amazon Kindle | 6 | 04-09-2010 09:55 PM |
Donations for Custom Recipes | ddavtian | Calibre | 5 | 01-23-2010 04:54 PM |
Help understanding custom recipes | andersent | Calibre | 0 | 12-17-2009 02:37 PM |