View Single Post
Old 08-11-2014, 01:05 AM   #2
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by kaufman View Post
This might belong in the Calibre section, but I created it for CC based on ideas that others here gave me, and I am posting it here in case anyone else wants it for the same reason.

This started because people were talking about sorting by Author and then Series and then Title, but this was giving me sorts where the books without series were coming first and then all of the series. What I actually wanted was to have the titles and series mixed together alphabetically. So I created a column called Authors Works that gave the title of the book if the book wasn't part of a series and a series (index) if it was part of a series.

The template is:

program:
first_non_empty(
test(field('series'),
strcat(field('series'), " (", field('series_index'), ")"),
""),
field('title')
)


I then added a custom grouping and now Author autosorts the way I want it to.
Code:
program:

first_non_empty(
	test(
		field('series'),
		strcat(
			field('series'),
			" (",
			field('series_index'),
			")"
		),
		""
	),
	field('title')
)
Nice.

I thought you might like to know, though, that you can use formatting here too, with finish_formatting() to apply prefix/suffix. The advantage here is that you can shape the series_index as demonstrated here to always return say, "07.50" for sorting purposes.

It is also slightly more readable by condensing first_non_empty(test(stuff)) into ifempty(). Possible performance boost (minuscule) by not evaluating field('series') twice.

(I am told you are a glutton for punishment, so you have to listen to me ramble about obscure template bits. )

Code:
program:

ifempty(
	strcat(
		field('series'),
		finish_formatting(
			field('series_index'),
			"5.2f",
			" (",
			")"
		)
	),
	field('title')
)

Last edited by eschwartz; 08-11-2014 at 01:10 AM.
eschwartz is offline   Reply With Quote