mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Port calibredb search
This commit is contained in:
parent
f99ae299f5
commit
895a5fb66a
@ -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
|
||||
|
@ -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'
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user