mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make tags sorted in the meta2 table.
This commit is contained in:
parent
01665ef514
commit
2662ab485f
@ -526,7 +526,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
def tags(r, idx=-1):
|
def tags(r, idx=-1):
|
||||||
tags = self.db.data[r][idx]
|
tags = self.db.data[r][idx]
|
||||||
if tags:
|
if tags:
|
||||||
return QVariant(', '.join(sorted(tags.split(','), key=sort_key)))
|
return QVariant(', '.join(tags.split(',')))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def series_type(r, idx=-1, siix=-1):
|
def series_type(r, idx=-1, siix=-1):
|
||||||
@ -577,7 +577,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
def text_type(r, mult=False, idx=-1):
|
def text_type(r, mult=False, idx=-1):
|
||||||
text = self.db.data[r][idx]
|
text = self.db.data[r][idx]
|
||||||
if text and mult:
|
if text and mult:
|
||||||
return QVariant(', '.join(sorted(text.split('|'),key=sort_key)))
|
return QVariant(', '.join(text.split('|')))
|
||||||
return QVariant(text)
|
return QVariant(text)
|
||||||
|
|
||||||
def number_type(r, idx=-1):
|
def number_type(r, idx=-1):
|
||||||
|
@ -14,6 +14,7 @@ from calibre.constants import preferred_encoding
|
|||||||
from calibre.library.field_metadata import FieldMetadata
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
from calibre.utils.date import parse_date
|
from calibre.utils.date import parse_date
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
|
from calibre.utils.icu import sort_key
|
||||||
|
|
||||||
class CustomColumns(object):
|
class CustomColumns(object):
|
||||||
|
|
||||||
@ -181,8 +182,8 @@ class CustomColumns(object):
|
|||||||
ans = row[self.FIELD_MAP[data['num']]]
|
ans = row[self.FIELD_MAP[data['num']]]
|
||||||
if data['is_multiple'] and data['datatype'] == 'text':
|
if data['is_multiple'] and data['datatype'] == 'text':
|
||||||
ans = ans.split('|') if ans else []
|
ans = ans.split('|') if ans else []
|
||||||
if data['display'].get('sort_alpha', False):
|
if data['display'].get('sort_alpha', True):
|
||||||
ans.sort(cmp=lambda x,y:cmp(x.lower(), y.lower()))
|
ans.sort(key=sort_key)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def get_custom_extra(self, idx, label=None, num=None, index_is_id=False):
|
def get_custom_extra(self, idx, label=None, num=None, index_is_id=False):
|
||||||
@ -534,8 +535,8 @@ class CustomColumns(object):
|
|||||||
if data['normalized']:
|
if data['normalized']:
|
||||||
query = '%s.value'
|
query = '%s.value'
|
||||||
if data['is_multiple']:
|
if data['is_multiple']:
|
||||||
query = 'group_concat(%s.value, "|")'
|
query = 'cc_sortconcat(%s.value)'
|
||||||
if not display.get('sort_alpha', False):
|
if not display.get('sort_alpha', True):
|
||||||
query = 'sort_concat(link.id, %s.value)'
|
query = 'sort_concat(link.id, %s.value)'
|
||||||
line = '''(SELECT {query} FROM {lt} AS link INNER JOIN
|
line = '''(SELECT {query} FROM {lt} AS link INNER JOIN
|
||||||
{table} ON(link.value={table}.id) WHERE link.book=books.id)
|
{table} ON(link.value={table}.id) WHERE link.book=books.id)
|
||||||
|
@ -242,7 +242,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
'timestamp',
|
'timestamp',
|
||||||
'(SELECT MAX(uncompressed_size) FROM data WHERE book=books.id) size',
|
'(SELECT MAX(uncompressed_size) FROM data WHERE book=books.id) size',
|
||||||
('rating', 'ratings', 'rating', 'ratings.rating'),
|
('rating', 'ratings', 'rating', 'ratings.rating'),
|
||||||
('tags', 'tags', 'tag', 'group_concat(name)'),
|
('tags', 'tags', 'tag', 'tags_sortconcat(name)'),
|
||||||
'(SELECT text FROM comments WHERE book=books.id) comments',
|
'(SELECT text FROM comments WHERE book=books.id) comments',
|
||||||
('series', 'series', 'series', 'name'),
|
('series', 'series', 'series', 'name'),
|
||||||
('publisher', 'publishers', 'publisher', 'name'),
|
('publisher', 'publishers', 'publisher', 'name'),
|
||||||
|
@ -19,7 +19,7 @@ from calibre.ebooks.metadata import title_sort, author_to_author_sort
|
|||||||
from calibre.utils.date import parse_date, isoformat
|
from calibre.utils.date import parse_date, isoformat
|
||||||
from calibre import isbytestring, force_unicode
|
from calibre import isbytestring, force_unicode
|
||||||
from calibre.constants import iswindows, DEBUG
|
from calibre.constants import iswindows, DEBUG
|
||||||
from calibre.utils.icu import strcmp
|
from calibre.utils.icu import strcmp, sort_key
|
||||||
|
|
||||||
global_lock = RLock()
|
global_lock = RLock()
|
||||||
|
|
||||||
@ -69,6 +69,25 @@ class Concatenate(object):
|
|||||||
return None
|
return None
|
||||||
return self.sep.join(self.ans)
|
return self.sep.join(self.ans)
|
||||||
|
|
||||||
|
class TagsSortConcatenate(object):
|
||||||
|
'''Sorted string concatenation aggregator for sqlite'''
|
||||||
|
def __init__(self, sep=','):
|
||||||
|
self.sep = sep
|
||||||
|
self.ans = []
|
||||||
|
|
||||||
|
def step(self, value):
|
||||||
|
if value is not None:
|
||||||
|
self.ans.append(value)
|
||||||
|
|
||||||
|
def finalize(self):
|
||||||
|
if not self.ans:
|
||||||
|
return None
|
||||||
|
return self.sep.join(sorted(self.ans, key=sort_key))
|
||||||
|
|
||||||
|
class CcSortConcatenate(TagsSortConcatenate):
|
||||||
|
def __init__(self):
|
||||||
|
TagsSortConcatenate.__init__(self, sep='|')
|
||||||
|
|
||||||
class SortedConcatenate(object):
|
class SortedConcatenate(object):
|
||||||
'''String concatenation aggregator for sqlite, sorted by supplied index'''
|
'''String concatenation aggregator for sqlite, sorted by supplied index'''
|
||||||
sep = ','
|
sep = ','
|
||||||
@ -155,6 +174,8 @@ class DBThread(Thread):
|
|||||||
c_ext_loaded = load_c_extensions(self.conn)
|
c_ext_loaded = load_c_extensions(self.conn)
|
||||||
self.conn.row_factory = sqlite.Row if self.row_factory else lambda cursor, row : list(row)
|
self.conn.row_factory = sqlite.Row if self.row_factory else lambda cursor, row : list(row)
|
||||||
self.conn.create_aggregate('concat', 1, Concatenate)
|
self.conn.create_aggregate('concat', 1, Concatenate)
|
||||||
|
self.conn.create_aggregate('tags_sortconcat', 1, TagsSortConcatenate)
|
||||||
|
self.conn.create_aggregate('cc_sortconcat', 1, CcSortConcatenate)
|
||||||
if not c_ext_loaded:
|
if not c_ext_loaded:
|
||||||
self.conn.create_aggregate('sortconcat', 2, SortedConcatenate)
|
self.conn.create_aggregate('sortconcat', 2, SortedConcatenate)
|
||||||
self.conn.create_aggregate('sort_concat', 2, SafeSortedConcatenate)
|
self.conn.create_aggregate('sort_concat', 2, SafeSortedConcatenate)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user