-
-
Notifications
You must be signed in to change notification settings - Fork 617
Expand file tree
/
Copy pathQueryBuilder.cs
More file actions
63 lines (58 loc) · 2.1 KB
/
Copy pathQueryBuilder.cs
File metadata and controls
63 lines (58 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using Flow.Launcher.Plugin;
namespace Flow.Launcher.Core.Plugin
{
public static class QueryBuilder
{
public static Query Build(string originalQuery, string trimmedQuery, Dictionary<string, PluginPair> nonGlobalPlugins)
{
// home query
if (string.IsNullOrEmpty(trimmedQuery))
{
return new Query()
{
Search = string.Empty,
OriginalQuery = string.Empty,
TrimmedQuery = string.Empty,
SearchTerms = Array.Empty<string>(),
ActionKeyword = string.Empty,
IsHomeQuery = true
};
}
// replace multiple white spaces with one white space
var terms = trimmedQuery.Split(Query.TermSeparator, StringSplitOptions.RemoveEmptyEntries);
if (terms.Length == 0)
{
// nothing was typed
return null;
}
string actionKeyword, search;
string possibleActionKeyword = terms[0];
string[] searchTerms;
if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
{
// use non global plugin for query
actionKeyword = possibleActionKeyword;
search = terms.Length > 1 ? trimmedQuery[(actionKeyword.Length + 1)..].TrimStart() : string.Empty;
searchTerms = terms[1..];
}
else
{
// non action keyword
actionKeyword = string.Empty;
search = trimmedQuery.TrimStart();
searchTerms = terms;
}
return new Query()
{
Search = search,
OriginalQuery = originalQuery,
TrimmedQuery = trimmedQuery,
SearchTerms = searchTerms,
ActionKeyword = actionKeyword,
IsHomeQuery = false
};
}
}
}