topk-js / query

Functions

abs()

function abs(expr: LogicalExpression): LogicalExpression;
Creates an absolute value expression. Parameters
ParameterType
exprLogicalExpression
Returns LogicalExpression

all()

function all(exprs: LogicalExpression[]): LogicalExpression;
Evaluates to true if each expr is true. Parameters
ParameterType
exprsLogicalExpression[]
Returns LogicalExpression

any()

function any(exprs: LogicalExpression[]): LogicalExpression;
Evaluates to true if at least one expr is true. Parameters
ParameterType
exprsLogicalExpression[]
Returns LogicalExpression

field()

function field(name: string): LogicalExpression;
Creates a field reference expression. Parameters
ParameterType
namestring
Returns LogicalExpression

filter()

function filter(expr: 
  | LogicalExpression
  | TextExpression): Query;
Creates a filter query stage. Parameters
ParameterType
expr| LogicalExpression | TextExpression
Returns Query

literal()

function literal(value: 
  | string
  | number
  | boolean
  | string[]
  | number[]
  | List): LogicalExpression;
Creates a literal value expression. Parameters
ParameterType
value| string | number | boolean | string[] | number[] | List
Returns LogicalExpression

match()

function match(token: string, options?: MatchOptions): TextExpression;
Creates a text match expression. Parameters
ParameterType
tokenstring
options?MatchOptions
Returns TextExpression

max()

function max(left: 
  | string
  | number
  | LogicalExpression, right: 
  | string
  | number
  | LogicalExpression): LogicalExpression;
Creates a MAX expression that returns the larger of two values. Parameters
ParameterType
left| string | number | LogicalExpression
right| string | number | LogicalExpression
Returns LogicalExpression

min()

function min(left: 
  | string
  | number
  | LogicalExpression, right: 
  | string
  | number
  | LogicalExpression): LogicalExpression;
Creates a MIN expression that returns the smaller of two values. Parameters
ParameterType
left| string | number | LogicalExpression
right| string | number | LogicalExpression
Returns LogicalExpression

not()

function not(expr: LogicalExpression): LogicalExpression;
Creates a logical NOT expression. Parameters
ParameterType
exprLogicalExpression
Returns LogicalExpression

select()

function select(exprs: Record<string, 
  | LogicalExpression
  | FunctionExpression>): Query;
Creates a select query stage. Parameters
ParameterType
exprsRecord<string, | LogicalExpression | FunctionExpression>
Returns Query

Classes

FunctionExpression

Internal

LogicalExpression

Internal Methods
abs()
abs(): LogicalExpression;
Computes the absolute value of the expression. Returns LogicalExpression
add()
add(other: 
  | number
  | LogicalExpression): LogicalExpression;
Adds another value to the expression. Parameters
ParameterType
other| number | LogicalExpression
Returns LogicalExpression
and()
and(other: 
  | boolean
  | LogicalExpression): LogicalExpression;
Computes the logical AND of the expression and another expression. Parameters
ParameterType
other| boolean | LogicalExpression
Returns LogicalExpression
boost()
boost(condition: 
  | boolean
  | LogicalExpression, boost: 
  | number
  | LogicalExpression): LogicalExpression;
Multiplies the scoring expression by the provided boost value if the condition is true. Otherwise, the scoring expression is unchanged (multiplied by 1). Parameters
ParameterType
condition| boolean | LogicalExpression
boost| number | LogicalExpression
Returns LogicalExpression
choose()
choose(x: 
  | string
  | number
  | boolean
  | LogicalExpression, y: 
  | string
  | number
  | boolean
  | LogicalExpression): LogicalExpression;
Chooses between two values based on the expression. Parameters
ParameterType
x| string | number | boolean | LogicalExpression
y| string | number | boolean | LogicalExpression
Returns LogicalExpression
coalesce()
coalesce(other: 
  | number
  | LogicalExpression): LogicalExpression;
Coalesces nulls in the expression with another value. Parameters
ParameterType
other| number | LogicalExpression
Returns LogicalExpression
contains()
contains(other: 
  | string
  | number
  | LogicalExpression): LogicalExpression;
Checks if the expression contains another value. Parameters
ParameterType
other| string | number | LogicalExpression
Returns LogicalExpression
div()
div(other: 
  | number
  | LogicalExpression): LogicalExpression;
Divides the expression by another value. Parameters
ParameterType
other| number | LogicalExpression
Returns LogicalExpression
eq()
eq(other: 
  | string
  | number
  | boolean
  | LogicalExpression): LogicalExpression;
Checks if the expression equals another value. Parameters
ParameterType
other| string | number | boolean | LogicalExpression
Returns LogicalExpression
exp()
exp(): LogicalExpression;
Computes the exponential of the expression. Returns LogicalExpression
gt()
gt(other: 
  | string
  | number
  | LogicalExpression): LogicalExpression;
Checks if the expression is greater than another value. Parameters
ParameterType
other| string | number | LogicalExpression
Returns LogicalExpression
gte()
gte(other: 
  | string
  | number
  | LogicalExpression): LogicalExpression;
Checks if the expression is greater than or equal to another value. Parameters
ParameterType
other| string | number | LogicalExpression
Returns LogicalExpression
in()
in(other: 
  | string
  | string[]
  | number[]
  | List
  | LogicalExpression): LogicalExpression;
