fix: deduplicate search results when PST is re-imported#8
Merged
Conversation
When the same PST file is imported multiple times, each import creates
a new account with duplicate emails. SearchMulti was unioning all
account indices without deduplication, so the same messages appeared
multiple times in the search list.
Fix: deduplicate in SearchMulti by content checksum (extracted from
path format folder/{checksum}-{id}.eml). Uses ROW_NUMBER() to keep one
row per unique content across accounts.
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
regexp_extract returns empty string on no match; COALESCE('', x) yields ''
so all rows were partitioned by '' and collapsed to one. Use NULLIF to
treat empty as NULL so fallback to account||path keeps each row unique.
Co-authored-by: Cursor <cursoragent@cursor.com>
Paths from readpst (message_1.eml) lack checksum; account||path yielded unique keys per account so same email in 2 accounts appeared twice. Use subject|from|to|date|body as fallback fingerprint for dedup. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Closes #7
When a PST file is re-imported, each import creates a new account. SearchMulti was unioning all account indices without deduplication, so identical emails appeared multiple times in the search list.
Fix: Deduplicate in SearchMulti by content checksum extracted from the path format
folder/{checksum}-{id}.eml. Uses DuckDBregexp_extract+ROW_NUMBER() OVER (PARTITION BY checksum ...)to keep one row per unique content across accounts.Added
TestSearchMultiDeduplicatesByChecksumto verify the behavior.Made with Cursor