1- using System ;
1+ using JetBrains . Annotations ;
2+ using System ;
23using System . Collections . Generic ;
34using System . Linq ;
45
@@ -11,65 +12,74 @@ public Query() { }
1112 /// <summary>
1213 /// to allow unit tests for plug ins
1314 /// </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 = "" )
1516 {
1617 Search = search ;
1718 RawQuery = rawQuery ;
1819 Terms = terms ;
20+ SearchTerms = searchTerms ;
1921 ActionKeyword = actionKeyword ;
2022 }
2123
2224 /// <summary>
2325 /// Raw query, this includes action keyword if it has
2426 /// We didn't recommend use this property directly. You should always use Search property.
2527 /// </summary>
26- public string RawQuery { get ; internal set ; }
28+ public string RawQuery { get ; internal init ; }
2729
2830 /// <summary>
2931 /// Search part of a query.
3032 /// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
3133 /// Since we allow user to switch a exclusive plugin to generic plugin,
3234 /// so this property will always give you the "real" query part of the query
3335 /// </summary>
34- public string Search { get ; internal set ; }
36+ public string Search { get ; internal init ; }
3537
3638 /// <summary>
37- /// The raw query splited into a string array.
39+ /// The search string split into a string array.
3840 /// </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 ; }
4048
4149 /// <summary>
4250 /// Query can be splited into multiple terms by whitespace
4351 /// </summary>
44- public const string TermSeperater = " " ;
52+ public const string TermSeparator = " " ;
53+
54+ [ Obsolete ( "Typo" ) ]
55+ public const string TermSeperater = TermSeparator ;
4556 /// <summary>
4657 /// User can set multiple action keywords seperated by ';'
4758 /// </summary>
48- public const string ActionKeywordSeperater = ";" ;
59+ public const string ActionKeywordSeparator = ";" ;
60+
61+ [ Obsolete ( "Typo" ) ]
62+ public const string ActionKeywordSeperater = ActionKeywordSeparator ;
63+
4964
5065 /// <summary>
5166 /// '*' is used for System Plugin
5267 /// </summary>
5368 public const string GlobalPluginWildcardSign = "*" ;
5469
55- public string ActionKeyword { get ; set ; }
70+ public string ActionKeyword { get ; init ; }
5671
5772 /// <summary>
5873 /// Return first search split by space if it has
5974 /// </summary>
6075 public string FirstSearch => SplitSearch ( 0 ) ;
6176
77+ private string _secondToEndSearch ;
78+
6279 /// <summary>
6380 /// strings from second search (including) to last search
6481 /// </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 ..] ) ) : "" ;
7383
7484 /// <summary>
7585 /// Return second search split by space if it has
@@ -83,16 +93,9 @@ public string SecondToEndSearch
8393
8494 private string SplitSearch ( int index )
8595 {
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 ;
9497 }
9598
9699 public override string ToString ( ) => RawQuery ;
97100 }
98- }
101+ }
0 commit comments