-
-
Notifications
You must be signed in to change notification settings - Fork 381
Improve windows index search with special character #3119
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.
See ❌ Event descriptions for more information. If the flagged items are 🤯 false positivesIf items relate to a ...
|
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
📝 WalkthroughWalkthroughThe changes in this pull request focus on enhancing the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/QueryConstructor.cs (1)
90-115
: Optimize the special character replacement method.While the implementation is functional, it could be improved in several ways:
- Reduce string allocations by using
Span<char>
more effectively- Add input validation
- Simplify the whitespace checking logic
- Consider a more concise name like
SanitizeSpecialCharacters
- private static string ReplaceSpecialCharacterWithTwoSideWhiteSpace(ReadOnlySpan<char> input) + private static string SanitizeSpecialCharacters(ReadOnlySpan<char> input) { + if (input.IsEmpty) + return string.Empty; + const string whiteSpace = " "; - - var inputString = input.ToString(); + var inputString = input.ToString(); // Required for Regex operations // Use regex to match special characters with whitespace on one side // and replace them with a single space var result = _specialCharacterMatcher.Replace(inputString, match => { - // Check if the match has whitespace on one side - bool hasLeadingWhitespace = match.Index > 0 && char.IsWhiteSpace(inputString[match.Index - 1]); - bool hasTrailingWhitespace = match.Index + match.Length < inputString.Length && char.IsWhiteSpace(inputString[match.Index + match.Length]); - if (hasLeadingWhitespace || hasTrailingWhitespace) - { - return whiteSpace; - } - return match.Value; + // Replace special character with space if it has whitespace on either side + return (match.Index > 0 && char.IsWhiteSpace(inputString[match.Index - 1])) || + (match.Index + match.Length < inputString.Length && char.IsWhiteSpace(inputString[match.Index + match.Length])) + ? whiteSpace + : match.Value; }); // Remove any extra spaces that might have been introduced return _multiWhiteSpacesMatcher.Replace(result, whiteSpace).Trim(); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/QueryConstructor.cs
(2 hunks)
🔇 Additional comments (2)
Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/QueryConstructor.cs (2)
83-88
: LGTM! Clean integration of special character handling.
The changes effectively integrate the special character sanitization while maintaining the existing input validation logic.
83-115
: Verify the special character handling implementation.
Let's ensure the changes handle special characters correctly and maintain existing functionality.
Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/QueryConstructor.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the well written PR 👍
PR
Improve windows index search with special character like
\@\@\#\#\&\&*_;,\%\|\!\(\)\{\}\[\]\^\~\?\\""\/\:\=\-
.If you type
Zotero & Obsidian
in search bar, the command will look like this:And
"&*"
can cause issue like this:So the outcome of windows index will be empty.
In this PR,
ReplaceSpecialCharacterWithTwoSideWhiteSpace
can handle those special character with white space on one side.So
"[special character]*"
will not exist in the command and windows index can work in that occasion.Test
Original:




After: