Skip to content

Add full-text search and search across all books - #4978

Open
613avi wants to merge 1 commit into
kiwix:mainfrom
613avi:upstream-content-search
Open

Add full-text search and search across all books#4978
613avi wants to merge 1 commit into
kiwix:mainfrom
613avi:upstream-content-search

Conversation

@613avi

@613avi 613avi commented Jul 14, 2026

Copy link
Copy Markdown

Fixes / features

Search currently only matches article titles, in the currently open book. This PR adds two search options, selected with chips at the top of the search screen:

  • Page content — full-text search over the page content using the ZIM file's Xapian index. Results show a snippet of the sentence where the term was found, with the match in bold. Books without a full-text index transparently fall back to the title search.
  • All books — the same search over every book on the device. Each result shows which book it came from, and opening a result switches the reader to that book first.

The selected mode is remembered (data store), so the search screen opens the way the user left it.

Implementation

  • ZimFileReader.searchFullText() lazily creates a libzim Searcher (and disposes it with the reader).
  • ZimSearchResultSet models the two kinds of result set (title suggestions / full-text search) so SearchState can page through either.
  • GlobalSearchResultGenerator searches the books of the library one by one on the IO dispatcher; an unreadable book is skipped rather than failing the whole search.
  • SearchItemToOpen carries the book a result belongs to, which CoreReaderViewModel uses to open that book before loading the page.

Testing

  • New GlobalSearchResultGeneratorTest; existing search tests updated for the new signatures.
  • :core:testDebugUnitTest, :core:ktlintCheck, :core:detektDebug and :app:assembleDebug all pass locally.
  • Manually tested on a device against a Wikipedia ZIM (title search, full-text search, and cross-book search including opening a result from another book).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y3LCEHHPfZmDSH9iF15UqV

The search screen can currently only look up article titles in the book
that is open. This adds two options, selectable with chips at the top of
the search screen:

* Page content: a full-text search over the content of the pages, using
  the Xapian index of the ZIM file (falls back to the title search for
  ZIM files without a full-text index). Results show a snippet of the
  sentence the term was found in, with the match in bold.
* All books: runs the same search over every book on the device. Each
  result shows the book it comes from, and opening it switches the
  reader to that book first.

The selected mode is remembered in the data store, so the search screen
opens the way the user left it.

Implementation notes:
* ZimFileReader gains searchFullText(), lazily creating a libzim Searcher.
* ZimSearchResultSet models the two kinds of result set (title/page
  content) so SearchState can iterate over either.
* GlobalSearchResultGenerator searches the books from the library one by
  one on the IO dispatcher; a book that cannot be read is skipped rather
  than failing the whole search.
* SearchItemToOpen carries the book of the result, which the reader uses
  to switch books before loading the page.
@MohitMaliFtechiz

Copy link
Copy Markdown
Collaborator

@613avi It seems it is a huge refactoring and feature change around the search. We shouldd diccuss this before implementing. You should create a ticket first before making the coding effort. So that we can decide wether we need to implement this or not.

@613avi

613avi commented Jul 14, 2026

Copy link
Copy Markdown
Author

I made this change for a personal need, and since I saw demand, I decided to submit a PR.

@MohitMaliFtechiz

Copy link
Copy Markdown
Collaborator

It seems it is related to #1324. But with some addtional changes. Like directly opening the book if not open in the reader.

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.

2 participants