Class QueryEngine<TData>
A QueryEngine defines how to build a query from an input string. It can be customized to support custom filters and operators.
Namespace: UnityEditor.Search
Syntax
public class QueryEngine<TData>
Type Parameters
Name | Description |
---|---|
TData | The filtered data type. |
Constructors
QueryEngine()
Construct a new QueryEngine.
Declaration
public QueryEngine()
QueryEngine(Boolean)
Construct a new QueryEngine.
Declaration
public QueryEngine(bool validateFilters)
Parameters
Type | Name | Description |
---|---|---|
Boolean | validateFilters | Indicates if the engine must validate filters when parsing the query. |
QueryEngine(QueryValidationOptions)
Construct a new QueryEngine with the specified validation options.
Declaration
public QueryEngine(QueryValidationOptions validationOptions)
Parameters
Type | Name | Description |
---|---|---|
QueryValidationOptions | validationOptions | The validation options to use in this engine. |
Properties
globalStringComparison
Global string comparison options for word matching and filter handling (if not overridden).
Declaration
public StringComparison globalStringComparison { get; }
Property Value
Type | Description |
---|---|
StringComparison |
searchDataCallback
The callback used to get the data to match to the search words.
Declaration
public Func<TData, IEnumerable<string>> searchDataCallback { get; }
Property Value
Type | Description |
---|---|
Func<TData, IEnumerable<String>> |
searchDataOverridesStringComparison
Indicates if word/phrase matching uses searchDataStringComparison or not.
Declaration
public bool searchDataOverridesStringComparison { get; }
Property Value
Type | Description |
---|---|
Boolean |
searchDataStringComparison
String comparison options for word/phrase matching.
Declaration
public StringComparison searchDataStringComparison { get; }
Property Value
Type | Description |
---|---|
StringComparison |
searchWordMatcher
The function used to match the search data against the search words.
Declaration
public Func<string, bool, StringComparison, string, bool> searchWordMatcher { get; }
Property Value
Type | Description |
---|---|
Func<String, Boolean, StringComparison, String, Boolean> |
skipIncompleteFilters
Boolean indicating if incomplete filters should be skipped. If skipIncompleteFilters is false, incomplete filters will generate errors when parsed.
Declaration
public bool skipIncompleteFilters { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
skipUnknownFilters
Boolean indicating if unknown filters should be skipped. If validateFilters is true and skipUnknownFilters is false, unknown filters will generate errors if no default handler is provided.
Declaration
public bool skipUnknownFilters { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
validateFilters
Get of set if the engine must validate filters when parsing the query. Defaults to true.
Declaration
public bool validateFilters { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
AddFilter<TFilter>(Regex, Func<TData, String, TFilter>, String[])
Add a new custom filter.
Declaration
public IQueryEngineFilter AddFilter<TFilter>(Regex token, Func<TData, string, TFilter> getDataFunc, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The regular expression that matches the filter. Matches what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData, a string representing the actual filter name that was matched and returns an object of type TFilter. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Returns
Type | Description |
---|---|
IQueryEngineFilter |
Type Parameters
Name | Description |
---|---|
TFilter | The type of the data that is compared by the filter. |
AddFilter<TFilter>(Regex, Func<TData, String, TFilter>, StringComparison, String[])
Add a new custom filter.
Declaration
public IQueryEngineFilter AddFilter<TFilter>(Regex token, Func<TData, string, TFilter> getDataFunc, StringComparison stringComparison, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The regular expression that matches the filter. Matches what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData, a string representing the actual filter name that was matched and returns an object of type TFilter. |
StringComparison | stringComparison | String comparison options. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Returns
Type | Description |
---|---|
IQueryEngineFilter |
Type Parameters
Name | Description |
---|---|
TFilter | The type of the data that is compared by the filter. |
AddFilter<TFilter>(Regex, Func<TData, String, String, TFilter, Boolean>, String[])
Add a new custom filter with a custom resolver. Useful when you wish to handle all operators yourself.
Declaration
public IQueryEngineFilter AddFilter<TFilter>(Regex token, Func<TData, string, string, TFilter, bool> filterResolver, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The regular expression that matches the filter. Matches what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, String, TFilter, Boolean> | filterResolver | Callback used to handle any operators for this filter. Takes an object of type TData, a string representing the actual filter name that was matched, the operator token and the filter value, and returns a boolean indicating if the filter passed or not. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Returns
Type | Description |
---|---|
IQueryEngineFilter |
Type Parameters
Name | Description |
---|---|
TFilter | The type of the data that is compared by the filter. |
AddFilter<TFilter>(String, Func<TData, TFilter>, String[])
Add a new custom filter.
Declaration
public void AddFilter<TFilter>(string token, Func<TData, TFilter> getDataFunc, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData and returns an object of type TFilter. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Type Parameters
Name | Description |
---|---|
TFilter | The type of the data that is compared by the filter. |
AddFilter<TFilter>(String, Func<TData, TFilter>, StringComparison, String[])
Add a new custom filter.
Declaration
public void AddFilter<TFilter>(string token, Func<TData, TFilter> getDataFunc, StringComparison stringComparison, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData and returns an object of type TFilter. |
StringComparison | stringComparison | String comparison options. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Type Parameters
Name | Description |
---|---|
TFilter | The type of the data that is compared by the filter. |
AddFilter<TFilter>(String, Func<TData, String, TFilter, Boolean>, String[])
Add a new custom filter with a custom resolver. Useful when you wish to handle all operators yourself.
Declaration
public void AddFilter<TFilter>(string token, Func<TData, string, TFilter, bool> filterResolver, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, TFilter, Boolean> | filterResolver | Callback used to handle any operators for this filter. Takes an object of type TData, the operator token and the filter value, and returns a boolean indicating if the filter passed or not. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Type Parameters
Name | Description |
---|---|
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(Regex, Func<TData, String, TParam, TFilter>, Func<String, TParam>, String[])
Add a new custom filter function.
Declaration
public IQueryEngineFilter AddFilter<TParam, TFilter>(Regex token, Func<TData, string, TParam, TFilter> getDataFunc, Func<string, TParam> parameterTransformer, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The regular expression that matches the filter. Matches what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, TParam, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData, a string representing the actual filter name that was matched, an object of type TParam, and returns an object of type TFilter. |
Func<String, TParam> | parameterTransformer | Callback used to convert a string to the type TParam. Used when parsing the query to convert what is passed to the function into the correct format. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Returns
Type | Description |
---|---|
IQueryEngineFilter |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(Regex, Func<TData, String, TParam, TFilter>, Func<String, TParam>, StringComparison, String[])
Add a new custom filter function.
Declaration
public IQueryEngineFilter AddFilter<TParam, TFilter>(Regex token, Func<TData, string, TParam, TFilter> getDataFunc, Func<string, TParam> parameterTransformer, StringComparison stringComparison, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The regular expression that matches the filter. Matches what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, TParam, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData, a string representing the actual filter name that was matched, an object of type TParam, and returns an object of type TFilter. |
Func<String, TParam> | parameterTransformer | Callback used to convert a string to the type TParam. Used when parsing the query to convert what is passed to the function into the correct format. |
StringComparison | stringComparison | String comparison options. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Returns
Type | Description |
---|---|
IQueryEngineFilter |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(Regex, Func<TData, String, TParam, TFilter>, String[])
Add a new custom filter function.
Declaration
public IQueryEngineFilter AddFilter<TParam, TFilter>(Regex token, Func<TData, string, TParam, TFilter> getDataFunc, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The regular expression that matches the filter. Matches what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, TParam, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData, a string representing the actual filter name that was matched, an object of type TParam, and returns an object of type TFilter. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Returns
Type | Description |
---|---|
IQueryEngineFilter |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(Regex, Func<TData, String, TParam, TFilter>, StringComparison, String[])
Add a new custom filter function.
Declaration
public IQueryEngineFilter AddFilter<TParam, TFilter>(Regex token, Func<TData, string, TParam, TFilter> getDataFunc, StringComparison stringComparison, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The regular expression that matches the filter. Matches what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, TParam, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData, a string representing the actual filter name that was matched, an object of type TParam, and returns an object of type TFilter. |
StringComparison | stringComparison | String comparison options. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Returns
Type | Description |
---|---|
IQueryEngineFilter |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(Regex, Func<TData, String, TParam, String, TFilter, Boolean>, Func<String, TParam>, String[])
Add a new custom filter function with a custom resolver. Useful when you wish to handle all operators yourself.
Declaration
public IQueryEngineFilter AddFilter<TParam, TFilter>(Regex token, Func<TData, string, TParam, string, TFilter, bool> filterResolver, Func<string, TParam> parameterTransformer, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The regular expression that matches the filter. Matches what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, TParam, String, TFilter, Boolean> | filterResolver | Callback used to handle any operators for this filter. Takes an object of type TData, a string representing the actual filter name that was matched, an object of type TParam, the operator token and the filter value, and returns a boolean indicating if the filter passed or not. |
Func<String, TParam> | parameterTransformer | Callback used to convert a string to the type TParam. Used when parsing the query to convert what is passed to the function into the correct format. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Returns
Type | Description |
---|---|
IQueryEngineFilter |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(Regex, Func<TData, String, TParam, String, TFilter, Boolean>, String[])
Add a new custom filter function with a custom resolver. Useful when you wish to handle all operators yourself.
Declaration
public IQueryEngineFilter AddFilter<TParam, TFilter>(Regex token, Func<TData, string, TParam, string, TFilter, bool> filterResolver, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The regular expression that matches the filter. Matches what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, String, TParam, String, TFilter, Boolean> | filterResolver | Callback used to handle any operators for this filter. Takes an object of type TData, a string representing the actual filter name that was matched, an object of type TParam, the operator token and the filter value, and returns a boolean indicating if the filter passed or not. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Returns
Type | Description |
---|---|
IQueryEngineFilter |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(String, Func<TData, TParam, TFilter>, Func<String, TParam>, String[])
Add a new custom filter function.
Declaration
public void AddFilter<TParam, TFilter>(string token, Func<TData, TParam, TFilter> getDataFunc, Func<string, TParam> parameterTransformer, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, TParam, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData and TParam, and returns an object of type TFilter. |
Func<String, TParam> | parameterTransformer | Callback used to convert a string to the type TParam. Used when parsing the query to convert what is passed to the function into the correct format. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(String, Func<TData, TParam, TFilter>, Func<String, TParam>, StringComparison, String[])
Add a new custom filter function.
Declaration
public void AddFilter<TParam, TFilter>(string token, Func<TData, TParam, TFilter> getDataFunc, Func<string, TParam> parameterTransformer, StringComparison stringComparison, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, TParam, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData and TParam, and returns an object of type TFilter. |
Func<String, TParam> | parameterTransformer | Callback used to convert a string to the type TParam. Used when parsing the query to convert what is passed to the function into the correct format. |
StringComparison | stringComparison | String comparison options. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(String, Func<TData, TParam, TFilter>, String[])
Add a new custom filter function.
Declaration
public void AddFilter<TParam, TFilter>(string token, Func<TData, TParam, TFilter> getDataFunc, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, TParam, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData and TParam, and returns an object of type TFilter. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(String, Func<TData, TParam, TFilter>, StringComparison, String[])
Add a new custom filter function.
Declaration
public void AddFilter<TParam, TFilter>(string token, Func<TData, TParam, TFilter> getDataFunc, StringComparison stringComparison, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, TParam, TFilter> | getDataFunc | Callback used to get the object that is used in the filter. Takes an object of type TData and TParam, and returns an object of type TFilter. |
StringComparison | stringComparison | String comparison options. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(String, Func<TData, TParam, String, TFilter, Boolean>, Func<String, TParam>, String[])
Add a new custom filter function with a custom resolver. Useful when you wish to handle all operators yourself.
Declaration
public void AddFilter<TParam, TFilter>(string token, Func<TData, TParam, string, TFilter, bool> filterResolver, Func<string, TParam> parameterTransformer, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, TParam, String, TFilter, Boolean> | filterResolver | Callback used to handle any operators for this filter. Takes an object of type TData, an object of type TParam, the operator token and the filter value, and returns a boolean indicating if the filter passed or not. |
Func<String, TParam> | parameterTransformer | Callback used to convert a string to the type TParam. Used when parsing the query to convert what is passed to the function into the correct format. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFilter<TParam, TFilter>(String, Func<TData, TParam, String, TFilter, Boolean>, String[])
Add a new custom filter function with a custom resolver. Useful when you wish to handle all operators yourself.
Declaration
public void AddFilter<TParam, TFilter>(string token, Func<TData, TParam, string, TFilter, bool> filterResolver, string[] supportedOperatorType = null)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TData, TParam, String, TFilter, Boolean> | filterResolver | Callback used to handle any operators for this filter. Takes an object of type TData, an object of type TParam, the operator token and the filter value, and returns a boolean indicating if the filter passed or not. |
String[] | supportedOperatorType | List of supported operator tokens. This list contains the supported operator tokens. Use null or an empty list to indicate that all operators are supported. |
Type Parameters
Name | Description |
---|---|
TParam | The type of the constant parameter passed to the function. |
TFilter | The type of the data that is compared by the filter. |
AddFiltersFromAttribute<TFilterAttribute, TTransformerAttribute>()
Add all custom filters that are identified with the method attribute TAttribute.
Declaration
public void AddFiltersFromAttribute<TFilterAttribute, TTransformerAttribute>()
where TFilterAttribute : QueryEngineFilterAttribute where TTransformerAttribute : QueryEngineParameterTransformerAttribute
Type Parameters
Name | Description |
---|---|
TFilterAttribute | The type of the attribute of filters to fetch. |
TTransformerAttribute | The attribute type for the parameter transformers associated with the filter attribute. |
AddNestedQueryAggregator<TNestedQueryData>(String, Func<IEnumerable<TNestedQueryData>, IEnumerable<TNestedQueryData>>)
Add a new nested query aggregator. An aggregator is an operation that can be applied on a nested query to aggregate the results of the nested query according to a certain criteria.
Declaration
public void AddNestedQueryAggregator<TNestedQueryData>(string token, Func<IEnumerable<TNestedQueryData>, IEnumerable<TNestedQueryData>> aggregator)
Parameters
Type | Name | Description |
---|---|---|
String | token | Name of the aggregator used when typing the query. This name will be lowercased when parsing the query to speedup the process. |
Func<IEnumerable<TNestedQueryData>, IEnumerable<TNestedQueryData>> | aggregator | Aggregator function. Takes the results of the nested query, and returns an aggregate that contains any number of items. |
Type Parameters
Name | Description |
---|---|
TNestedQueryData | The type of data returned by the nested query. |
AddOperator(String)
Add a global custom filter operator.
Declaration
public void AddOperator(string op)
Parameters
Type | Name | Description |
---|---|---|
String | op | The operator identifier. |
AddOperatorHandler<TFilterVariable, TFilterConstant>(String, Func<TFilterVariable, TFilterConstant, Boolean>)
Add a custom filter operator handler.
Declaration
public void AddOperatorHandler<TFilterVariable, TFilterConstant>(string op, Func<TFilterVariable, TFilterConstant, bool> handler)
Parameters
Type | Name | Description |
---|---|---|
String | op | The filter operator. |
Func<TFilterVariable, TFilterConstant, Boolean> | handler | Callback to handle the operation. Takes a TFilterVariable (value returned by the filter handler, will vary for each element) and a TFilterConstant (right hand side value of the operator, which is constant), and returns a boolean indicating if the filter passes or not. |
Type Parameters
Name | Description |
---|---|
TFilterVariable | The operator's left hand side type. This is the type returned by a filter handler. |
TFilterConstant | The operator's right hand side type. |
AddOperatorHandler<TFilterVariable, TFilterConstant>(String, Func<TFilterVariable, TFilterConstant, StringComparison, Boolean>)
Add a custom filter operator handler.
Declaration
public void AddOperatorHandler<TFilterVariable, TFilterConstant>(string op, Func<TFilterVariable, TFilterConstant, StringComparison, bool> handler)
Parameters
Type | Name | Description |
---|---|---|
String | op | The filter operator. |
Func<TFilterVariable, TFilterConstant, StringComparison, Boolean> | handler | Callback to handle the operation. Takes a TFilterVariable (value returned by the filter handler, will vary for each element), a TFilterConstant (right hand side value of the operator, which is constant), a StringComparison option and returns a boolean indicating if the filter passes or not. |
Type Parameters
Name | Description |
---|---|
TFilterVariable | The operator's left hand side type. This is the type returned by a filter handler. |
TFilterConstant | The operator's right hand side type. |
AddTypeParser<TFilterConstant>(Func<String, ParseResult<TFilterConstant>>)
Add a global type parser that parses a string and returns a custom type. Used by custom operator handlers.
Declaration
public void AddTypeParser<TFilterConstant>(Func<string, ParseResult<TFilterConstant>> parser)
Parameters
Type | Name | Description |
---|---|---|
Func<String, ParseResult<TFilterConstant>> | parser | Callback used to determine if a string can be converted into TFilterConstant. Takes a string and returns a ParseResult object. This contains the success flag, and the actual converted value if it succeeded. |
Type Parameters
Name | Description |
---|---|
TFilterConstant | The type of the parsed operand that is on the right hand side of the operator. |
ClearFilters()
Removes all filters that were added on the QueryEngine.
Declaration
public void ClearFilters()
GetAllFilters()
Declaration
public IEnumerable<IQueryEngineFilter> GetAllFilters()
Returns
Type | Description |
---|---|
IEnumerable<IQueryEngineFilter> |
GetOperator(String)
Get a custom operator added on the QueryEngine.
Declaration
public QueryFilterOperator GetOperator(string op)
Parameters
Type | Name | Description |
---|---|---|
String | op | The operator identifier. |
Returns
Type | Description |
---|---|
QueryFilterOperator | The global QueryFilterOperator or an invalid QueryFilterOperator if it does not exist. |
Parse(String, Boolean)
Declaration
[Obsolete("Parse has been deprecated. Use ParseQuery instead.")]
public Query<TData> Parse(string text, bool useFastYieldingQueryHandler = false)
Parameters
Type | Name | Description |
---|---|---|
String | text | |
Boolean | useFastYieldingQueryHandler |
Returns
Type | Description |
---|---|
Query<TData> |
Parse<TQueryHandler, TPayload>(String, IQueryHandlerFactory<TData, TQueryHandler, TPayload>)
Declaration
[Obsolete("Parse has been deprecated. Use ParseQuery instead.")]
public Query<TData, TPayload> Parse<TQueryHandler, TPayload>(string text, IQueryHandlerFactory<TData, TQueryHandler, TPayload> queryHandlerFactory)
where TQueryHandler : IQueryHandler<TData, TPayload> where TPayload : class
Parameters
Type | Name | Description |
---|---|---|
String | text | |
IQueryHandlerFactory<TData, TQueryHandler, TPayload> | queryHandlerFactory |
Returns
Type | Description |
---|---|
Query<TData, TPayload> |
Type Parameters
Name | Description |
---|---|
TQueryHandler | |
TPayload |
ParseQuery(String, Boolean)
Parse a query string into a ParsedQuery operation. This ParsedQuery operation can then be used to filter any data set of type TData.
Declaration
public ParsedQuery<TData> ParseQuery(string text, bool useFastYieldingQueryHandler = false)
Parameters
Type | Name | Description |
---|---|---|
String | text | The query input string. |
Boolean | useFastYieldingQueryHandler | Set to true to get a query that will yield null results for elements that don't pass the query, instead of only the elements that pass the query. |
Returns
Type | Description |
---|---|
ParsedQuery<TData> | ParsedQuery operation of type TData. |
ParseQuery<TQueryHandler, TPayload>(String, IQueryHandlerFactory<TData, TQueryHandler, TPayload>)
Parse a query string into a ParsedQuery operation. This ParsedQuery operation can then be used to filter any data set of type TData.
Declaration
public ParsedQuery<TData, TPayload> ParseQuery<TQueryHandler, TPayload>(string text, IQueryHandlerFactory<TData, TQueryHandler, TPayload> queryHandlerFactory)
where TQueryHandler : IQueryHandler<TData, TPayload> where TPayload : class
Parameters
Type | Name | Description |
---|---|---|
String | text | The query input string. |
IQueryHandlerFactory<TData, TQueryHandler, TPayload> | queryHandlerFactory | A factory object that creates query handlers of type TQueryHandler. See IQueryHandlerFactory. |
Returns
Type | Description |
---|---|
ParsedQuery<TData, TPayload> | ParsedQuery operation of type TData and TPayload. |
Type Parameters
Name | Description |
---|---|
TQueryHandler | Type of the underlying query handler. See IQueryHandler. |
TPayload | Type of the payload that the query handler receives. |
RemoveFilter(Regex)
Remove a custom filter.
Declaration
public void RemoveFilter(Regex token)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Remarks
You will get a warning if you try to remove a filter that does not exist.
RemoveFilter(String)
Remove a custom filter.
Declaration
public void RemoveFilter(string token)
Parameters
Type | Name | Description |
---|---|---|
String | token | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Remarks
You will get a warning if you try to remove a filter that does not exist.
RemoveFilter(IQueryEngineFilter)
Remove a custom filter.
Declaration
public void RemoveFilter(IQueryEngineFilter filter)
Parameters
Type | Name | Description |
---|---|---|
IQueryEngineFilter | filter | A IQueryEngineFilter that was returned by UnityEditor.Search.QueryEngine`1.AddFilter(System.String,System.String[]). |
RemoveOperator(String)
Removes a custom operator that was added on the QueryEngine.
Declaration
public void RemoveOperator(string op)
Parameters
Type | Name | Description |
---|---|---|
String | op | The operator identifier. |
SetDefaultFilter(Func<TData, String, String, String, Boolean>)
Set the default filter handler for filters that were not registered.
Declaration
public void SetDefaultFilter(Func<TData, string, string, string, bool> handler)
Parameters
Type | Name | Description |
---|---|---|
Func<TData, String, String, String, Boolean> | handler | Callback used to handle the filter. Takes an object of type TData, the filter identifier, the operator and the filter value, and returns a boolean indicating if the filter passed or not. |
SetDefaultParamFilter(Func<TData, String, String, String, String, Boolean>)
Set the default filter handler for function filters that were not registered.
Declaration
public void SetDefaultParamFilter(Func<TData, string, string, string, string, bool> handler)
Parameters
Type | Name | Description |
---|---|---|
Func<TData, String, String, String, String, Boolean> | handler | Callback used to handle the function filter. Takes an object of type TData, the filter identifier, the parameter, the operator and the filter value, and returns a boolean indicating if the filter passed or not. |
SetFilterNestedQueryTransformer<TNestedQueryData, TRhs>(String, Func<TNestedQueryData, TRhs>)
Set a filter's nested query transformer function. This function takes the result of a nested query and extract the necessary data to compare with the filter.
Declaration
public void SetFilterNestedQueryTransformer<TNestedQueryData, TRhs>(string filterToken, Func<TNestedQueryData, TRhs> transformer)
Parameters
Type | Name | Description |
---|---|---|
String | filterToken | The identifier of the filter. Typically what precedes the operator in a filter (for example, "id" in "id>=2"). |
Func<TNestedQueryData, TRhs> | transformer | The transformer function. |
Type Parameters
Name | Description |
---|---|
TNestedQueryData | The type of data returned by the nested query. |
TRhs | The type expected on the right hand side of the filter. |
SetGlobalStringComparisonOptions(StringComparison)
Set global string comparison options. Used for word matching and filter handling (unless overridden by filter).
Declaration
public void SetGlobalStringComparisonOptions(StringComparison stringComparison)
Parameters
Type | Name | Description |
---|---|---|
StringComparison | stringComparison | String comparison options. |
SetNestedQueryHandler<TNestedQueryData>(Func<String, String, IEnumerable<TNestedQueryData>>)
Set the function that will handle nested queries. Only one handler can be set.
Declaration
public void SetNestedQueryHandler<TNestedQueryData>(Func<string, string, IEnumerable<TNestedQueryData>> handler)
Parameters
Type | Name | Description |
---|---|---|
Func<String, String, IEnumerable<TNestedQueryData>> | handler | The function that handles nested queries. It receives the nested query and the filter token on which the query is applied, and returns an IEnumerable. |
Type Parameters
Name | Description |
---|---|
TNestedQueryData | The type of data returned by the nested query. |
SetSearchDataCallback(Func<TData, IEnumerable<String>>)
Set the callback to be used to fetch the data that will be matched against the search words.
Declaration
public void SetSearchDataCallback(Func<TData, IEnumerable<string>> getSearchDataCallback)
Parameters
Type | Name | Description |
---|---|---|
Func<TData, IEnumerable<String>> | getSearchDataCallback | Callback used to get the data to be matched against the search words. Takes an object of type TData and return an IEnumerable of strings. |
SetSearchDataCallback(Func<TData, IEnumerable<String>>, Func<String, String>, StringComparison)
Set the callback to be used to fetch the data that will be matched against the search words, plus a transformer on those words.
Declaration
public void SetSearchDataCallback(Func<TData, IEnumerable<string>> getSearchDataCallback, Func<string, string> searchWordTransformerCallback, StringComparison stringComparison)
Parameters
Type | Name | Description |
---|---|---|
Func<TData, IEnumerable<String>> | getSearchDataCallback | Callback used to get the data to be matched against the search words. Takes an object of type TData and return an IEnumerable of strings. |
Func<String, String> | searchWordTransformerCallback | Callback used to transform a search word during the query parsing. Useful when doing lowercase or uppercase comparison. Can return null or an empty string to remove the word from the query. |
StringComparison | stringComparison | String comparison options. |
SetSearchDataCallback(Func<TData, IEnumerable<String>>, StringComparison)
Set the callback to be used to fetch the data that will be matched against the search words.
Declaration
public void SetSearchDataCallback(Func<TData, IEnumerable<string>> getSearchDataCallback, StringComparison stringComparison)
Parameters
Type | Name | Description |
---|---|---|
Func<TData, IEnumerable<String>> | getSearchDataCallback | Callback used to get the data to be matched against the search words. Takes an object of type TData and return an IEnumerable of strings. |
StringComparison | stringComparison | String comparison options. |
SetSearchWordMatcher(Func<String, Boolean, StringComparison, String, Boolean>)
Set the search word matching function to be used instead of the default one. Set to null to use the default.
Declaration
public void SetSearchWordMatcher(Func<string, bool, StringComparison, string, bool> wordMatcher)
Parameters
Type | Name | Description |
---|---|---|
Func<String, Boolean, StringComparison, String, Boolean> | wordMatcher | The search word matching function. The first parameter is the search word. The second parameter is a boolean for exact match or not. The third parameter is the StringComparison options. The fourth parameter is an element of the array returned by the search data callback. The function returns true for a match or false for no match. |
TryGetFilter(Regex, out IQueryEngineFilter)
Try to get a filter by its token.
Declaration
public bool TryGetFilter(Regex token, out IQueryEngineFilter filter)
Parameters
Type | Name | Description |
---|---|---|
Regex | token | The token used to create the filter. |
IQueryEngineFilter | filter | The existing IQueryEngineFilter, or null if it does not exist. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the filter was retrieved or false if the filter does not exist. |
TryGetFilter(String, out IQueryEngineFilter)
Try to get a filter by its token.
Declaration
public bool TryGetFilter(string token, out IQueryEngineFilter filter)
Parameters
Type | Name | Description |
---|---|---|
String | token | The token used to create the filter. |
IQueryEngineFilter | filter | The existing IQueryEngineFilter, or null if it does not exist. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the filter was retrieved or false if the filter does not exist. |