Checks if the expression is in another value. Parameters
ParameterType
other| string | string[] | number[] | List | LogicalExpression
Returns LogicalExpression
isNotNull()
isNotNull(): LogicalExpression;
Checks if the expression evaluates to a non-null value. Returns LogicalExpression
isNull()
isNull(): LogicalExpression;
Checks if the expression evaluates to null. Returns LogicalExpression
ln()
ln(): LogicalExpression;
Computes the natural logarithm of the expression. Returns LogicalExpression
lt()
lt(other: 
  | string
  | number
  | LogicalExpression): LogicalExpression;
Checks if the expression is less than another value. Parameters
ParameterType
other| string | number | LogicalExpression
Returns LogicalExpression
lte()
lte(other: 
  | string
  | number
  | LogicalExpression): LogicalExpression;
Checks if the expression is less than or equal to another value. Parameters
ParameterType
other| string | number | LogicalExpression
Returns LogicalExpression
matchAll()
matchAll(other: 
  | string
  | string[]
  | LogicalExpression): LogicalExpression;
Checks if the expression matches all terms against the field with keyword index. Parameters
ParameterType
other| string | string[] | LogicalExpression
Returns LogicalExpression
matchAny()
matchAny(other: 
  | string
  | string[]
  | LogicalExpression): LogicalExpression;
Checks if the expression matches any term against the field with keyword index. Parameters
ParameterType
other| string | string[] | LogicalExpression
Returns LogicalExpression
max()
max(other: 
  | string
  | number
  | LogicalExpression): LogicalExpression;
Computes the maximum of the expression and another value. Parameters
ParameterType
other| string | number | LogicalExpression
Returns LogicalExpression
min()
min(other: 
  | string
  | number
  | LogicalExpression): LogicalExpression;
Computes the minimum of the expression and another value. Parameters
ParameterType
other| string | number | LogicalExpression
Returns LogicalExpression
mul()
mul(other: 
  | number
  | LogicalExpression): LogicalExpression;
Multiplies the expression by another value. Parameters
ParameterType
other| number | LogicalExpression
Returns LogicalExpression
ne()
ne(other: 
  | string
  | number
  | boolean
  | LogicalExpression): LogicalExpression;
Checks if the expression does not equal another value. Parameters
ParameterType
other| string | number | boolean | LogicalExpression
Returns LogicalExpression
or()
or(other: 
  | boolean
  | LogicalExpression): LogicalExpression;
Computes the logical OR of the expression and another expression. Parameters
ParameterType
other| boolean | LogicalExpression
Returns LogicalExpression
sqrt()
sqrt(): LogicalExpression;
Computes the square root of the expression. Returns LogicalExpression
square()
square(): LogicalExpression;
Computes the square of the expression. Returns LogicalExpression
startsWith()
startsWith(other: 
  | string
  | LogicalExpression): LogicalExpression;
Checks if the expression starts with another value. Parameters
ParameterType
other| string | LogicalExpression
Returns LogicalExpression
sub()
sub(other: 
  | number
  | LogicalExpression): LogicalExpression;
Subtracts another value from the expression. Parameters
ParameterType
other| number | LogicalExpression
Returns LogicalExpression
toString()
toString(): string;
Returns a string representation of the logical expression. Returns string

Query

Internal A query object that represents a sequence of query stages. Queries are built by chaining together different stages like select, filter, topk, etc. Each stage performs a specific operation on the data. Methods
count()
count(): Query;
Adds a count stage to the query. Returns Query
filter()
filter(expr: 
  | LogicalExpression
  | TextExpression): Query;
Adds a filter stage to the query. Parameters
ParameterType
expr| LogicalExpression | TextExpression
Returns Query
rerank()
rerank(options?: RerankOptions): Query;
Adds a rerank stage to the query. Parameters
ParameterType
options?RerankOptions
Returns Query
select()
select(exprs: Record<string, 
  | LogicalExpression
  | FunctionExpression>): Query;
Adds a select stage to the query. Parameters
ParameterType
exprsRecord<string, | LogicalExpression | FunctionExpression>
Returns Query
topk()
topk(
   expr: LogicalExpression, 
   k: number, 
   asc?: boolean): Query;
Adds a top-k stage to the query. Parameters
ParameterType
exprLogicalExpression
knumber
asc?boolean
Returns Query

TextExpression

Constructors Constructor
new TextExpression(): TextExpression;
Returns TextExpression Methods
and()
and(other: TextExpression): TextExpression;
Computes the logical AND of the expression and another text expression. Parameters
ParameterType
otherTextExpression
Returns TextExpression
or()
or(other: TextExpression): TextExpression;
Computes the logical OR of the expression and another text expression. Parameters
ParameterType
otherTextExpression
Returns TextExpression

Interfaces

MatchOptions

Options for text matching. This struct contains configuration options for text matching operations, including field specification, weight, and matching behavior. Properties
PropertyTypeDescription
all?booleanWhether to match all terms
field?stringField to match against
weight?numberWeight for the match

Term

Properties
PropertyTypeDescription
field?stringThe field to match against.
tokenstringThe token to match.
weightnumberThe weight of the term.