Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Operator<T> Abstract

Represents the low level abstraction of query generation that is responsible for the creation of queries themselves.

Operators are ment to be stateless and held as singleton instances, as they can be shared without any issues. This library uses the OperatorService to store the singleton instances, but you can use your own solution, or instantiate them multiple times if you prefer.

Type Parameters

  • T

    type of arguments this Operator can generate queries from

Hierarchy

Index

Constructors

  • new Operator<T>(numberOfOperands: number, operatorSymbols?: string): Operator<T>

Properties

_numberOfOperands: number

Determines the arity of the operator, that is the number of arguments/operands it takes.

_operatorSymbols: string

The operator symbol that is used to generate the query.

ESCAPABLE_CHARACTERS: Set<string> = ...

Reserved characters for Elasticsearch queries. These characters can be escaped with a \ character.

INPUT_PLACEHOLDER: "" = ''

Represents the placeholder "block" in operator display names.

UNESCAPABLE_CHARACTERS: Set<string> = ...

Reserved characters for Elasticsearch queries. These characters cannot be escaped and must be removed from queries.

Accessors

  • get numberOfOperands(): number

Methods

  • checkArgumentsCount(args: any[]): void
  • createQuery(elasticKeywords: string[], args: T[], escapeArgs?: boolean): Query
  • Simple implementation of query generation. Will not be suitable for all Operator derivatives.

    Escapes the first argument from the args array, calls the [query()]{@link Operator#query} function for each keyword and combines the results with an OR operator.

    Parameters

    • elasticKeywords: string[]
    • args: T[]
    • escapeArgs: boolean = true

    Returns Query

    query that wos constructed with the given arguments and keywords. Returns an empty query if no arguments are provided.

  • getOperatorNameTemplate(): string[]
  • serialize(): string
  • forEachKeyword(elasticKeywords: string[], queryConstructor: ((keyword: string) => Query)): Query
  • query(elasticKeyword: string, arg: string, operator: string): string
  • Creates a Query string query string literal with the provided arguments.

    Parameters

    • elasticKeyword: string

      Elasticsearch index keyword for the field you want to query

    • arg: string

      The value that you want to query the property for

    • operator: string

      The operator you want to use to query the indexed field. Consult the Elasticsearch's documentation for more information.

    Returns string

    combines the input strings by this pattern: ([elasticKeyword]:[operator][arg])

  • wrapInputWithQuotes(input: string, forceWrap?: boolean): WrapResult

Generated using TypeDoc