Repository navigation
Add Page.search_for_fuzzy() for edit-distance text search - #5293
Open
veget-able wants to merge 2 commits into
Open
veget-able wants to merge 2 commits into
veget-able wants to merge 2 commits into
Conversation
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.
Adds
Page.search_for_fuzzy(needle, *, max_edits, clip=None, textpage=None)to find text with small spelling differences. It returns one dictionary per occurrence, containing the extractedtext, Levenshteindistanceand groupedquadsfor highlighting. No additional dependency is required.The matcher normalizes Unicode case, whitespace and line-end hyphens, while preserving source character boundaries. Exact query pieces narrow the candidate regions before a bounded edit-distance scan. The API documentation describes overlap selection, extraction order, TextPage reuse and the limits of interpreting edit distance.
An internal RAWDICT mode retains native character quads when quad corrections are disabled, including the setting used by PyMuPDF4LLM. This keeps highlighting accurate without changing global settings. The usual RAWDICT output remains unchanged.
Local measurements with 100-character queries and
max_edits=2, including extraction and quad construction, were 3.8–5.4 times the nativesearch_for(quads=True)time with corrections enabled, and 5.8–6.6 times with corrections disabled. These cover 1k, 5k and 20k synthetic pages and the first page ofgithub_sample.pdf; repeated text can be substantially slower. The documented usage is exact search followed by a fuzzy fallback.Validation on Windows, Python 3.13.2 and MuPDF 1.28.6:
tests/test_pylint.pypassed, including the new module.75ea5228; no new warnings.