using JetBrains.Annotations; using System; using System.Collections.Generic; using System.Linq; namespace Flow.Launcher.Plugin { public class Query { public Query() { } /// /// to allow unit tests for plug ins /// public Query(string rawQuery, string search, string[] terms, string actionKeyword = "") { Search = search; RawQuery = rawQuery; Terms = terms; ActionKeyword = actionKeyword; } /// /// Raw query, this includes action keyword if it has /// We didn't recommend use this property directly. You should always use Search property. /// public string RawQuery { get; internal init; } /// /// Search part of a query. /// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery. /// 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 /// public string Search { get; internal init; } /// /// The raw query splited into a string array. /// public string[] Terms { get; init; } /// /// Query can be splited into multiple terms by whitespace /// public const string TermSeparator = " "; /// /// User can set multiple action keywords seperated by ';' /// public const string ActionKeywordSeparator = ";"; /// /// '*' is used for System Plugin /// public const string GlobalPluginWildcardSign = "*"; public string ActionKeyword { get; init; } /// /// Return first search split by space if it has /// public string FirstSearch => SplitSearch(0); private string _secondToEndSearch; /// /// strings from second search (including) to last search /// public string SecondToEndSearch => _secondToEndSearch ??= string.Join(' ', Terms.AsMemory(2)); /// /// Return second search split by space if it has /// public string SecondSearch => SplitSearch(1); /// /// Return third search split by space if it has /// public string ThirdSearch => SplitSearch(2); private string SplitSearch(int index) { return index < Terms.Length ? Terms[index] : string.Empty; } public override string ToString() => RawQuery; } }