PowerToys-Run-WebSearchShortcut icon indicating copy to clipboard operation
PowerToys-Run-WebSearchShortcut copied to clipboard

Inconsistent Search Engine Return Behavior with Space After Key Letter

Open DinMon opened this issue 7 months ago • 4 comments

When using the search functionality in the PowerToys Run WebSearchShortcut repository, there is an inconsistency in how search engines are returned based on user input. The expected behavior is that when a user specifies a key letter followed by a space, only the corresponding search engine should be returned. However, the current implementation does not adhere to this logic. Below are the scenarios illustrating the issue, along with the configuration of the search engines:

Search Engine Configuration:

{
  "Perplexity": {
    "Url": "https://www.perplexity.ai?q=%s",
    "Keyword": "p"
  },
  "Startpage": {
    "Url": "https://www.startpage.com/sp/search?query=%s",
    "Keyword": "s"
  },
  "Brave": {
    "Url": "https://search.brave.com/search?q=%s",
    "Keyword": "b"
  },
  "Youtube": {
    "Url": "https://www.youtube.com/results?search_query=%s",
    "Keyword": "y"
  },
  "Reddit": {
    "Url": "https://www.reddit.com/search/?q=%s",
    "Keyword": "r"
  },
  "StackOverflow": {
    "Url": "https://stackoverflow.com/search?q=%s",
    "Keyword": "so"
  }
}

Scenarios Illustrating the Issue:

  1. Scenario 1: s; y

    • Input: s; y
    • Expected Output: Only "YouTube" should be returned as the search engine.
    • Actual Output: Both "Perplexity" and "YouTube" are returned.
  2. Scenario 2: s; y (with a space after y)

    • Input: s; y
    • Expected Output: Only "YouTube" should be returned.
    • Actual Output: Both "Perplexity" and "YouTube" are returned.
  3. Scenario 3: s; y {query}

    • Input: s; y {query}
    • Expected Output: Only "YouTube" should be returned.
    • Actual Output: Only "YouTube" is returned as expected.

Original Code Snippet:

/// <summary>
/// Return a filtered list, based on the given query.
/// </summary>
/// <param name="query">The query to filter the list.</param>
/// <returns>A filtered list, can be empty when nothing was found.</returns>
public List<Result> Query(Query query)
{
    // ... existing code ...

    var tokens = args.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);

    if (tokens.Length == 1)
    {
        results.AddRange(WebSearchShortcutStorage.GetRecords(args).Select(x => GetResultForSelectOrOpen(x, args, query)));
    }

    var item = WebSearchShortcutStorage.GetRecord(tokens[0]);
    if (tokens.Length == 2 && item != null)
    {
        results.Add(GetResultForSearch(item, tokens[1], query));
        results.AddRange(SuggestionsCache);
    }
    // ... existing code ...
}

Summary of the Issue:

The search functionality currently returns multiple search engines when a key letter is followed by a space. For example, typing s; y or s; y should return only "YouTube," but it also returns "Perplexity." This inconsistency is confusing. The expected behavior in my opnion is that any input with a key letter followed by a space should yield only the corresponding search engine.

DinMon avatar Jul 22 '24 13:07 DinMon