aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-06-04 22:49:54 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-06-04 22:49:54 +0200
commit96465262f72b1b4230513e978d8412d0affc75a1 (patch)
tree8239326b2cd8423140c796b8d65831d4cace5aee
parent9d6c7b5ef7f651a64e27db3d676a3a0153a85e7b (diff)
Search for all entries
-rw-r--r--lesana/collection.py7
-rw-r--r--lesana/command.py15
-rw-r--r--tests/test_collection.py8
3 files changed, 24 insertions, 6 deletions
diff --git a/lesana/collection.py b/lesana/collection.py
index d3715d1..da001ae 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -263,6 +263,13 @@ class Collection(object):
yield self._match_to_entry(match)
offset += pagesize
+ def get_all_documents(self):
+ cache = self._get_cache()
+ postlist = cache.postlist("")
+ for post in postlist:
+ doc = cache.get_document(post.docid)
+ yield self._doc_to_entry(doc)
+
def _match_to_entry(self, match):
return self._doc_to_entry(match.document)
diff --git a/lesana/command.py b/lesana/command.py
index 41448b3..2915d30 100644
--- a/lesana/command.py
+++ b/lesana/command.py
@@ -198,13 +198,16 @@ class Search(guacamole.Command):
offset = ctx.args.offset or 0
pagesize = ctx.args.pagesize or 12
collection = Collection(ctx.args.collection)
- collection.start_search(' '.join(ctx.args.query))
- if ctx.args.all:
- results = collection.get_all_search_results()
+ if ctx.args.query == ['*']:
+ results = collection.get_all_documents()
else:
- results = collection.get_search_results(
- offset,
- pagesize)
+ collection.start_search(' '.join(ctx.args.query))
+ 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(
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 891a439..5c326e3 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -87,6 +87,14 @@ class testCollection(unittest.TestCase):
matches = list(self.collection.get_all_search_results())
self.assertEqual(matches, [])
+ def test_all_entries(self):
+ self.collection = lesana.Collection('tests/data/simple')
+ res = self.collection.get_all_documents()
+ matches = list(res)
+ self.assertEqual(len(matches), 3)
+ for m in matches:
+ self.assertIsInstance(m, lesana.Entry)
+
def test_entry_from_uid(self):
self.collection = lesana.Collection('tests/data/simple')
entry = self.collection.entry_from_uid(