Skip to content

Conversation

@veloman-yunkan
Copy link
Collaborator

This is the clean-up work extracted from #994

It helps to reduce boilerplate code in tests.
The helper utilities getSuggestions() and EXPECT_SUGGESTION_RESULTS
in the suggestion unit-test actually return and check only titles.
So renamed them as follows, so that the old names can then
be used for new helpers for more exhaustive testing of suggestions:

getSuggestions() -> getSuggestedTitles()
EXPECT_SUGGESTION_RESULTS() -> EXPECT_SUGGESTED_TITLES()
zim::Archive::Entry::offset() is not a state modifier method.

The bug was hiding there for almost four years and was not observed as
it only applied to paging of suggestions in the absence of Xapian DB.

Paging (infinite scrolling) of suggestions in the UI was implemented in
kiwix-desktop last year and was (naturally) tested only on ZIM archives
with Xapian indexes.
The diff is a little easier to understand if whitespace changes are
ignored.
It was used to get rid of the custom copy-constructor and
copy-assignment operator in SuggestionIterator::SuggestionInternalData,
but probably may be (re)used in other code like that.
Didn't replace `std::unique_ptr` with `ValuePtr` in `mp_rangeIterator` and
`mp_internal` data members of `zim::SuggestionIterator` since the latter
is part of the libzim public API (and that would require making
`smartptr.h` a public header file).
Moved the declaration of SuggestionIterator::SuggestionInternalData
to suggestion_iterator.cpp. As a result, had to move the definition of
SuggestionResultSet::{begin,end}() there, too.
Renamed SuggestionIterator::Impl::{mp_internalDb -> mp_db}
... instead of the full Xapian document
@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

❌ Patch coverage is 60.36036% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.13%. Comparing base (0db0295) to head (5d00100).
⚠️ Report is 43 commits behind head on main.

Files with missing lines Patch % Lines
src/suggestion_iterator.cpp 61.38% 8 Missing and 31 partials ⚠️
src/suggestion.cpp 16.66% 0 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1006      +/-   ##
==========================================
+ Coverage   57.96%   58.13%   +0.17%     
==========================================
  Files         101      101              
  Lines        5407     5384      -23     
  Branches     2219     2197      -22     
==========================================
- Hits         3134     3130       -4     
+ Misses        800      795       -5     
+ Partials     1473     1459      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Rewrote the Suggestion.indexFullPath unit-test by checking the Xapian data
directly.
Having data members conditionally compiled makes the libzim ABI
dependent on the build type which can lead to crashes if a wrong
build of libzim is used with the client application.

This commit doesn't fully solve the problem since LIBZIM_WITH_XAPIAN
is still used in include/zim/suggestion.h
@kelson42
Copy link
Contributor

@veloman-yunkan Few questions my side:

  • Ready to review?
  • Obviously implies to API change and behaviour change?
  • Impact only the pre-existing suggestion code (no new stuff related to the spellchecking as this sutff should be handled separatly)

@veloman-yunkan
Copy link
Collaborator Author

@veloman-yunkan Few questions my side:

  • Ready to review?

@kelson42 I intended to have it merged right before #1007, but as a refactoring/cleanup effort it makes sense to commit this work regardless of whether any subsequent changes dependent on it follow.

  • Obviously implies to API change and behaviour change?

Did you mean no API and behaviour change? If yes, then mostly yes. There is one bug-fix for an exotic scenario.

  • Impact only the pre-existing suggestion code (no new stuff related to the spellchecking as this sutff should be handled separatly)

Yes, this is a purely clean-up PR.

@kelson42 kelson42 merged commit c883006 into main Sep 29, 2025
26 of 31 checks passed
@kelson42 kelson42 deleted the suggestions_cleanup branch September 29, 2025 12:35
@kelson42 kelson42 added this to the 9.4.0 milestone Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants