Skip to content

Commit 787c9ed

Browse files
author
renaud gaudin
committed
Added all_entry_count and article_count
libzim now has three different count methods for entries: - `all_entry_count`: number of entries in the archive - `entry_count`: number of user entries in the archive - `article_count`: number of articles in the archive
1 parent 07e0534 commit 787c9ed

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

libzim/wrapper.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ cdef extern from "lib.h":
147147
ZimItem* getIllustrationItem() except +
148148
ZimItem* getIllustrationItem(int size) except +
149149
size_type getEntryCount() except +
150+
size_type getAllEntryCount() except +
151+
size_type getArticleCount() except +
150152

151153
string getChecksum() except +
152154
string getFilename() except +

libzim/wrapper.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,14 @@ cdef class PyArchive:
598598
def entry_count(self) -> int:
599599
return self.c_archive.getEntryCount()
600600

601+
@property
602+
def all_entry_count(self) -> int:
603+
return self.c_archive.getAllEntryCount()
604+
605+
@property
606+
def article_count(self) -> int:
607+
return self.c_archive.getArticleCount()
608+
601609
def get_illustration_sizes(self):
602610
# FIXME: using static shortcut instead of libzim's
603611
# cdef set[unsigned int] sizes = self.c_archive.getIllustrationSizes()

tests/test_libzim_reader.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"checksum": None,
3232
"is_valid": True,
3333
"entry_count": 0,
34+
"all_entry_count": 4,
35+
"article_count": 0,
3436
"suggestion_string": "",
3537
"suggestion_count": 0,
3638
"suggestion_result": [],
@@ -74,6 +76,8 @@
7476
"checksum": None,
7577
"is_valid": True,
7678
"entry_count": 371,
79+
"all_entry_count": 371,
80+
"article_count": 284,
7781
"suggestion_string": "lucky",
7882
"suggestion_count": 1,
7983
"suggestion_result": ["A/That_Lucky_Old_Sun"],
@@ -115,6 +119,8 @@
115119
"checksum": "abcd818c87079cb29282282b47ee46ec",
116120
"is_valid": True,
117121
"entry_count": 60,
122+
"all_entry_count": 75,
123+
"article_count": 0,
118124
"suggestion_string": "favicon",
119125
"suggestion_count": 1,
120126
"suggestion_result": ["favicon.png"],
@@ -160,6 +166,8 @@
160166
"checksum": None,
161167
"is_valid": True,
162168
"entry_count": 19,
169+
"all_entry_count": 19,
170+
"article_count": 1,
163171
"suggestion_string": "empty",
164172
"suggestion_count": 1,
165173
"suggestion_result": ["A/empty.html"],
@@ -359,6 +367,8 @@ def test_reader_checksum(all_zims, filename, has_checksum, is_valid):
359367
[
360368
"filename",
361369
"entry_count",
370+
"all_entry_count",
371+
"article_count",
362372
"suggestion_string",
363373
"suggestion_count",
364374
"suggestion_result",
@@ -372,6 +382,8 @@ def test_reader_suggest_search(
372382
all_zims,
373383
filename,
374384
entry_count,
385+
all_entry_count,
386+
article_count,
375387
suggestion_string,
376388
suggestion_count,
377389
suggestion_result,
@@ -383,6 +395,10 @@ def test_reader_suggest_search(
383395

384396
# suggestion and search results
385397
assert zim.entry_count == entry_count
398+
assert zim.all_entry_count == all_entry_count
399+
assert zim.article_count == article_count
400+
401+
386402
# TODO: restore [search-api]
387403
# assert (
388404
# zim.get_estimated_suggestions_results_count(suggestion_string)

0 commit comments

Comments
 (0)