Port calibredb search

This commit is contained in:
Kovid Goyal 2017-05-02 14:04:29 +05:30
parent f99ae299f5
commit 895a5fb66a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 38 additions and 7 deletions

View File

@ -4,19 +4,50 @@
from __future__ import absolute_import, division, print_function, unicode_literals
readonly = False
from calibre import prints
readonly = True
version = 0 # change this if you change signature of implementation()
def implementation(db, notify_changes, *args):
is_remote = notify_changes is not None
is_remote
def implementation(db, notify_changes, query):
return db.search(query)
def option_parser(get_parser, args):
pass
parser = get_parser(
_(
'''\
%prog search [options] search expression
Search the library for the specified search term, returning a comma separated
list of book ids matching the search expression. The output format is useful
to feed into other commands that accept a list of ids as input.
The search expression can be anything from calibre's powerful search query
language, for example: {0}
'''
).format('author:asimov title:robot')
)
parser.add_option(
'-l',
'--limit',
default=-1,
type=int,
help=_('The maximum number of results to return. Default is all results.')
)
return parser
def main(opts, args, dbctx):
raise NotImplementedError('TODO: implement this')
if len(args) < 1:
raise SystemExit(_('Error: You must specify the search expression'))
q = ' '.join(args)
ids = dbctx.run('search', q)
if not ids:
raise SystemExit(_('No books matching the search expression:') + ' ' + q)
ids = sorted(ids)
if opts.limit > -1:
ids = ids[:opts.limit]
prints(','.join(map(str, ids)), end='')
return 0

View File

@ -23,7 +23,7 @@ COMMANDS = (
'set_metadata', 'export', 'catalog', 'saved_searches', 'add_custom_column',
'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
'check_library', 'list_categories', 'backup_metadata', 'clone', 'embed_metadata',
# 'search'
'search'
)