Skip to content

[BUG]: use byte offset in full-text reader rather than token position #4531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025

Conversation

codetheweb
Copy link
Contributor

@codetheweb codetheweb commented May 12, 2025

Description of changes

The full-text reader had a bug where it used the positions of tokens to determine whether the tokens appeared sequentially, rather than using the byte offset of tokens. This was problematic because the index stores byte offsets. Since Unicode characters can be many bytes wide, we cannot guarantee that the stored byte offsets are strictly consecutive.

Test plan

How are these changes tested?

Added a test that fails on main.

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?

n/a

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@codetheweb codetheweb force-pushed the bug-fts-reader-byte-offset-vs-token-position branch from 69dca61 to 8891e68 Compare May 12, 2025 20:56
@codetheweb codetheweb marked this pull request as ready for review May 12, 2025 21:07
@codetheweb codetheweb requested review from rescrv and HammadB May 12, 2025 21:07
Copy link
Contributor

Fix for Full-Text Search with Unicode Characters

This PR fixes a bug in the full-text reader where token positions were used instead of byte offsets when determining if tokens appeared sequentially. Since Unicode characters can be variable-width (multiple bytes), using token positions led to incorrect search results when texts contained multi-byte characters. The fix uses byte offsets to properly handle Unicode text.

Key Changes:
• Changed position adjustment logic to use byte offsets instead of token positions
• Simplified the token position adjustment algorithm
• Added a test case for documents containing multi-byte characters

Affected Areas:
• Full-text search implementation in rust/index/src/fulltext/types.rs

This summary was automatically generated by @propel-code-bot

@codetheweb codetheweb enabled auto-merge (squash) May 12, 2025 21:37
@codetheweb codetheweb merged commit 796610e into main May 12, 2025
70 checks passed
@codetheweb codetheweb deleted the bug-fts-reader-byte-offset-vs-token-position branch May 12, 2025 21:55
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