Repository navigation
feat(core): search a publication's text - #28
Closed
devaryakjha wants to merge 7 commits into
Closed
devaryakjha wants to merge 7 commits into
devaryakjha wants to merge 7 commits into
Conversation
Publication.search(for:options:) finds a query in reflowable formats by reading each chapter's markup into the same flat text the reader script indexes, so every result is a Locator that go(to:) opens at the page holding the match, with the matched text and some words around it. PDF searches through PDFKit in its module, with a page fragment and the chapter's title from the outline. ReaderController.search(for:options:) drops results when the session changes while searching. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfwUCp8GqHWUdTK7EhZCT5
findString returned a different set of selections than the page text holds on the Apple CI runner, so results came out with the wrong pages. Searching PDFPage.string with the shared matcher gives the same results and context as reflowable formats, and the page is set on each match. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfwUCp8GqHWUdTK7EhZCT5
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfwUCp8GqHWUdTK7EhZCT5
xcodebuild's console doesn't print expectation comments, but it does print a thrown error's description. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfwUCp8GqHWUdTK7EhZCT5
Publication.search finds a format's module through the registry, and the PDF test opened the publication through the module directly, so the search fell through to the markup search and found nothing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfwUCp8GqHWUdTK7EhZCT5
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfwUCp8GqHWUdTK7EhZCT5
PDFKit reads only the text inside a page's box. The fixture's pages were 200 points wide, so a 12-point line was cut at 33 characters and the search found two matches of three. Pages are letter-sized now. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfwUCp8GqHWUdTK7EhZCT5
2 tasks done
devaryakjha
added a commit
that referenced
this pull request
Oct 21, 2026
Lands four pull requests in one: - #28 feat(core): search a publication's text. Publication.search finds a query in reflowable formats and PDFs, returning Locators that go(to:) opens at the match, with the text around it. - #29 feat(ui): standard controls, accessibility and a String Catalog. ReaderView draws a title bar, table of contents, search and appearance sheets and a position slider; every control is labelled for VoiceOver, and user-facing strings are localizable. - #30 feat(archives): read CBR and CB7 through libarchive, in the optional ChekReaderArchives product. - #27 Point the README at the 0.1.0 release instead of main. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfwUCp8GqHWUdTK7EhZCT5
Contributor
Author
|
Landed on Generated by Claude Code |
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.
Requested by Arya · project thread
Before
The reader had no search. An app wanting to find text in an open book had to read every chapter itself and had no way to turn a hit into a location the navigator could open.
After
Publication.search(for:options:)andReaderController.search(for:options:)find a query and returnLocatorvalues in reading order. Each result carries the matched text with some words around it intext, the chapter's title when the table of contents names it, and a progression through its resource.ReaderController.go(to:)opens the page holding the match, because the context is a slice of the same flat text the reader script uses for anchors.SearchOptionssets case and diacritic sensitivity and a result limit (1000 by default).PDFModule, with apage=Nfragment per result and the outline's title for the page.Visual highlighting of a match on the page isn't part of this; it needs a decorations feature in the reader script and comes with the controls PR.
How
HTMLText.flatteninChekReaderCorereads an HTML or XHTML document into the body's text with whitespace collapsed, skippinghead,script,style, comments and declarations, and decoding entities. It does what the script'stextIndexplusnormalizeddo, so a result'sbeforeandhighlightare exactly whatgoToTextlooks for.ReaderFormatModulegains an optionalsearchhook with a default returningnil, so only PDF overrides it.PDFFixture.documentcan now put a line of text on chosen pages, which the PDF search test uses.HTMLTextTests(what the flattening keeps and drops),SearchTestsin the EPUB target (hits across chapters with context, case, diacritics, limit, blank query),searchesTheOpenPublicationinReaderControllerTests,findsTextOnPagesinPDFModuleTests.Built and tested here with Swift 6.4.1 on Linux (
swift build --build-tests && swift test --skip-build, 180 tests pass). The PDF path and Apple targets weren't built here, since there's no Xcode in this environment; the Apple CI job covers them.Generated by Claude Code