1
- using System ;
1
+ using JetBrains . Annotations ;
2
+ using System ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
@@ -11,65 +12,74 @@ public Query() { }
11
12
/// <summary>
12
13
/// to allow unit tests for plug ins
13
14
/// </summary>
14
- public Query ( string rawQuery , string search , string [ ] terms , string actionKeyword = "" )
15
+ public Query ( string rawQuery , string search , string [ ] terms , string [ ] searchTerms , string actionKeyword = "" )
15
16
{
16
17
Search = search ;
17
18
RawQuery = rawQuery ;
18
19
Terms = terms ;
20
+ SearchTerms = searchTerms ;
19
21
ActionKeyword = actionKeyword ;
20
22
}
21
23
22
24
/// <summary>
23
25
/// Raw query, this includes action keyword if it has
24
26
/// We didn't recommend use this property directly. You should always use Search property.
25
27
/// </summary>
26
- public string RawQuery { get ; internal set ; }
28
+ public string RawQuery { get ; internal init ; }
27
29
28
30
/// <summary>
29
31
/// Search part of a query.
30
32
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
31
33
/// Since we allow user to switch a exclusive plugin to generic plugin,
32
34
/// so this property will always give you the "real" query part of the query
33
35
/// </summary>
34
- public string Search { get ; internal set ; }
36
+ public string Search { get ; internal init ; }
35
37
36
38
/// <summary>
37
- /// The raw query splited into a string array.
39
+ /// The search string split into a string array.
38
40
/// </summary>
39
- public string [ ] Terms { get ; set ; }
41
+ public string [ ] SearchTerms { get ; init ; }
42
+
43
+ /// <summary>
44
+ /// The raw query split into a string array
45
+ /// </summary>
46
+ [ Obsolete ( "It may or may not include action keyword, which can be confusing. Use SearchTerms instead" ) ]
47
+ public string [ ] Terms { get ; init ; }
40
48
41
49
/// <summary>
42
50
/// Query can be splited into multiple terms by whitespace
43
51
/// </summary>
44
- public const string TermSeperater = " " ;
52
+ public const string TermSeparator = " " ;
53
+
54
+ [ Obsolete ( "Typo" ) ]
55
+ public const string TermSeperater = TermSeparator ;
45
56
/// <summary>
46
57
/// User can set multiple action keywords seperated by ';'
47
58
/// </summary>
48
- public const string ActionKeywordSeperater = ";" ;
59
+ public const string ActionKeywordSeparator = ";" ;
60
+
61
+ [ Obsolete ( "Typo" ) ]
62
+ public const string ActionKeywordSeperater = ActionKeywordSeparator ;
63
+
49
64
50
65
/// <summary>
51
66
/// '*' is used for System Plugin
52
67
/// </summary>
53
68
public const string GlobalPluginWildcardSign = "*" ;
54
69
55
- public string ActionKeyword { get ; set ; }
70
+ public string ActionKeyword { get ; init ; }
56
71
57
72
/// <summary>
58
73
/// Return first search split by space if it has
59
74
/// </summary>
60
75
public string FirstSearch => SplitSearch ( 0 ) ;
61
76
77
+ private string _secondToEndSearch ;
78
+
62
79
/// <summary>
63
80
/// strings from second search (including) to last search
64
81
/// </summary>
65
- public string SecondToEndSearch
66
- {
67
- get
68
- {
69
- var index = string . IsNullOrEmpty ( ActionKeyword ) ? 1 : 2 ;
70
- return string . Join ( TermSeperater , Terms . Skip ( index ) . ToArray ( ) ) ;
71
- }
72
- }
82
+ public string SecondToEndSearch => SearchTerms . Length > 1 ? ( _secondToEndSearch ??= string . Join ( ' ' , SearchTerms [ 1 ..] ) ) : "" ;
73
83
74
84
/// <summary>
75
85
/// Return second search split by space if it has
@@ -83,16 +93,9 @@ public string SecondToEndSearch
83
93
84
94
private string SplitSearch ( int index )
85
95
{
86
- try
87
- {
88
- return string . IsNullOrEmpty ( ActionKeyword ) ? Terms [ index ] : Terms [ index + 1 ] ;
89
- }
90
- catch ( IndexOutOfRangeException )
91
- {
92
- return string . Empty ;
93
- }
96
+ return index < SearchTerms . Length ? SearchTerms [ index ] : string . Empty ;
94
97
}
95
98
96
99
public override string ToString ( ) => RawQuery ;
97
100
}
98
- }
101
+ }
0 commit comments