Class: Search
July 15, 2024 · View on GitHub
redis-om / Search
Class: Search<T>
Entry point to fluent search. This is the default Redis OM experience. Requires that RediSearch (and optionally RedisJSON) be installed.
Template
The type of Entity being sought.
Type parameters
| Name | Type |
|---|---|
T | extends Entity = Record<string, any> |
Hierarchy
-
↳
Search
Table of contents
Accessors
Methods
- all
- allIds
- allKeys
- and
- count
- first
- firstId
- firstKey
- max
- maxId
- maxKey
- min
- minId
- minKey
- or
- page
- pageOfIds
- pageOfKeys
- returnAll
- returnAllIds
- returnAllKeys
- returnCount
- returnFirst
- returnFirstId
- returnFirstKey
- returnMax
- returnMaxId
- returnMaxKey
- returnMin
- returnMinId
- returnMinKey
- returnPage
- returnPageOfIds
- returnPageOfKeys
- sortAsc
- sortAscending
- sortBy
- sortDesc
- sortDescending
- where
Accessors
return
• get return(): AbstractSearch<T>
Returns the current instance. Syntactic sugar to make your code more fluent.
Returns
this
Inherited from
AbstractSearch.return
Defined in
Methods
all
▸ all(options?): Promise<T[]>
Returns all the Entities that match this query. This method
makes multiple calls to Redis until all the Entities are returned.
You can specify the batch size by setting the pageSize property on the
options:
const entities = await repository.search().returnAll({ pageSize: 100 })
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
options | Object | undefined | Options for the call. |
options.pageSize | number | 10 | Number of Entities returned per batch. |
Returns
Promise<T[]>
An array of Entities matching the query.
Inherited from
Defined in
allIds
▸ allIds(options?): Promise<string[]>
Returns all the entity IDs that match this query. This method
makes multiple calls to Redis until all the entity IDs are returned.
You can specify the batch size by setting the pageSize property on the
options:
const keys = await repository.search().returnAllIds({ pageSize: 100 })
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
options | Object | undefined | Options for the call. |
options.pageSize | number | 10 | Number of entity IDs returned per batch. |
Returns
Promise<string[]>
An array of entity IDs matching the query.
Inherited from
Defined in
allKeys
▸ allKeys(options?): Promise<string[]>
Returns all the key names in Redis that match this query. This method
makes multiple calls to Redis until all the key names are returned.
You can specify the batch size by setting the pageSize property on the
options:
const keys = await repository.search().returnAllKeys({ pageSize: 100 })
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
options | Object | undefined | Options for the call. |
options.pageSize | number | 10 | Number of key names returned per batch. |
Returns
Promise<string[]>
An array of key names matching the query.
Inherited from
Defined in
and
▸ and(field): WhereField<T>
Sets up a query matching a particular field as a logical AND.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field to filter on. |
Returns
WhereField<T>
A subclass of WhereField matching the type of the field.
Defined in
▸ and(subSearchFn): Search<T>
Sets up a nested search as a logical AND.
Parameters
| Name | Type | Description |
|---|---|---|
subSearchFn | SubSearchFunction<T> | A function that takes a Search and returns another Search. |
Returns
Search<T>
this.
Defined in
count
▸ count(): Promise<number>
Returns the number of Entities that match this query.
Returns
Promise<number>
Inherited from
Defined in
first
▸ first(): Promise<null | T>
Returns the first Entity that matches this query.
Returns
Promise<null | T>
Inherited from
Defined in
firstId
▸ firstId(): Promise<null | string>
Returns the first entity ID that matches this query.
Returns
Promise<null | string>
Inherited from
Defined in
firstKey
▸ firstKey(): Promise<null | string>
Returns the first key name that matches this query.
Returns
Promise<null | string>
Inherited from
Defined in
max
▸ max(field): Promise<null | T>
Finds the Entity with the maximal value for a field.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field with the maximal value. |
Returns
Promise<null | T>
The entity ID Entity with the maximal value
Inherited from
Defined in
maxId
▸ maxId(field): Promise<null | string>
Finds the entity ID with the maximal value for a field.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field with the maximal value. |
Returns
Promise<null | string>
The entity ID with the maximal value
Inherited from
Defined in
maxKey
▸ maxKey(field): Promise<null | string>
Finds the key name in Redis with the maximal value for a field.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field with the maximal value. |
Returns
Promise<null | string>
The key name with the maximal value
Inherited from
Defined in
min
▸ min(field): Promise<null | T>
Finds the Entity with the minimal value for a field.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field with the minimal value. |
Returns
Promise<null | T>
The Entity with the minimal value
Inherited from
Defined in
minId
▸ minId(field): Promise<null | string>
Finds the entity ID with the minimal value for a field.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field with the minimal value. |
Returns
Promise<null | string>
The entity ID with the minimal value
Inherited from
Defined in
minKey
▸ minKey(field): Promise<null | string>
Finds the key name in Redis with the minimal value for a field.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field with the minimal value. |
Returns
Promise<null | string>
The key name with the minimal value
Inherited from
Defined in
or
▸ or(field): WhereField<T>
Sets up a query matching a particular field as a logical OR.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field to filter on. |
Returns
WhereField<T>
A subclass of WhereField matching the type of the field.
Defined in
▸ or(subSearchFn): Search<T>
Sets up a nested search as a logical OR.
Parameters
| Name | Type | Description |
|---|---|---|
subSearchFn | SubSearchFunction<T> | A function that takes a Search and returns another Search. |
Returns
Search<T>
this.
Defined in
page
▸ page(offset, count): Promise<T[]>
Returns a page of Entities that match this query.
Parameters
| Name | Type | Description |
|---|---|---|
offset | number | The offset for where to start returning Entities. |
count | number | The number of Entities to return. |
Returns
Promise<T[]>
An array of Entities matching the query.
Inherited from
Defined in
pageOfIds
▸ pageOfIds(offset, count): Promise<string[]>
Returns a page of entity IDs that match this query.
Parameters
| Name | Type | Description |
|---|---|---|
offset | number | The offset for where to start returning entity IDs. |
count | number | The number of entity IDs to return. |
Returns
Promise<string[]>
An array of strings matching the query.
Inherited from
Defined in
pageOfKeys
▸ pageOfKeys(offset, count): Promise<string[]>
Returns a page of key names in Redis that match this query.
Parameters
| Name | Type | Description |
|---|---|---|
offset | number | The offset for where to start returning key names. |
count | number | The number of key names to return. |
Returns
Promise<string[]>
An array of strings matching the query.
Inherited from
Defined in
returnAll
▸ returnAll(options?): Promise<T[]>
Alias for all.
Parameters
| Name | Type | Default value |
|---|---|---|
options | Object | undefined |
options.pageSize | number | 10 |
Returns
Promise<T[]>
Inherited from
Defined in
returnAllIds
▸ returnAllIds(options?): Promise<string[]>
Alias for allIds.
Parameters
| Name | Type | Default value |
|---|---|---|
options | Object | undefined |
options.pageSize | number | 10 |
Returns
Promise<string[]>
Inherited from
Defined in
returnAllKeys
▸ returnAllKeys(options?): Promise<string[]>
Alias for allKeys.
Parameters
| Name | Type | Default value |
|---|---|---|
options | Object | undefined |
options.pageSize | number | 10 |
Returns
Promise<string[]>
Inherited from
Defined in
returnCount
▸ returnCount(): Promise<number>
Alias for count.
Returns
Promise<number>
Inherited from
Defined in
returnFirst
▸ returnFirst(): Promise<null | T>
Alias for first.
Returns
Promise<null | T>
Inherited from
Defined in
returnFirstId
▸ returnFirstId(): Promise<null | string>
Alias for firstId.
Returns
Promise<null | string>
Inherited from
Defined in
returnFirstKey
▸ returnFirstKey(): Promise<null | string>
Alias for firstKey.
Returns
Promise<null | string>
Inherited from
Defined in
returnMax
▸ returnMax(field): Promise<null | T>
Alias for max.
Parameters
| Name | Type |
|---|---|
field | Exclude<keyof T, keyof EntityInternal> |
Returns
Promise<null | T>
Inherited from
Defined in
returnMaxId
▸ returnMaxId(field): Promise<null | string>
Alias for maxId.
Parameters
| Name | Type |
|---|---|
field | Exclude<keyof T, keyof EntityInternal> |
Returns
Promise<null | string>
Inherited from
Defined in
returnMaxKey
▸ returnMaxKey(field): Promise<null | string>
Alias for maxKey.
Parameters
| Name | Type |
|---|---|
field | Exclude<keyof T, keyof EntityInternal> |
Returns
Promise<null | string>
Inherited from
Defined in
returnMin
▸ returnMin(field): Promise<null | T>
Alias for min.
Parameters
| Name | Type |
|---|---|
field | Exclude<keyof T, keyof EntityInternal> |
Returns
Promise<null | T>
Inherited from
Defined in
returnMinId
▸ returnMinId(field): Promise<null | string>
Alias for minId.
Parameters
| Name | Type |
|---|---|
field | Exclude<keyof T, keyof EntityInternal> |
Returns
Promise<null | string>
Inherited from
Defined in
returnMinKey
▸ returnMinKey(field): Promise<null | string>
Alias for minKey.
Parameters
| Name | Type |
|---|---|
field | Exclude<keyof T, keyof EntityInternal> |
Returns
Promise<null | string>
Inherited from
Defined in
returnPage
▸ returnPage(offset, count): Promise<T[]>
Alias for page.
Parameters
| Name | Type |
|---|---|
offset | number |
count | number |
Returns
Promise<T[]>
Inherited from
Defined in
returnPageOfIds
▸ returnPageOfIds(offset, count): Promise<string[]>
Alias for pageOfIds.
Parameters
| Name | Type |
|---|---|
offset | number |
count | number |
Returns
Promise<string[]>
Inherited from
AbstractSearch.returnPageOfIds
Defined in
returnPageOfKeys
▸ returnPageOfKeys(offset, count): Promise<string[]>
Alias for pageOfKeys.
Parameters
| Name | Type |
|---|---|
offset | number |
count | number |
Returns
Promise<string[]>
Inherited from
AbstractSearch.returnPageOfKeys
Defined in
sortAsc
▸ sortAsc(field): AbstractSearch<T>
Alias for sortAscending.
Parameters
| Name | Type |
|---|---|
field | Exclude<keyof T, keyof EntityInternal> |
Returns
Inherited from
Defined in
sortAscending
▸ sortAscending(field): AbstractSearch<T>
Applies an ascending sort to the query.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field to sort by. |
Returns
this
Inherited from
Defined in
sortBy
▸ sortBy(fieldName, order?): AbstractSearch<T>
Applies sorting for the query.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
fieldName | Exclude<keyof T, keyof EntityInternal> | undefined | The field to sort by. |
order | "ASC" | "DESC" | "ASC" | The order of returned Entities Defaults to ASC (ascending) if not specified |
Returns
this
Inherited from
Defined in
sortDesc
▸ sortDesc(field): AbstractSearch<T>
Alias for sortDescending.
Parameters
| Name | Type |
|---|---|
field | Exclude<keyof T, keyof EntityInternal> |
Returns
Inherited from
Defined in
sortDescending
▸ sortDescending(field): AbstractSearch<T>
Applies a descending sort to the query.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field to sort by. |
Returns
this
Inherited from
Defined in
where
▸ where(field): WhereField<T>
Sets up a query matching a particular field. If there are multiple calls to where, they are treated logically as AND.
Parameters
| Name | Type | Description |
|---|---|---|
field | Exclude<keyof T, keyof EntityInternal> | The field to filter on. |
Returns
WhereField<T>
A subclass of WhereField matching the type of the field.
Defined in
▸ where(subSearchFn): Search<T>
Sets up a nested search. If there are multiple calls to where, they are treated logically as AND.
Parameters
| Name | Type | Description |
|---|---|---|
subSearchFn | SubSearchFunction<T> | A function that takes a Search and returns another Search. |
Returns
Search<T>
this.