Class QueryEngine<TData> | Quick Search | 1.5.4
docs.unity3d.com
    Show / Hide Table of Contents

    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.

    Inheritance
    Object
    QueryEngine<TData>
    QueryEngine
    Namespace: Unity.QuickSearch
    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.

    Properties

    globalStringComparison

    Global string comparison options for word matching and filter handling (if not overridden by filter).

    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>>

    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>(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 (i.e. "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. Null for all operators.

    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 (i.e. "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. Null for all operators.

    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 (i.e. "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. Null for all operators.

    Type Parameters
    Name Description
    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 (i.e. "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. Null for all operators.

    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 (i.e. "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. Null for all operators.

    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 (i.e. "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. Null for all operators.

    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 (i.e. "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. Null for all operators.

    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.

    AddOperator(String)

    Add a 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.

    AddTypeParser<TFilterConstant>(Func<String, ParseResult<TFilterConstant>>)

    Add a type parser that parse 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.

    Parse(String)

    Parse a query string into a Query operation. This Query operation can then be used to filter any data set of type TData.

    Declaration
    public Query<TData> Parse(string text)
    Parameters
    Type Name Description
    String text

    The query input string.

    Returns
    Type Description
    Query<TData>

    Query operation of type TData.

    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.

    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.

    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.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023