-
-
Notifications
You must be signed in to change notification settings - Fork 600
Expand file tree
/
Copy pathQuery.cs
More file actions
127 lines (109 loc) · 4.96 KB
/
Query.cs
File metadata and controls
127 lines (109 loc) · 4.96 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Text.Json.Serialization;
namespace Flow.Launcher.Plugin
{
/// <summary>
/// Represents a query that is sent to a plugin.
/// </summary>
public class Query
{
/// <summary>
/// Original query, exactly how the user has typed into the search box.
/// We don't recommend using this property directly. You should always use Search property.
/// </summary>
public string OriginalQuery { get; internal init; }
/// <summary>
/// Raw query, this includes action keyword if it has.
/// It has handled built-in custom query hotkeys and built-in shortcuts, and it trims the whitespace.
/// We don't recommend using this property directly. You should always use Search property.
/// </summary>
[Obsolete("RawQuery is renamed to TrimmedQuery. This property will be removed. Update the code to use TrimmedQuery instead.")]
public string RawQuery {
get => TrimmedQuery;
internal init { TrimmedQuery = value; }
}
/// <summary>
/// Original query but with trimmed whitespace. Includes action keyword.
/// It has handled built-in custom query hotkeys and build-in shortcuts.
/// If you need the exact original query from the search box, use OriginalQuery property instead.
/// We don't recommend using this property directly. You should always use Search property.
/// </summary>
public string TrimmedQuery { get; internal init; }
/// <summary>
/// Determines whether the query was forced to execute again.
/// For example, the value will be true when the user presses Ctrl + R.
/// When this property is true, plugins handling this query should avoid serving cached results.
/// </summary>
public bool IsReQuery { get; internal set; } = false;
/// <summary>
/// Determines whether the query is a home query.
/// </summary>
public bool IsHomeQuery { get; internal init; } = false;
/// <summary>
/// Search part of a query.
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as TrimmedQuery.
/// Since we allow user to switch a exclusive plugin to generic plugin,
/// so this property will always give you the "real" query part of the query
/// </summary>
public string Search { get; internal init; }
/// <summary>
/// The search string split into a string array.
/// Does not include the <see cref="ActionKeyword"/>.
/// </summary>
public string[] SearchTerms { get; init; }
/// <summary>
/// Query can be splited into multiple terms by whitespace
/// </summary>
public const string TermSeparator = " ";
/// <summary>
/// User can set multiple action keywords seperated by whitespace
/// </summary>
public const string ActionKeywordSeparator = TermSeparator;
/// <summary>
/// Wildcard action keyword. Plugins using this value will be queried on every search.
/// </summary>
public const string GlobalPluginWildcardSign = "*";
/// <summary>
/// The action keyword part of this query.
/// For global plugins this value will be empty.
/// </summary>
public string ActionKeyword { get; init; }
/// <summary>
/// Splits <see cref="SearchTerms"/> by spaces and returns the first item.
/// </summary>
/// <remarks>
/// returns an empty string when <see cref="SearchTerms"/> does not have enough items.
/// </remarks>
[JsonIgnore]
public string FirstSearch => SplitSearch(0);
[JsonIgnore]
private string _secondToEndSearch;
/// <summary>
/// strings from second search (including) to last search
/// </summary>
[JsonIgnore]
public string SecondToEndSearch => SearchTerms.Length > 1 ? (_secondToEndSearch ??= string.Join(' ', SearchTerms[1..])) : "";
/// <summary>
/// Splits <see cref="SearchTerms"/> by spaces and returns the second item.
/// </summary>
/// <remarks>
/// returns an empty string when <see cref="SearchTerms"/> does not have enough items.
/// </remarks>
[JsonIgnore]
public string SecondSearch => SplitSearch(1);
/// <summary>
/// Splits <see cref="SearchTerms"/> by spaces and returns the third item.
/// </summary>
/// <remarks>
/// returns an empty string when <see cref="SearchTerms"/> does not have enough items.
/// </remarks>
[JsonIgnore]
public string ThirdSearch => SplitSearch(2);
private string SplitSearch(int index)
{
return index < SearchTerms.Length ? SearchTerms[index] : string.Empty;
}
/// <inheritdoc />
public override string ToString() => TrimmedQuery;
}
}