mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Add 'is_csp' (is colon separated pair) attribute to field_metadata. Make get_categories and searching use it.
This commit is contained in:
parent
82af1ac792
commit
ffbab9ab52
@ -455,6 +455,7 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
valq_mkind, valq = self._matchkind(query)
|
||||
|
||||
loc = self.field_metadata[location]['rec_index']
|
||||
split_char = self.field_metadata[location]['is_multiple']
|
||||
for id_ in candidates:
|
||||
item = self._data[id_]
|
||||
if item is None:
|
||||
@ -465,7 +466,7 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
matches.add(id_)
|
||||
continue
|
||||
|
||||
pairs = [p.strip() for p in item[loc].split(',')]
|
||||
pairs = [p.strip() for p in item[loc].split(split_char)]
|
||||
for pair in pairs:
|
||||
parts = pair.split(':')
|
||||
if len(parts) != 2:
|
||||
@ -569,9 +570,10 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
return self.get_numeric_matches(location, query[1:],
|
||||
candidates, val_func=vf)
|
||||
|
||||
# special case: identifiers. isbn is a special case within the case
|
||||
if location == 'identifiers':
|
||||
if original_location == 'isbn':
|
||||
# special case: colon-separated fields such as identifiers. isbn
|
||||
# is a special case within the case
|
||||
if fm['is_csp']:
|
||||
if location == 'identifiers' and original_location == 'isbn':
|
||||
return self.get_keypair_matches('identifiers',
|
||||
'=isbn:'+query, candidates)
|
||||
return self.get_keypair_matches(location, query, candidates)
|
||||
|
@ -1273,7 +1273,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
for category in tb_cats.keys():
|
||||
cat = tb_cats[category]
|
||||
if not cat['is_category'] or cat['kind'] in ['user', 'search'] \
|
||||
or category in ['news', 'formats', 'identifiers']:
|
||||
or category in ['news', 'formats'] or cat['is_csp']:
|
||||
continue
|
||||
# Get the ids for the item values
|
||||
if not cat['is_custom']:
|
||||
|
@ -80,6 +80,8 @@ class FieldMetadata(dict):
|
||||
|
||||
rec_index: the index of the field in the db metadata record.
|
||||
|
||||
is_csp: field contains colon-separated pairs. Must also be text, is_multiple
|
||||
|
||||
'''
|
||||
|
||||
VALID_DATA_TYPES = frozenset([None, 'rating', 'text', 'comments', 'datetime',
|
||||
@ -98,7 +100,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Authors'),
|
||||
'search_terms':['authors', 'author'],
|
||||
'is_custom':False,
|
||||
'is_category':True}),
|
||||
'is_category':True,
|
||||
'is_csp': False}),
|
||||
('series', {'table':'series',
|
||||
'column':'name',
|
||||
'link_column':'series',
|
||||
@ -109,7 +112,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Series'),
|
||||
'search_terms':['series'],
|
||||
'is_custom':False,
|
||||
'is_category':True}),
|
||||
'is_category':True,
|
||||
'is_csp': False}),
|
||||
('formats', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -118,7 +122,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Formats'),
|
||||
'search_terms':['formats', 'format'],
|
||||
'is_custom':False,
|
||||
'is_category':True}),
|
||||
'is_category':True,
|
||||
'is_csp': False}),
|
||||
('publisher', {'table':'publishers',
|
||||
'column':'name',
|
||||
'link_column':'publisher',
|
||||
@ -129,7 +134,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Publishers'),
|
||||
'search_terms':['publisher'],
|
||||
'is_custom':False,
|
||||
'is_category':True}),
|
||||
'is_category':True,
|
||||
'is_csp': False}),
|
||||
('rating', {'table':'ratings',
|
||||
'column':'rating',
|
||||
'link_column':'rating',
|
||||
@ -140,7 +146,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Ratings'),
|
||||
'search_terms':['rating'],
|
||||
'is_custom':False,
|
||||
'is_category':True}),
|
||||
'is_category':True,
|
||||
'is_csp': False}),
|
||||
('news', {'table':'news',
|
||||
'column':'name',
|
||||
'category_sort':'name',
|
||||
@ -150,7 +157,8 @@ class FieldMetadata(dict):
|
||||
'name':_('News'),
|
||||
'search_terms':[],
|
||||
'is_custom':False,
|
||||
'is_category':True}),
|
||||
'is_category':True,
|
||||
'is_csp': False}),
|
||||
('tags', {'table':'tags',
|
||||
'column':'name',
|
||||
'link_column': 'tag',
|
||||
@ -161,7 +169,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Tags'),
|
||||
'search_terms':['tags', 'tag'],
|
||||
'is_custom':False,
|
||||
'is_category':True}),
|
||||
'is_category':True,
|
||||
'is_csp': False}),
|
||||
('identifiers', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -170,7 +179,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Identifiers'),
|
||||
'search_terms':['identifiers', 'identifier', 'isbn'],
|
||||
'is_custom':False,
|
||||
'is_category':True}),
|
||||
'is_category':True,
|
||||
'is_csp': True}),
|
||||
('author_sort',{'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -179,7 +189,8 @@ class FieldMetadata(dict):
|
||||
'name':None,
|
||||
'search_terms':['author_sort'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('au_map', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -188,7 +199,8 @@ class FieldMetadata(dict):
|
||||
'name':None,
|
||||
'search_terms':[],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('comments', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -196,7 +208,9 @@ class FieldMetadata(dict):
|
||||
'kind':'field',
|
||||
'name':_('Comments'),
|
||||
'search_terms':['comments', 'comment'],
|
||||
'is_custom':False, 'is_category':False}),
|
||||
'is_custom':False,
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('cover', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'int',
|
||||
@ -205,7 +219,8 @@ class FieldMetadata(dict):
|
||||
'name':None,
|
||||
'search_terms':['cover'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('id', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'int',
|
||||
@ -214,7 +229,8 @@ class FieldMetadata(dict):
|
||||
'name':None,
|
||||
'search_terms':[],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('last_modified', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'datetime',
|
||||
@ -223,7 +239,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Date'),
|
||||
'search_terms':['last_modified'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('ondevice', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -232,7 +249,8 @@ class FieldMetadata(dict):
|
||||
'name':_('On Device'),
|
||||
'search_terms':['ondevice'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('path', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -241,7 +259,8 @@ class FieldMetadata(dict):
|
||||
'name':None,
|
||||
'search_terms':[],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('pubdate', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'datetime',
|
||||
@ -250,7 +269,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Published'),
|
||||
'search_terms':['pubdate'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('series_index',{'table':None,
|
||||
'column':None,
|
||||
'datatype':'float',
|
||||
@ -259,7 +279,8 @@ class FieldMetadata(dict):
|
||||
'name':None,
|
||||
'search_terms':['series_index'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('sort', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -268,7 +289,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Title Sort'),
|
||||
'search_terms':['title_sort'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('size', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'float',
|
||||
@ -277,7 +299,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Size (MB)'),
|
||||
'search_terms':['size'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('timestamp', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'datetime',
|
||||
@ -286,7 +309,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Date'),
|
||||
'search_terms':['date'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('title', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -295,7 +319,8 @@ class FieldMetadata(dict):
|
||||
'name':_('Title'),
|
||||
'search_terms':['title'],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
('uuid', {'table':None,
|
||||
'column':None,
|
||||
'datatype':'text',
|
||||
@ -304,7 +329,8 @@ class FieldMetadata(dict):
|
||||
'name':None,
|
||||
'search_terms':[],
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
'is_category':False,
|
||||
'is_csp': False}),
|
||||
]
|
||||
# }}}
|
||||
|
||||
@ -433,7 +459,7 @@ class FieldMetadata(dict):
|
||||
return l
|
||||
|
||||
def add_custom_field(self, label, table, column, datatype, colnum, name,
|
||||
display, is_editable, is_multiple, is_category):
|
||||
display, is_editable, is_multiple, is_category, is_csp):
|
||||
key = self.custom_field_prefix + label
|
||||
if key in self._tb_cats:
|
||||
raise ValueError('Duplicate custom field [%s]'%(label))
|
||||
@ -446,7 +472,7 @@ class FieldMetadata(dict):
|
||||
'colnum':colnum, 'display':display,
|
||||
'is_custom':True, 'is_category':is_category,
|
||||
'link_column':'value','category_sort':'value',
|
||||
'is_editable': is_editable,}
|
||||
'is_csp' : is_csp, 'is_editable': is_editable,}
|
||||
self._add_search_terms_to_map(key, [key])
|
||||
self.custom_label_to_key_map[label] = key
|
||||
if datatype == 'series':
|
||||
@ -458,7 +484,7 @@ class FieldMetadata(dict):
|
||||
'colnum':None, 'display':{},
|
||||
'is_custom':False, 'is_category':False,
|
||||
'link_column':None, 'category_sort':None,
|
||||
'is_editable': False,}
|
||||
'is_editable': False, 'is_csp': False}
|
||||
self._add_search_terms_to_map(key, [key])
|
||||
self.custom_label_to_key_map[label+'_index'] = key
|
||||
|
||||
@ -507,7 +533,7 @@ class FieldMetadata(dict):
|
||||
'datatype':None, 'is_multiple':None,
|
||||
'kind':'user', 'name':name,
|
||||
'search_terms':st, 'is_custom':False,
|
||||
'is_category':True}
|
||||
'is_category':True, 'is_csp': False}
|
||||
self._add_search_terms_to_map(label, st)
|
||||
|
||||
def add_search_category(self, label, name):
|
||||
@ -517,7 +543,7 @@ class FieldMetadata(dict):
|
||||
'datatype':None, 'is_multiple':None,
|
||||
'kind':'search', 'name':name,
|
||||
'search_terms':[], 'is_custom':False,
|
||||
'is_category':True}
|
||||
'is_category':True, 'is_csp': False}
|
||||
|
||||
def set_field_record_index(self, label, index, prefer_custom=False):
|
||||
if prefer_custom:
|
||||
|
Loading…
x
Reference in New Issue
Block a user