diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b3e14c..9fc5664 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Patch vendored `wombat.js` so `retrieveWBOSRCAsURL` (the helper behind the above element-property fix) resolves a recorded original against the frame's true original URL (`wb_info.url`) instead of its replay-time `ownerDocument`, fixing it returning/using a URL under the wrong host for a page whose own URL was changed by a fuzzy rule (e.g. YouTube embeds), which broke playback (#398) - Add a host-gated `SITE_JS_PATCHES` mechanism to `JsRewriter`, fixing MDN's `` widget missing a deterministic `permalink` attribute (#394) +### Changed + +- Re-enable `test_indexing_item_not_front` and test libzim's current indexing behavior for non-front items, including non-front `text/html` ones (#400) + ## [5.5.2] - 2026-11-06 ### Fixed diff --git a/tests/zim/test_indexing.py b/tests/zim/test_indexing.py index 0279ee9..66a13af 100644 --- a/tests/zim/test_indexing.py +++ b/tests/zim/test_indexing.py @@ -119,8 +119,8 @@ def test_indexing_item_is_front(tmp_path: pathlib.Path, png_image: pathlib.Path) assert reader.get_search_results_count("food") == 0 -@pytest.mark.skip # see https://github.com/openzim/python-scraperlib/issues/258 def test_indexing_item_not_front(tmp_path: pathlib.Path, png_image: pathlib.Path): + """Create a ZIM with a non-front item with custom title and content for indexing""" fpath = tmp_path / "test.zim" main_path = "welcome" with Creator(fpath, main_path).config_dev_metadata() as creator: @@ -139,21 +139,73 @@ def test_indexing_item_not_front(tmp_path: pathlib.Path, png_image: pathlib.Path assert fpath.exists() reader = Archive(fpath) - # "brain" works as a suggestion but "food" doesn't work because since no front - # article is present in the zim file, libzim doesn't create a title xapian index. - # so, when searching suggestion, libzim is fallback to a binary search on the title - # and return only article starting by the query. - # see https://github.com/openzim/libzim/issues/902#issuecomment-2223050129 - assert "welcome" in list(reader.get_suggestions("brain")) + # libzim 3.13 yields no suggestions for a non-front item. + # This test documents libzim's current behaviour. + assert "welcome" not in list(reader.get_suggestions("brain")) assert "welcome" not in list(reader.get_suggestions("food")) assert "welcome" not in list(reader.get_suggestions("screen")) assert "welcome" not in list(reader.get_suggestions("car")) - assert reader.get_search_results_count("screen") >= 1 - assert reader.get_search_results_count("car") >= 1 + assert reader.get_search_results_count("screen") == 1 + assert reader.get_search_results_count("car") == 1 assert reader.get_search_results_count("brain") == 0 assert reader.get_search_results_count("food") == 0 +def test_indexing_html_not_front_custom(tmp_path: pathlib.Path): + """A non-front HTML item has custom indexing data""" + fpath = tmp_path / "test.zim" + main_path = "welcome" + with Creator(fpath, main_path).config_dev_metadata() as creator: + creator.add_item( + StaticItem( + content="car", + path="welcome", + title="brain food", + mimetype="text/html", + index_data=IndexData(title="screen", content="car"), + hints={libzim.writer.Hint.FRONT_ARTICLE: False}, + ) + ) + assert fpath.exists() + + reader = Archive(fpath) + assert "welcome" not in list(reader.get_suggestions("brain")) + assert "welcome" not in list(reader.get_suggestions("food")) + assert "welcome" not in list(reader.get_suggestions("screen")) + assert "welcome" not in list(reader.get_suggestions("car")) + assert reader.get_search_results_count("screen") == 1 + assert reader.get_search_results_count("car") == 1 + assert reader.get_search_results_count("brain") == 0 + assert reader.get_search_results_count("food") == 0 + + +def test_indexing_html_not_front_with_libzim(tmp_path: pathlib.Path): + """A non-front HTML item is automatically indexed by libzim""" + fpath = tmp_path / "test.zim" + main_path = "welcome" + with Creator(fpath, main_path).config_dev_metadata() as creator: + creator.add_item( + StaticItem( + content="screencar", + path="welcome", + title="brain food", + mimetype="text/html", + hints={libzim.writer.Hint.FRONT_ARTICLE: False}, + ) + ) + assert fpath.exists() + + reader = Archive(fpath) + assert "welcome" not in list(reader.get_suggestions("brain")) + assert "welcome" not in list(reader.get_suggestions("food")) + assert "welcome" not in list(reader.get_suggestions("screen")) + assert "welcome" not in list(reader.get_suggestions("car")) + assert reader.get_search_results_count("brain") == 1 + assert reader.get_search_results_count("food") == 1 + assert reader.get_search_results_count("car") == 1 + assert reader.get_search_results_count("screen") == 0 + + def _assert_pdf_zim(fpath: pathlib.Path): assert fpath.exists()