Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre Companion

Notices

Reply
 
Thread Tools Search this Thread
Old 08-10-2014, 11:54 PM   #1
kaufman
Calibre Companion Fanatic
kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.
 
kaufman's Avatar
 
Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
New Custom Column definition for new sort

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.
kaufman is offline   Reply With Quote
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
Advert
Old 08-11-2014, 02: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
@kaufman: as eschwartz said, nice.

I assume that you are using the new custom column in a user-defined sort (Authors, #yourCol). You could do it all in the custom column, freeing a user-defined sort and also giving you the possibility to invert the sort. Using eschwartz's modification, the template would be:
Code:
program:

strcat(
	field('author_sort'),
	':::',
	ifempty(
		strcat(
			field('series'),
			finish_formatting(
				field('series_index'),
				"5.2f",
				" (",
				")"
			)
		),
		field('title')
	)
)
Also, you might want to use the series_sort() function instead of field('series'). Depends on whether you want to sort on "The Lost Fleet" or "Lost Fleet, The".

Last edited by chaley; 08-11-2014 at 03:49 AM. Reason: fix template to use author_sort instead of authors and to mention series_sort()
chaley is offline   Reply With Quote
Old 08-11-2014, 11:58 AM   #4
kaufman
Calibre Companion Fanatic
kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.
 
kaufman's Avatar
 
Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
Thank you both for the suggestions.

Quote:
Originally Posted by chaley View Post
I assume that you are using the new custom column in a user-defined sort (Authors, #yourCol). You could do it all in the custom column, freeing a user-defined sort and also giving you the possibility to invert the sort.
I'm actually not using the user-defined sorts at all. Partially for the inversion but mostly because i just didn't need it. The custom column already contained all the information I needed.

I have used both your suggestions and updated my definition to:

Code:
program:

strcat(
    field('author_sort'),
    " - ",
	ifempty(
		strcat(
			series_sort(),
			finish_formatting(
				field('series_index'),
				"5.2f",
				" (",
				")"
			)
		),
		field('title')
	)
)
Which is simpler, as well as using the various sorted versions of the columns. I originally didn't include the author at the beginning because I currently only use this for a single author, but I added it in to make the solution more general.


Off topic, but I wonder why its a field for author_sort but a function for series_sort.

Thanks again to both of you for the improvements.
kaufman is offline   Reply With Quote
Old 08-11-2014, 12:59 PM   #5
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 kaufman View Post
Off topic, but I wonder why its a field for author_sort but a function for series_sort.
It is because their isn't a series sort field in the database. The value is computed whenever it is needed. That is also why it cannot be edited in calibre's edit metadata dialogs.
chaley is offline   Reply With Quote
Advert
Old 08-11-2014, 10:16 PM   #6
kaufman
Calibre Companion Fanatic
kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.
 
kaufman's Avatar
 
Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
That's interesting. I wonder why that is. If the program can figure out how to do the series sort, why can't it figure out the other ones?
kaufman is offline   Reply With Quote
Old 08-11-2014, 11:03 PM   #7
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
That's interesting. I wonder why that is. If the program can figure out how to do the series sort, why can't it figure out the other ones?
It can but it doesn't.

The gory details are something like this: many fields can have different sort values. Especially when things get hairy with different languages. Also, some authors have odd names that don't follow the usual rules -- possibly they have multiple last names or whatever foreign concept I don't care about -- so you have the ability to manually override those sort values. However the default value will be the one calibre automatically computes (or the manually specified one in the metadata, which calibre never overwrites).

Why is series_sort different, would be a better question. I am not sure, except maybe it is assumed there will be no need for anyone to ever manually edit the series_sort? I cannot say I have heard of an example where it is necessary...
eschwartz is offline   Reply With Quote
Old 08-12-2014, 01:18 AM   #8
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 eschwartz View Post
Why is series_sort different, would be a better question. I am not sure, except maybe it is assumed there will be no need for anyone to ever manually edit the series_sort? I cannot say I have heard of an example where it is necessary...
Purely historical. From time to time we get enhancement requests to add it as a first-class field, but no developer cares enough about it to do the considerable amount of work required.
chaley is offline   Reply With Quote
Old 08-13-2014, 10:54 AM   #9
kaufman
Calibre Companion Fanatic
kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.
 
kaufman's Avatar
 
Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
Quote:
Originally Posted by kaufman View Post
I originally didn't include the author at the beginning because I currently only use this for a single author, but I added it in to make the solution more general.
And now I have taken it out again.

My sorting was being messed up because I had an author who had 15 solo books and 1 book with another author. That 1 book was coming up at the top (because of the second author's name) rather than in the middle of the series that it is part of.
kaufman is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Manual Sort or Sort by custom column Dethmaul Marvin 2 04-28-2014 11:54 AM
Custom column returns value based on value of another custom column? calvin-c Calibre 3 09-14-2013 02:24 PM
Custom yes/no column built from long text column Philantrop Library Management 7 03-23-2013 07:44 PM
how to move value(s) of tag column to a custom made column zoorakhan Library Management 0 12-08-2012 03:53 AM
Is it possible to sort a custom column like authors or title? arspr Library Management 2 03-15-2011 04:44 PM


All times are GMT -4. The time now is 01:25 AM.


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