2023-06-24 14:15:36 +00:00
|
|
|
using System;
|
2020-02-22 09:02:07 +00:00
|
|
|
using System.Collections.Generic;
|
2020-04-21 09:12:17 +00:00
|
|
|
using Flow.Launcher.Plugin;
|
2020-02-22 09:02:07 +00:00
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
namespace Flow.Launcher.Core.Plugin
|
2020-02-22 09:02:07 +00:00
|
|
|
{
|
|
|
|
|
public static class QueryBuilder
|
|
|
|
|
{
|
|
|
|
|
public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalPlugins)
|
|
|
|
|
{
|
|
|
|
|
// replace multiple white spaces with one white space
|
2021-09-07 22:07:21 +00:00
|
|
|
var terms = text.Split(Query.TermSeparator, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
if (terms.Length == 0)
|
2020-02-22 09:02:07 +00:00
|
|
|
{ // nothing was typed
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-10 09:36:46 +00:00
|
|
|
var rawQuery = text;
|
2020-02-22 09:02:07 +00:00
|
|
|
string actionKeyword, search;
|
2021-09-07 22:07:21 +00:00
|
|
|
string possibleActionKeyword = terms[0];
|
|
|
|
|
string[] searchTerms;
|
2021-09-06 17:31:07 +00:00
|
|
|
|
2020-02-22 09:02:07 +00:00
|
|
|
if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
|
|
|
|
|
{ // use non global plugin for query
|
|
|
|
|
actionKeyword = possibleActionKeyword;
|
2022-04-10 12:42:54 +00:00
|
|
|
search = terms.Length > 1 ? rawQuery[(actionKeyword.Length + 1)..].TrimStart() : string.Empty;
|
2021-09-07 22:07:21 +00:00
|
|
|
searchTerms = terms[1..];
|
2020-02-22 09:02:07 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // non action keyword
|
|
|
|
|
actionKeyword = string.Empty;
|
2022-04-10 12:42:54 +00:00
|
|
|
search = rawQuery.TrimStart();
|
2021-09-07 22:07:21 +00:00
|
|
|
searchTerms = terms;
|
2020-02-22 09:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 14:15:36 +00:00
|
|
|
return new Query ()
|
|
|
|
|
{
|
|
|
|
|
Search = search,
|
|
|
|
|
RawQuery = rawQuery,
|
|
|
|
|
SearchTerms = searchTerms,
|
|
|
|
|
ActionKeyword = actionKeyword
|
|
|
|
|
};
|
2020-02-22 09:02:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|