diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2017-01-29 22:46:23 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2017-01-29 22:46:23 +0100 |
commit | c709c2eb5ebb3a661d228423860f3bdd46dac375 (patch) | |
tree | ae34fccff93f00031a825097cda1edabc894e832 | |
parent | cf5270ab70e0753c3fa2c016233963f287253794 (diff) |
Add option to show all search results
-rw-r--r-- | lesana/command.py | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/lesana/command.py b/lesana/command.py index dd1864a..56c855a 100644 --- a/lesana/command.py +++ b/lesana/command.py @@ -139,27 +139,35 @@ class Index(guacamole.Command): class Search(guacamole.Command): arguments = [ - (['--collection', '-c'], dict( + ] + + def register_arguments(self, parser): + parser.add_argument( + '--collection', '-c', help='The collection to work on (default .)' - )), - (['--template', '-t'], dict( + ) + parser.add_argument( + '--template', '-t', help='Am', - )), - (['--offset'], dict( + ), + parser.add_argument( + '--offset', type=int, - )), - (['--pagesize'], dict( + ), + parser.add_argument( + '--pagesize', type=int, - )), - (['query'], dict( + ), + parser.add_argument( + '--all', + action='store_true', + help='Return all available results' + ) + parser.add_argument( + 'query', help='Xapian query to search in the collection', nargs='+' - )), - ] - - def register_arguments(self, parser): - for arg in self.arguments: - parser.add_argument(*arg[0], **arg[1]) + ), def invoked(self, ctx): # TODO: implement "searching" for everything @@ -177,9 +185,12 @@ class Search(guacamole.Command): pagesize = ctx.args.pagesize or 12 collection = Collection(ctx.args.collection) collection.start_search(' '.join(ctx.args.query)) - results = collection.get_search_results( - offset, - pagesize) + if ctx.args.all: + results = collection.get_all_search_results() + else: + results = collection.get_search_results( + offset, + pagesize) if ctx.args.template: env = jinja2.Environment( loader=jinja2.FileSystemLoader( |