View Single Post
Old 09-12-2024, 06:49 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: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Montana Harper View Post
I realize this is probably a really niche thing, but is there any way to search a notes field (e.g., notes attached to an author) for specific text? I want to build a custom column that shows me a check mark if particular text is included in an author note.

I have a number of custom columns built from other columns that do something similar, but since the notes aren't fields with lookup names, I'm not even sure if it's possible to do what I want. Currently I'm using a workaround that involves adding a specific tag to every book by an author whom I want to flag, but that's both time-consuming and easy to forget about when adding a new book, whereas if I can just make a single note for the author it would be so much easier.

TIA!
You can do this with the template function get_note().

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
Notes on the template:
  • This uses the first author. You must decide what to do if there are multiple authors. For example, you might want to loop over all the authors checking if any have a note.
  • The first argument of the 'in' operator is a regular expression. Keep that in mind when deciding on what search you want to do.
  • Using the 'ans' variable isn't really necessary. You can instead use the return value of the 'if'. I use the variable to avoid problems if/when code is added after the if, just to be sure I am getting the return value I want.
  • IMPORTANT: While testing this I found a bug in the get_note() function. The 'plain_text' option doesn't work. I have submitted a fix to Kovid. I will post here when the fix is in calibre source. In the meantime use HTML instead of plain text (the third parameter to get_note() is ''). It will be significantly slower but it should work as long as what you are looking for doesn't resemble an HTML tag too closely.

Depending on what you want to do, there are two ways to proceed.
  1. You just want a column with a checkmark
    • Create a composite column using the above template, with "show checkmarks" True.
  2. You want a column icon
    • Create an advanced rule using the template, but return the image name instead of 'Yes' or 'No'
    or
    • Create a composite column using the above template Use this column in a column icon rule looking for the value 'Yes'. You might want to hide this column in the booklist and book details.
  3. You want both. Do the composite column in option 1 then use that column in the second choice for the column icon in option 2.

Last edited by chaley; 09-12-2024 at 07:25 AM.
chaley is offline   Reply With Quote