This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# `SEARCH` Handler | ||
|
||
:::warning | ||
By default, it is **disabled**. | ||
::: | ||
|
||
You can activate the SEARCH handler to allow HTTP clients to run Elasticsearch-based full-text search queries on the model. | ||
|
||
:::warning | ||
Currently, the full-text search feature is **EXPERIMENTAL**. | ||
|
||
Still, we strongly suggest to use it in some little parts of your application. | ||
::: | ||
|
||
This is a simple definition of the ALL handlers; | ||
|
||
```ts | ||
import { Model, DEFAULT_HANDLERS, HandlerTypes } from "axe-api"; | ||
|
||
class User extends Model { | ||
get handlers() { | ||
return [...DEFAULT_HANDLERS, HandlerTypes.SEARCH]; | ||
} | ||
} | ||
|
||
export default User; | ||
``` | ||
|
||
Clients can use the following query to fetch data; | ||
|
||
```bash | ||
$ curl \ | ||
-H "Content-Type: application/json" \ | ||
-X GET http://localhost:3000/api/v1/users/search?text=karl | ||
``` | ||
|
||
This is an example result of the request; | ||
|
||
```json | ||
{ | ||
"data": [ | ||
{ | ||
"id": 1, | ||
"name": "Karl Popper", | ||
"created_at": "2021-10-16T19:18:47.000Z", | ||
"updated_at": "2021-10-16T19:18:47.000Z" | ||
} | ||
], | ||
"pagination": { | ||
"total": 1, | ||
"lastPage": 1, | ||
"perPage": 10, | ||
"currentPage": 1, | ||
"from": 0, | ||
"to": 10 | ||
} | ||
} | ||
``` |