[PT Run] Results only for plugin with longest matching activation phrase (#15132)

* first try to fix with new idea

* small changes

* [PT Run] Updated QuryBuilder unit tests

* [PT Run] Updated QueryBuilder test

* [PT Run] Updated QueryBuilder test name

* Improvements

* Improve readability of test

* Improve Query-Tests for spellcheck

* clean expect.txt

Co-authored-by: cyberrex5 <ghassanjad2004@gmail.com>
This commit is contained in:
Heiko
2021-12-27 17:00:07 +01:00
committed by GitHub
parent 7ac7e48e66
commit 979d3c6011
3 changed files with 52 additions and 28 deletions

View File

@@ -18,20 +18,37 @@ namespace PowerLauncher.Plugin
}
text = text.Trim();
int longestActionKeywordLength = 0;
// This Dictionary contains the corresponding query for each plugin
Dictionary<PluginPair, Query> pluginQueryPair = new Dictionary<PluginPair, Query>();
foreach (var plugin in PluginManager.NonGlobalPlugins)
foreach (var nonGlobalPlugin in PluginManager.NonGlobalPlugins)
{
var pluginActionKeyword = plugin.Metadata.ActionKeyword;
if (plugin.Metadata.Disabled || !text.StartsWith(pluginActionKeyword, StringComparison.Ordinal))
var pluginActionKeyword = nonGlobalPlugin.Metadata.ActionKeyword;
if (nonGlobalPlugin.Metadata.Disabled || !text.StartsWith(pluginActionKeyword, StringComparison.Ordinal))
{
continue;
}
// Save the length of the longest matching keyword for later use
if (pluginActionKeyword.Length > longestActionKeywordLength)
{
longestActionKeywordLength = pluginActionKeyword.Length;
}
// A new query is constructed for each plugin
var query = new Query(text, pluginActionKeyword);
pluginQueryPair.TryAdd(plugin, query);
pluginQueryPair.TryAdd(nonGlobalPlugin, query);
}
// If we have plugin action keywords that start with the same char we get false positives (Example: ? and ??)
// Here we remove each query pair that has a shorter keyword than the longest matching one
foreach (PluginPair plugin in pluginQueryPair.Keys)
{
if (plugin.Metadata.ActionKeyword.Length < longestActionKeywordLength)
{
pluginQueryPair.Remove(plugin);
}
}
// If the user has specified a matching action keyword, then do not