Skip to content

#6027 - Exhaustive conversation search #6078

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cemsozens
Copy link

First time contributor checklist

Contributor checklist

  • My commits are rebased on the latest main branch
  • My commits are in nice logical chunks
  • My contribution is fully baked and is ready to be merged as is
  • I have tested my contribution on these devices:
    *iPhone 16 Pro, iOS 18.5

Description

This pull request fixes #6027 by making conversation search truly exhaustive. Originally, searching within a conversation would perform a global FTS search across all conversations (limited to 500 results), then filter by thread ID at the application level.

Problem

A conversation search that looks like:

  • Search for "http" → 212 results
  • Search for "https" → 215 results

This was impossible since "https" is more specific than "http", indicating the search was not exhaustive.

Root Cause

The original flow was:

  1. Global FTS search: SELECT * FROM fts_table WHERE content MATCH 'https' LIMIT 500
  2. Application filtering: Check if message.uniqueThreadId == targetThreadId

If most of the 500 global matches were from other conversations, the target conversation would get incomplete results.

Solution

Move the thread filtering to the database level using SQL JOINs:

SELECT content.*, interaction.uniqueThreadId  
FROM fts_table
LEFT JOIN model_TSInteraction ON model_TSInteraction.uniqueId = content.uniqueId
WHERE content.ftsContent MATCH 'https' 
AND model_TSInteraction.uniqueThreadId = 'target-conversation-id'
LIMIT 500

Now the LIMIT applies only to messages within the target conversation, ensuring exhaustive results.

Changes Made

Enhanced FullTextSearchIndexer.swift

  • Added overloaded search() method with optional threadUniqueId parameter
  • When threadUniqueId is provided, uses thread-specific SQL query with JOIN
  • Maintains backward compatibility with existing global search functionality

Updated FullTextSearcher.swift

  • searchWithinConversation() now uses the new thread-specific search method
  • Removed application-level filtering since database now handles it
  • Improved performance by eliminating wasted work on irrelevant messages

Added comprehensive tests

  • FullTextSearchIndexerTest.swift which covers:
    • Search exhaustiveness scenarios with large datasets
    • Thread-specific vs global search behavior
    • Performance testing with 1000+ messages
    • Snippet generation with long message content
    • Edge cases (empty queries, non-existent threads, result limits)

@sashaweiss-signal
Copy link
Contributor

Hi, thanks for your interest in contributing. Since this is a non-trivial change with serious performance and UX implications it'll require fairly intensive review, I'm going to mark this as acknowledged for the moment but I can't guarantee when we'll be able to review.

Search is something that we're interested in improving, and we'll consider this among the other improvements we want to make down the line!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search is not exhaustive
2 participants