Flow.Launcher/Flow.Launcher.Plugin/Query.cs

101 lines
3.3 KiB
C#
Raw Permalink Normal View History

using JetBrains.Annotations;
using System;
using System.Collections.Generic;
2015-10-31 16:02:56 +00:00
using System.Linq;
2013-12-19 15:51:20 +00:00
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Plugin
2013-12-19 15:51:20 +00:00
{
public class Query
{
2020-03-02 01:22:26 +00:00
public Query() { }
2019-10-17 09:19:52 +00:00
/// <summary>
/// to allow unit tests for plug ins
/// </summary>
public Query(string rawQuery, string search, string[] terms, string[] searchTerms, string actionKeyword = "")
2019-10-17 09:19:52 +00:00
{
Search = search;
RawQuery = rawQuery;
2021-09-21 02:51:07 +00:00
Terms = terms;
SearchTerms = searchTerms;
2019-10-17 09:19:52 +00:00
ActionKeyword = actionKeyword;
}
/// <summary>
/// Raw query, this includes action keyword if it has
/// We didn't recommend use this property directly. You should always use Search property.
/// </summary>
public string RawQuery { get; internal init; }
/// <summary>
/// Search part of a query.
2015-02-06 10:13:22 +00:00
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
2015-10-31 16:02:56 +00:00
/// 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; }
2015-10-31 16:02:56 +00:00
/// <summary>
/// The search string split into a string array.
2015-10-31 16:02:56 +00:00
/// </summary>
public string[] SearchTerms { get; init; }
2021-09-21 02:51:07 +00:00
/// <summary>
/// The raw query split into a string array
/// </summary>
[Obsolete("It may or may not include action keyword, which can be confusing. Use SearchTerms instead")]
public string[] Terms { get; init; }
/// <summary>
/// Query can be splited into multiple terms by whitespace
/// </summary>
public const string TermSeparator = " ";
[Obsolete("Typo")]
public const string TermSeperater = TermSeparator;
/// <summary>
/// User can set multiple action keywords seperated by ';'
/// </summary>
public const string ActionKeywordSeparator = ";";
2021-09-21 02:51:07 +00:00
[Obsolete("Typo")]
public const string ActionKeywordSeperater = ActionKeywordSeparator;
2015-10-31 16:02:56 +00:00
2015-11-02 00:09:42 +00:00
/// <summary>
/// '*' is used for System Plugin
2015-11-02 00:09:42 +00:00
/// </summary>
public const string GlobalPluginWildcardSign = "*";
2015-11-02 00:09:42 +00:00
public string ActionKeyword { get; init; }
/// <summary>
/// Return first search split by space if it has
/// </summary>
2015-10-31 16:02:56 +00:00
public string FirstSearch => SplitSearch(0);
private string _secondToEndSearch;
/// <summary>
/// strings from second search (including) to last search
/// </summary>
public string SecondToEndSearch => SearchTerms.Length > 1 ? (_secondToEndSearch ??= string.Join(' ', SearchTerms[1..])) : "";
/// <summary>
/// Return second search split by space if it has
/// </summary>
2015-10-31 16:02:56 +00:00
public string SecondSearch => SplitSearch(1);
/// <summary>
/// Return third search split by space if it has
/// </summary>
2015-10-31 16:02:56 +00:00
public string ThirdSearch => SplitSearch(2);
private string SplitSearch(int index)
{
return index < SearchTerms.Length ? SearchTerms[index] : string.Empty;
}
2015-10-31 16:02:56 +00:00
public override string ToString() => RawQuery;
2013-12-19 15:51:20 +00:00
}
}