diff --git a/src/calibre/gui2/dialogs/config/create_custom_column.py b/src/calibre/gui2/dialogs/config/create_custom_column.py index fdf093b6d5..c0f17b8cba 100644 --- a/src/calibre/gui2/dialogs/config/create_custom_column.py +++ b/src/calibre/gui2/dialogs/config/create_custom_column.py @@ -105,6 +105,8 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): return self.simple_error('', _('No lookup name was provided')) if re.match('^\w*$', col) is None or not col[0].isalpha() or col.lower() != col: return self.simple_error('', _('The lookup name must contain only lower case letters, digits and underscores, and start with a letter')) + if col.endswith('_index'): + return self.simple_error('', _('Lookup names cannot end with _index, because these names are reserved for the index of a series column.')) col_heading = unicode(self.column_heading_box.text()) col_type = self.column_types[self.column_type_box.currentIndex()]['datatype'] if col_type == '*text': diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index ef74188bdf..ba4095fbc5 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -264,7 +264,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): # account for the series index column. Field_metadata knows that # the series index is one larger than the series. If you change # it here, be sure to change it there as well. - self.FIELD_MAP[str(col)+'_s_index'] = base = base+1 + self.FIELD_MAP[str(col)+'_index'] = base = base+1 + self.field_metadata.set_field_record_index( + self.custom_column_num_map[col]['label']+'_index', + base, + prefer_custom=True) self.FIELD_MAP['cover'] = base+1 self.field_metadata.set_field_record_index('cover', base+1, prefer_custom=False) diff --git a/src/calibre/library/field_metadata.py b/src/calibre/library/field_metadata.py index f29b432eec..2a79c3a75b 100644 --- a/src/calibre/library/field_metadata.py +++ b/src/calibre/library/field_metadata.py @@ -36,7 +36,7 @@ class FieldMetadata(dict): treated as a single term. If not None, it contains a string, and the field is assumed to contain a list of terms separated by that string - kind == standard: is a db field. + kind == field: is a db field. kind == category: standard tag category that isn't a field. see news. kind == user: user-defined tag category. kind == search: saved-searches category. @@ -239,7 +239,7 @@ class FieldMetadata(dict): 'is_multiple':None, 'kind':'field', 'name':None, - 'search_terms':[], + 'search_terms':['series_index'], 'is_custom':False, 'is_category':False}), ('sort', {'table':None, @@ -395,6 +395,18 @@ class FieldMetadata(dict): 'is_editable': is_editable,} self._add_search_terms_to_map(key, [key]) self.custom_label_to_key_map[label] = key + if datatype == 'series': + key += '_index' + self._tb_cats[key] = {'table':None, 'column':None, + 'datatype':'float', 'is_multiple':False, + 'kind':'field', 'name':'', + 'search_terms':[key], 'label':label+'_index', + 'colnum':None, 'display':{}, + 'is_custom':False, 'is_category':False, + 'link_column':None, 'category_sort':None, + 'is_editable': False,} + self._add_search_terms_to_map(key, [key]) + self.custom_label_to_key_map[label+'_index'] = key def remove_custom_fields(self): for key in self.get_custom_fields(): diff --git a/src/calibre/manual/gui.rst b/src/calibre/manual/gui.rst index 7ffc77575e..a2032f3071 100644 --- a/src/calibre/manual/gui.rst +++ b/src/calibre/manual/gui.rst @@ -212,9 +212,10 @@ metadata. You can build advanced search queries easily using the :guilabel:`Advanced Search Dialog`, accessed by clicking the button |sbi|. -Available fields for searching are: ``tag, title, author, publisher, series, rating, cover, comments, format, -isbn, date, pubdate, search, size`` and custom columns. If a device is plugged in, the ``ondevice`` field -becomes available. To find the search name for a custom column, hover your mouse over the column header. +Available fields for searching are: ``tag, title, author, publisher, series, series_index, rating, cover, +comments, format, isbn, date, pubdate, search, size`` and custom columns. If a device is plugged in, the +``ondevice`` field becomes available. To find the search name for a custom column, hover your mouse over the +column header. The syntax for searching for dates is:: @@ -223,9 +224,8 @@ The syntax for searching for dates is:: pubdate:=2009 Will find all books published in 2009 If the date is ambiguous, the current locale is used for date comparison. For example, in an mm/dd/yyyy -locale, 2/1/2009 is interpreted as 1 Feb 2009. In a dd/mm/yyyy locale, it is interpreted as 2 Jan 2009. - -Some special date strings are available. The string ``today`` translates to today's date, whatever it is. The +locale, 2/1/2009 is interpreted as 1 Feb 2009. In a dd/mm/yyyy locale, it is interpreted as 2 Jan 2009. Some +special date strings are available. The string ``today`` translates to today's date, whatever it is. The strings `yesterday`` and ``thismonth`` also work. In addition, the string ``daysago`` can be used to compare to a date some number of days ago, for example: date:>10daysago, date:<=45daysago. @@ -234,9 +234,15 @@ You can search for books that have a format of a certain size like this:: size:>1.1M Will find books with a format larger than 1.1MB size:<=1K Will find books with a format smaller than 1KB -Dates and numeric fields support the operators ``=`` (equals), ``>`` (greater than), ``>=`` (greater than or -equal to), ``<`` (less than), ``<=`` (less than or equal to), and ``!=`` (not equal to). Rating fields are -considered to be numeric. For example, the search ``rating:>=3`` will find all books rated 3 or higher. +Dates and numeric fields support the relational operators ``=`` (equals), ``>`` (greater than), ``>=`` +(greater than or equal to), ``<`` (less than), ``<=`` (less than or equal to), and ``!=`` (not equal to). +Rating fields are considered to be numeric. For example, the search ``rating:>=3`` will find all books rated 3 +or higher. + +Series indices are searchable. For the standard series, the search name is 'series_index'. For +custom series columns, use the column search name followed by _index. For example, to search the indices for a +custom series column named ``#my_series``, you would use the search name ``#my_series_index``. +Series indices are numbers, so you can use the relational operators described above. The special field ``search`` is used for saved searches. So if you save a search with the name "My spouse's books" you can enter ``search:"My spouse's books"`` in the search bar to reuse the saved