Skip to content

Comments

fixes search not being added to filters#1179

Merged
MrgSub merged 1 commit intostagingfrom
06-01-fixes_search_not_being_added_to_filters
Jun 2, 2025
Merged

fixes search not being added to filters#1179
MrgSub merged 1 commit intostagingfrom
06-01-fixes_search_not_being_added_to_filters

Conversation

@ahmetskilinc
Copy link
Contributor

@ahmetskilinc ahmetskilinc commented Jun 1, 2025

TL;DR

Improved search functionality in the command palette by adding automatic filter creation for search queries.

What changed?

  • Removed the processSearchQuery function that was handling natural language date parsing
  • Added automatic creation of search filters when users enter search queries
  • Added special handling for AI-generated search queries, creating distinct filters for them
  • Added detection for filter syntax to prevent creating redundant search filters
  • Updated dependency arrays in useCallback hooks to include the new addFilter function

How to test?

  1. Open the command palette and enter a search query (e.g., "emails from John")
  2. Verify that a search filter is automatically created with the label "Search: 'emails from John'"
  3. Try an AI-generated search query and confirm it creates a filter with "AI Search:" prefix
  4. Test queries that already use filter syntax (e.g., "from:john@example.com") and verify they don't create redundant filters
  5. Ensure that multiple search filters can be added and that they properly combine in the search query

Why make this change?

This change improves the user experience by automatically creating search filters from queries, making it easier for users to see and manage their active search criteria. It also differentiates between regular searches and AI-enhanced searches, giving users better visibility into how their search terms are being processed and applied.

Summary by CodeRabbit

  • New Features

    • Improved search functionality by automatically adding a search filter when queries do not use filter prefixes.
    • Enhanced AI-generated search queries now display with an "AI Search:" label.
  • Refactor

    • Simplified search processing by removing custom date parsing and streamlining filter handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 1, 2025

Walkthrough

This change streamlines the search query handling in the command palette context by removing custom natural language date parsing and the processSearchQuery function. It now directly uses AI-powered search parsing and uniformly adds 'search' filters for queries without filter prefixes, simplifying the overall logic.

Changes

File(s) Change Summary
apps/mail/components/context/command-palette-context.tsx Removed processSearchQuery, eliminated custom date parsing, refactored search/filter logic to use AI parsing and uniform filter addition.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CommandPaletteContext
    participant AIParser

    User->>CommandPaletteContext: Submit search query
    alt Query starts with filter prefix
        CommandPaletteContext->>CommandPaletteContext: Add corresponding filter
    else Query is non-empty and no filter prefix
        CommandPaletteContext->>AIParser: Parse query (AI-powered)
        AIParser-->>CommandPaletteContext: Return parsed query
        CommandPaletteContext->>CommandPaletteContext: Add 'search' filter (label: "AI Search:" if AI-generated)
    end
Loading

Possibly related PRs

  • Mail-0/Zero#1154: Completely rewrote command-palette-context.tsx to implement a multi-view command palette with advanced search/filter features, including natural language and AI-powered search query generation.

Suggested reviewers

  • MrgSub

Poem

In the warren, search was once a maze,
With dates parsed out in winding ways.
Now the code is lean and spry,
AI helps queries hop and fly!
Filters added with a cheerful cheer—
Simpler search for all to hear!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ahmetskilinc ahmetskilinc marked this pull request as ready for review June 1, 2025 12:02
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/mail/components/context/command-palette-context.tsx (1)

558-569: Consider extracting duplicated filter creation logic.

This code block duplicates the filter syntax checking and search filter creation logic from executeSearch (lines 432-443). Consider extracting this into a shared helper function to follow the DRY principle.

+  const createSearchFilterIfNeeded = useCallback((query: string, isAI = false) => {
+    const isFilterSyntax = /^(from:|to:|subject:|has:|is:|after:|before:|label:)/.test(
+      query.trim(),
+    );
+    if (query.trim() && !isFilterSyntax) {
+      const searchFilter: ActiveFilter = {
+        id: `${isAI ? 'ai-' : ''}search-${Date.now()}`,
+        type: 'search',
+        value: isAI ? query : query,
+        display: isAI ? `AI Search: "${query}"` : `Search: "${query}"`,
+      };
+      addFilter(searchFilter);
+    }
+  }, [addFilter]);

Then update both executeSearch and handleSearch to use this helper:

-      const isFilterSyntax = /^(from:|to:|subject:|has:|is:|after:|before:|label:)/.test(
-        query.trim(),
-      );
-      if (query.trim() && !isFilterSyntax) {
-        const searchFilter: ActiveFilter = {
-          id: `search-${Date.now()}`,
-          type: 'search',
-          value: query,
-          display: `Search: "${query}"`,
-        };
-        addFilter(searchFilter);
-      }
+      createSearchFilterIfNeeded(query);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13bae8f and ce78e27.

📒 Files selected for processing (1)
  • apps/mail/components/context/command-palette-context.tsx (7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/mail/components/context/command-palette-context.tsx (1)
apps/server/src/trpc/routes/ai/search.ts (1)
  • generateSearchQuery (10-23)
🔇 Additional comments (5)
apps/mail/components/context/command-palette-context.tsx (5)

41-41: LGTM! Import cleanup aligns with feature changes.

The removal of parseNaturalLanguageDate is consistent with simplifying the search query handling by removing custom date parsing logic.


432-443: Good implementation of filter syntax detection.

The regex pattern correctly identifies common Gmail filter prefixes to avoid creating redundant search filters. The implementation properly trims the query before checking.


461-461: Dependency array correctly updated.

The addition of addFilter to the dependency array ensures the callback stays in sync with the latest filter management logic.


541-547: Excellent differentiation for AI-generated searches.

The "AI Search:" prefix clearly distinguishes AI-generated searches from regular ones, improving user awareness of active search types.


601-601: Dependency array correctly includes all required dependencies.

The addition of both generateSearchQuery and addFilter ensures the callback properly responds to changes in these dependencies.

@MrgSub MrgSub merged commit 90ae1c2 into staging Jun 2, 2025
3 checks passed
Copy link
Collaborator

MrgSub commented Jun 2, 2025

Merge activity

@MrgSub MrgSub deleted the 06-01-fixes_search_not_being_added_to_filters branch June 2, 2025 20:55
@coderabbitai coderabbitai bot mentioned this pull request Jun 25, 2025
7 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jul 16, 2025
31 tasks
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