A class that extends BaseTranslator to translate structured queries into functional filters.

Example

const functionalTranslator = new FunctionalTranslator();
const relevantDocuments = await functionalTranslator.getRelevantDocuments(
"Which movies are rated higher than 8.5?",
);

Hierarchy

Constructors

Properties

VisitComparisonOutput: FunctionFilter
VisitOperationOutput: FunctionFilter
VisitStructuredQueryOutput: {
    filter: FunctionFilter;
} | {
    [k: string]: never;
}

Type declaration

Type declaration

  • [k: string]: never
allowedComparators: Comparator[] = ...
allowedOperators: Operator[] = ...

Methods

  • Formats a given function (either an operator or a comparator) into a string.

    Returns string

    Formatted string representation of the function.

  • Returns a function that performs a comparison based on the provided comparator.

    Type Parameters

    Parameters

    • comparator: Comparator

      The comparator to base the comparison function on.

    Returns ((a, b) => boolean)

    A function that takes two arguments and returns a boolean based on the comparison.

      • (a, b): boolean
      • Returns a function that performs a comparison based on the provided comparator.

        Parameters

        • a: string | number
        • b: ValueType[C]

        Returns boolean

        A function that takes two arguments and returns a boolean based on the comparison.

  • Returns a function that performs an operation based on the provided operator.

    Parameters

    • operator: Operator

      The operator to base the operation function on.

    Returns ((a, b) => boolean)

    A function that takes two boolean arguments and returns a boolean based on the operation.

      • (a, b): boolean
      • Returns a function that performs an operation based on the provided operator.

        Parameters

        • a: boolean
        • b: boolean

        Returns boolean

        A function that takes two boolean arguments and returns a boolean based on the operation.

  • Merges two filters into one, based on the specified merge type.

    Parameters

    • defaultFilter: FunctionFilter

      The default filter function.

    • generatedFilter: FunctionFilter

      The generated filter function.

    • mergeType: string = "and"

      The type of merge to perform. Can be 'and', 'or', or 'replace'. Default is 'and'.

    Returns undefined | FunctionFilter

    A function that takes a Document as an argument and returns a boolean based on the merged filters, or undefined if both filters are empty.

  • Visits the comparison part of a structured query and translates it into a functional filter.

    Parameters

    • comparison: Comparison

      The comparison part of a structured query.

    Returns FunctionFilter

    A function that takes a Document as an argument and returns a boolean based on the comparison.

  • Visits the operation part of a structured query and translates it into a functional filter.

    Parameters

    • operation: Operation

      The operation part of a structured query.

    Returns FunctionFilter

    A function that takes a Document as an argument and returns a boolean based on the operation.

  • Visits a structured query and translates it into a functional filter.

    Parameters

    Returns {
        filter: FunctionFilter;
    } | {
        [k: string]: never;
    }

    An object containing a filter property, which is a function that takes a Document as an argument and returns a boolean based on the structured query.

Generated using TypeDoc