Skip to content

feat: fuzzy find #32

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 2 commits into from
Mar 24, 2025
Merged

feat: fuzzy find #32

merged 2 commits into from
Mar 24, 2025

Conversation

nao1215
Copy link
Owner

@nao1215 nao1215 commented Mar 24, 2025

Summary by CodeRabbit

  • New Features

    • Introduced an interactive SQL query history feature with fuzzy search. Users can type keywords to filter history items, and selecting a history entry now copies the query into the input field.
    • Enhanced the user interface with improved styling and keyboard navigation for seamless interaction.
  • Documentation

    • Updated feature descriptions and visual guides to reflect the new SQL query history functionality, including a dynamic demonstration GIF.
  • Chores

    • Added a new dependency for fuzzy search functionality.
    • Updated configuration for linting tools to specify the version used.

Copy link

coderabbitai bot commented Mar 24, 2025

Walkthrough

This pull request updates the documentation and user interface to support a new SQL query history feature with fuzzy search capabilities. The README now includes a description and a GIF image for query history, while the go.mod file adds a new fuzzy search dependency. The TUI component has been modified to incorporate a search input, update the displayed history dynamically using the fuzzy search package, and adjust layout and focus behavior.

Changes

File(s) Change Summary
README.md Updated "Key Features" to include "Query History"; revised instructions for interacting with the SQL query history (copy query now occurs in the input field instead of the text area); replaced a static image with a GIF for the history list.
go.mod Added a new dependency: github.com/lithammer/fuzzysearch v1.1.8.
tui/tui.go Introduced fuzzy search in the showHistoryList method; added an updateList(query string) function and a new styled search input field; modified the layout and focus behavior to toggle between the input and history list, and streamlined error handling.
.github/workflows/reviewdog.yml Added a new configuration option for golangci-lint specifying version v1.64.8.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TUI
    participant FuzzySearch as Fuzzy Package
    participant HistoryData

    User->>TUI: Enters search query
    TUI->>FuzzySearch: Apply fuzzy filter on query history
    FuzzySearch-->>TUI: Returns filtered history items
    TUI->>HistoryData: Refresh history list display
    HistoryData-->>TUI: Provides updated list
    TUI->>User: Displays filtered SQL query history
Loading

Poem

I’m a rabbit with code in my paws,
Hopping through changes without a pause.
Query history now dances with fuzzy delight,
Input fields and lists shining bright.
With every keystroke, my heart takes flight!
🐰✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 136579d and 794ee43.

📒 Files selected for processing (1)
  • .github/workflows/reviewdog.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/reviewdog.yml (1)

19-20: Pin Specific Lint Version

The explicit pinning of golangci_lint_version: v1.64.8 helps ensure consistent linting behavior across runs. Please verify that this version is compatible with our existing custom lint rules and any project-specific configurations.


🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

This comment has been minimized.

Copy link

@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 (2)
tui/tui.go (2)

576-600: Efficient implementation of fuzzy search with good UX considerations.

The fuzzy search implementation is well-structured. The use of a closure function for updating the list is a clean approach. Some UX improvements to consider:

  • The truncation of long SQL queries to 75 characters with ellipsis improves readability
  • The reverse ordering (newest first) makes it easier to find recent queries
  • The fuzzy matching leverages the library effectively

Consider adding a placeholder text to the search input field to guide users:

 searchInput := tview.NewInputField().
 	SetLabel("Fuzzy Search: ").
+	SetPlaceholder("Type to filter history...").
 	SetFieldStyle(tcell.StyleDefault.

583-586: Consider handling case sensitivity in fuzzy search.

The current implementation uses fuzzy.Match with default settings, which might not handle case sensitivity in the most user-friendly way.

-if query != "" && !fuzzy.Match(query, displayText) {
+// Perform case-insensitive fuzzy matching for better UX
+if query != "" && !fuzzy.MatchFold(query, displayText) {
 	continue
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between df8b120 and 136579d.

⛔ Files ignored due to path filters (3)
  • doc/image/sql_query_history.gif is excluded by !**/*.gif
  • doc/image/sql_query_history.png is excluded by !**/*.png
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • README.md (2 hunks)
  • go.mod (1 hunks)
  • tui/tui.go (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
tui/tui.go (4)
tui/theme.go (6)
  • t (24-40)
  • t (59-314)
  • t (317-327)
  • t (330-341)
  • t (344-356)
  • t (359-370)
infrastructure/persistence/history.go (4)
  • historyLister (86-88)
  • h (28-47)
  • h (64-81)
  • h (98-131)
interactor/history.go (1)
  • historyLister (49-51)
domain/model/history.go (3)
  • h (27-35)
  • h (38-44)
  • History (11-16)
🔇 Additional comments (8)
go.mod (1)

17-17: Good choice of fuzzy search library.

The addition of github.com/lithammer/fuzzysearch is appropriate for implementing fuzzy search functionality. This is a well-maintained library with good performance characteristics for text matching.

README.md (2)

14-14: Great addition to the Key Features section.

The new feature description clearly communicates the functionality added to users. Mentioning both the query history and fuzzy search capability in a concise manner is helpful.


72-74: Documentation updated to accurately reflect the new UI workflow.

The documentation has been properly updated to explain the fuzzy search functionality and how users can interact with it. Replacing the static image with a GIF is a nice touch that will make it easier for users to understand the feature.

tui/tui.go (5)

13-13: Import added correctly for fuzzy search functionality.

The import for the fuzzysearch package is properly added to support the implementation of the fuzzy search feature.


545-548: Simplified context and error handling.

The code now uses context.Background() directly, which is simpler and cleaner than creating a separate context variable. The error is also passed directly to showError without wrapping it, which is more consistent with the rest of the codebase.


555-574: Well-styled list component with proper theming.

The list styling is comprehensive and properly uses the theme colors from the application, which ensures consistency with the overall UI. The border, background, text, and selection styles are all appropriately configured.


602-647: Clean implementation of search input and keyboard navigation.

The search input field is well-integrated with the existing UI patterns. Key points:

  1. The keyboard navigation between search input and list using TAB is intuitive
  2. The layout with search input above the list follows standard patterns
  3. The focus behavior is properly implemented

The integration with the existing application flow (returning to the main UI) is also handled correctly.


592-598: Good use of closure to capture correct history item.

Using a closure to capture the correct history item is the right approach to avoid the common gotcha of loop variable capture in Go. This ensures that each list item correctly sets the corresponding SQL query.

Copy link

Code Metrics Report

main (df8b120) #32 (7b0b4c8) +/-
Coverage 34.7% 34.7% 0.0%
Test Execution Time 3s 2s -1s
Details
  |                     | main (df8b120) | #32 (7b0b4c8) | +/-  |
  |---------------------|----------------|---------------|------|
  | Coverage            |          34.7% |         34.7% | 0.0% |
  |   Files             |             27 |            27 |    0 |
  |   Lines             |            966 |           966 |    0 |
  |   Covered           |            336 |           336 |    0 |
+ | Test Execution Time |             3s |            2s |  -1s |

Reported by octocov

@nao1215 nao1215 merged commit 9346b68 into main Mar 24, 2025
10 checks passed
@nao1215 nao1215 deleted the nchika/fuzzy-find branch March 26, 2025 11:44
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.

1 participant