Add full-text search and search across all books - #4978
Open
613avi wants to merge 1 commit into
Open
Conversation
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.
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. |
Author
|
I made this change for a personal need, and since I saw demand, I decided to submit a PR. |
Collaborator
|
It seems it is related to #1324. But with some addtional changes. Like directly opening the book if not open in the reader. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
The selected mode is remembered (data store), so the search screen opens the way the user left it.
Implementation
ZimFileReader.searchFullText()lazily creates a libzimSearcher(and disposes it with the reader).ZimSearchResultSetmodels the two kinds of result set (title suggestions / full-text search) soSearchStatecan page through either.GlobalSearchResultGeneratorsearches the books of the library one by one on the IO dispatcher; an unreadable book is skipped rather than failing the whole search.SearchItemToOpencarries the book a result belongs to, whichCoreReaderViewModeluses to open that book before loading the page.Testing
GlobalSearchResultGeneratorTest; existing search tests updated for the new signatures.:core:testDebugUnitTest,:core:ktlintCheck,:core:detektDebugand:app:assembleDebugall pass locally.🤖 Generated with Claude Code
https://claude.ai/code/session_01Y3LCEHHPfZmDSH9iF15UqV