Skip to content
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

Inconsistent Search Engine Return Behavior with Space After Key Letter #24

Closed
DinMon opened this issue Jul 22, 2024 · 4 comments
Closed

Comments

@DinMon
Copy link

DinMon commented Jul 22, 2024

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.

@Daydreamer-riri
Copy link
Owner

Hi @DinMon , thank you for the Issue. Regarding trailing spaces related issues, I have tried this before, and at that time I came to the conclusion that Powertoys Run had removed trailing spaces when it passed the user's input to me, and I had no way of knowing whether or not the user had typed a space after the last letter.

But regarding Scenario 1 you mentioned, do you think we should only show the corresponding search engine when the user inputs a word that exactly matches a search engine, instead of matching all search engines normally? I think this is achievable.

@DinMon
Copy link
Author

DinMon commented Jul 23, 2024

Hi @Daydreamer-riri, I think it will be good to use StartWith in GetRecords(string query) in Storage.cs instead of Contains. Yeah coming back to your question, in my opnion, you don't need to see Perplexity because it contains 'y' keywords in it but rather the options that the query start with.
/

@Daydreamer-riri
Copy link
Owner

I think it will be good to use StartWith in GetRecords(string query) in Storage.cs instead of Contains.

In most search scenarios, the search behavior is Contains. For example, in everything, or file search in vscode. Sometimes I don't remember the exact spelling of the target, but I remember a few letters, which can help me find it.

For cases of exact match, I think it might be better to prioritize the exact match results to the highest weight and make them the first item.

@DinMon
Copy link
Author

DinMon commented Jul 25, 2024

Yes, I think changing the weight is a good way to resolve the issue.

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

No branches or pull requests

2 participants