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

BUG: Query Results Ranking Issue for Plugins #2904

Closed
2 tasks done
Jack251970 opened this issue Aug 18, 2024 · 3 comments
Closed
2 tasks done

BUG: Query Results Ranking Issue for Plugins #2904

Jack251970 opened this issue Aug 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Jack251970
Copy link
Contributor

Checks

  • I have checked that this issue has not already been reported.

  • I am using the latest version of Flow Launcher.

Problem Description

I have developed a plugin, and I seem to meet some issue with the ranking sequence of the query results.

I implement the IAsyncPlugin interface and when I load clear actions, the ranking sequence of the items is like this.

image

These are my C# codes, I have set the score of the clear list item to 4, but the item is on the bottom instead of the top?🧐

public Task<List<Result>> QueryAsync(Query query, CancellationToken token)
{
    return Task.Run(() => Query(query));
}

public List<Result> Query(Query query)
{
    var results = new List<Result>();

    if (query.FirstSearch == Settings.ClearKeyword)
    {
        // clear actions
        results.AddRange(
            new[]
            {
                // clear list item
                new Result
                {
                    Title = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_list_title"),
                    SubTitle = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_list_subtitle"),
                    IcoPath = PathHelper.ListIconPath,
                    Glyph = ResourceHelper.ListGlyph,
                    Score = 4,
                    Action = _ =>
                    {
                        var number = DeleteAllRecordsFromList();
                        if (number != 0)
                        {
                            Context.API.ShowMsg(Context.GetTranslation("flowlauncher_plugin_clipboardplus_success"),
                                string.Format(
                                    Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_list_msg_subtitle"), number));
                            return true;
                        }
                        else
                        {
                            Context.API.ShowMsg(Context.GetTranslation("flowlauncher_plugin_clipboardplus_success"),
                                Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_fail_msg_subtitle"));
                            return false;
                        }
                    },
                },

                // clear both item
                new Result
                {
                    Title = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_both_title"),
                    SubTitle = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_both_subtitle"),
                    IcoPath = PathHelper.DatabaseIconPath,
                    Glyph = ResourceHelper.DatabaseGlyph,
                    Score = 3,
                    AsyncAction = async _ =>
                    {
                        var number = await DeleteAllRecordsFromListDatabaseAsync();
                        if (number != 0)
                        {
                            Context.API.ShowMsg(Context.GetTranslation("flowlauncher_plugin_clipboardplus_success"),
                                string.Format(
                                    Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_both_msg_subtitle"), number));
                            return true;
                        }
                        else
                        {
                            Context.API.ShowMsg(Context.GetTranslation("flowlauncher_plugin_clipboardplus_success"),
                                Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_fail_msg_subtitle"));
                            return false;
                        }
                    }
                },

                // clear pinned item
                new Result
                {
                    Title = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_unpin_title"),
                    SubTitle = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_unpin_subtitle"),
                    IcoPath = PathHelper.UnpinIcon1Path,
                    Glyph = ResourceHelper.UnpinGlyph,
                    Score = 2,
                    AsyncAction = async _ =>
                    {
                        var number = await DeleteUnpinnedRecordsFromListDatabaseAsync();
                        if (number != 0)
                        {
                            Context.API.ShowMsg(Context.GetTranslation("flowlauncher_plugin_clipboardplus_success"),
                                string.Format(
                                    Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_unpin_msg_subtitle"), number));
                            return true;
                        }
                        else
                        {
                            Context.API.ShowMsg(Context.GetTranslation("flowlauncher_plugin_clipboardplus_success"),
                                Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_fail_msg_subtitle"));
                            return false;
                        }
                    }
                },

                // clear invalid item
                new Result
                {
                    Title = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_invalid_title"),
                    SubTitle = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_invalid_subtitle"),
                    IcoPath = PathHelper.ErrorIconPath,
                    Glyph = ResourceHelper.ErrorGlyph,
                    Score = 1,
                    AsyncAction = async _ =>
                    {
                        var number = await DeleteInvalidRecordsFromListDatabaseAsync();
                        if (number != 0)
                        {
                            Context.API.ShowMsg(Context.GetTranslation("flowlauncher_plugin_clipboardplus_success"),
                                string.Format(
                                    Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_invalid_msg_subtitle"), number));
                            return true;
                        }
                        else
                        {
                            Context.API.ShowMsg(Context.GetTranslation("flowlauncher_plugin_clipboardplus_success"),
                                Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_fail_msg_subtitle"));
                            return false;
                        }
                    }
                }
            }
        );
    }
    else
    {
        // clear action
        results.Add(
            new Result
            {
                Title = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_title"),
                SubTitle = Context.GetTranslation("flowlauncher_plugin_clipboardplus_clear_subtitle"),
                IcoPath = PathHelper.ClearIconPath,
                Glyph = ResourceHelper.ClearGlyph,
                Score = SettingsViewModel.MaximumMaxRecords + 1,
                Action = _ =>
                {
                    Context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ClearKeyword} ", true);
                    return false;
                },
            }
        );

        // records results
        ...
    }
    return results;
}

I really don't know why this issue happens.

To Reproduce

No response

Screenshots

No response

Flow Launcher Version

1.19.0

Windows Build Number

10.0.22631.4037

Error Log

No response

@Jack251970 Jack251970 added the bug Something isn't working label Aug 18, 2024
@jjw24
Copy link
Member

jjw24 commented Aug 18, 2024

Try setting them a bit further apart, 50, 100, 150 so on. Flow itself will also add to the score based on the frequency of the result used.

@Jack251970
Copy link
Contributor Author

Thanks, I get it.

@jjw24
Copy link
Member

jjw24 commented Dec 24, 2024

Feature is now available in prerelease. Can turn selection count off via result class. #3144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants