This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH] Add Collection.count_search_results()

Message ID
DKIM signature
Download raw message
Patch: +14 -0
This patch adds `Collection.count_search_results()` method which
counts results from a search.

It's much faster than count `get_all_search_results()`, as we avoid
to create Entry instances for every results.

On a collection with 264 items, doing a search for '+', counting
all results with


takes ~930 ms on my system, while


takes ~1.5 ms

 lesana/collection.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lesana/collection.py b/lesana/collection.py
index a3c6e22..00be506 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -414,6 +414,20 @@ class Collection(object):
            for match in mset:
                yield self._match_to_entry(match)
            offset += pagesize
    def count_search_results(self):
        if not self._enquire:
        count = 0
        offset = 0
        pagesize = 100
        while True:
            mset = self._enquire.get_mset(offset, pagesize)
            if mset.size() == 0:
            count += mset.size()
            offset += pagesize
        return count

    def get_all_documents(self):
Reply to thread Export thread (mbox)