2015-01-26 17:46:55 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2015-11-01 00:02:56 +08:00
|
|
|
|
using System.Linq;
|
2013-12-19 23:51:20 +08:00
|
|
|
|
|
2014-01-29 18:33:24 +08:00
|
|
|
|
namespace Wox.Plugin
|
2013-12-19 23:51:20 +08:00
|
|
|
|
{
|
|
|
|
|
public class Query
|
|
|
|
|
{
|
2019-10-17 17:19:52 +08:00
|
|
|
|
internal Query() { }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// to allow unit tests for plug ins
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Query(string rawQuery, string search, string[] terms, string actionKeyword = null)
|
|
|
|
|
{
|
|
|
|
|
Search = search;
|
|
|
|
|
RawQuery = rawQuery;
|
|
|
|
|
Terms = terms;
|
|
|
|
|
ActionKeyword = actionKeyword;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-26 17:46:55 +08:00
|
|
|
|
/// <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>
|
2015-11-03 13:09:54 +08:00
|
|
|
|
public string RawQuery { get; internal set; }
|
2015-01-26 17:46:55 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Search part of a query.
|
2015-02-06 18:13:22 +08:00
|
|
|
|
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
|
2015-11-01 00:02:56 +08: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
|
2015-01-26 17:46:55 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string Search { get; internal set; }
|
|
|
|
|
|
2015-11-01 00:02:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The raw query splited into a string array.
|
|
|
|
|
/// </summary>
|
2015-11-06 06:47:28 +08:00
|
|
|
|
public string[] Terms { get; set; }
|
2015-01-26 17:46:55 +08:00
|
|
|
|
|
2015-11-06 04:44:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Query can be splited into multiple terms by whitespace
|
|
|
|
|
/// </summary>
|
2015-11-05 06:49:40 +08:00
|
|
|
|
public const string TermSeperater = " ";
|
2015-11-06 04:44:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// User can set multiple action keywords seperated by ';'
|
|
|
|
|
/// </summary>
|
2015-11-05 06:49:40 +08:00
|
|
|
|
public const string ActionKeywordSeperater = ";";
|
2015-11-01 00:02:56 +08:00
|
|
|
|
|
2015-11-02 08:09:42 +08:00
|
|
|
|
/// <summary>
|
2015-11-06 04:44:14 +08:00
|
|
|
|
/// '*' is used for System Plugin
|
2015-11-02 08:09:42 +08:00
|
|
|
|
/// </summary>
|
2015-11-06 04:44:14 +08:00
|
|
|
|
public const string GlobalPluginWildcardSign = "*";
|
2015-11-02 08:09:42 +08:00
|
|
|
|
|
2015-11-05 06:49:40 +08:00
|
|
|
|
public string ActionKeyword { get; set; }
|
2015-01-26 17:46:55 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Return first search split by space if it has
|
|
|
|
|
/// </summary>
|
2015-11-01 00:02:56 +08:00
|
|
|
|
public string FirstSearch => SplitSearch(0);
|
2015-01-26 17:46:55 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// strings from second search (including) to last search
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string SecondToEndSearch
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2015-11-05 06:49:40 +08:00
|
|
|
|
var index = string.IsNullOrEmpty(ActionKeyword) ? 1 : 2;
|
|
|
|
|
return string.Join(TermSeperater, Terms.Skip(index).ToArray());
|
2015-01-26 17:46:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Return second search split by space if it has
|
|
|
|
|
/// </summary>
|
2015-11-01 00:02:56 +08:00
|
|
|
|
public string SecondSearch => SplitSearch(1);
|
2015-01-26 17:46:55 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Return third search split by space if it has
|
|
|
|
|
/// </summary>
|
2015-11-01 00:02:56 +08:00
|
|
|
|
public string ThirdSearch => SplitSearch(2);
|
2015-01-26 17:46:55 +08:00
|
|
|
|
|
|
|
|
|
private string SplitSearch(int index)
|
|
|
|
|
{
|
2015-11-01 00:02:56 +08:00
|
|
|
|
try
|
2015-01-26 17:46:55 +08:00
|
|
|
|
{
|
2015-11-05 06:49:40 +08:00
|
|
|
|
return string.IsNullOrEmpty(ActionKeyword) ? Terms[index] : Terms[index + 1];
|
2015-11-01 00:02:56 +08:00
|
|
|
|
}
|
|
|
|
|
catch (IndexOutOfRangeException)
|
|
|
|
|
{
|
2015-11-05 06:49:40 +08:00
|
|
|
|
return string.Empty;
|
2015-01-26 17:46:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-01 00:02:56 +08:00
|
|
|
|
public override string ToString() => RawQuery;
|
2015-01-26 17:46:55 +08:00
|
|
|
|
|
2015-11-05 06:49:40 +08:00
|
|
|
|
[Obsolete("Use ActionKeyword, this property will be removed in v1.3.0")]
|
2015-11-03 13:09:54 +08:00
|
|
|
|
public string ActionName { get; internal set; }
|
2015-01-26 17:46:55 +08:00
|
|
|
|
|
|
|
|
|
[Obsolete("Use Search instead, this property will be removed in v1.3.0")]
|
2015-11-03 13:09:54 +08:00
|
|
|
|
public List<string> ActionParameters { get; internal set; }
|
2014-02-28 23:21:01 +08:00
|
|
|
|
|
2015-01-26 17:46:55 +08:00
|
|
|
|
[Obsolete("Use Search instead, this method will be removed in v1.3.0")]
|
2015-11-03 13:09:54 +08:00
|
|
|
|
public string GetAllRemainingParameter() => Search;
|
2013-12-19 23:51:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|