directus-extension-search-engine
v0.0.6
Published
search engine
Downloads
208
Maintainers
Readme
I. Setup Docker compose & Env
typesense:
image: typesense/typesense:27.0.rc7
container_name: typesense-search
restart: always
ports:
- "8108:8108"
volumes:
- ./typesense-data:/data
command: '--data-dir /data --api-key=$TYPESENSE_API_KEY --enable-cors'
TYPESENSE_API_KEY="112233"
II. Configs
Install
npm i directus-extension-search-engine
1. Field Engine Type
Allows to configure the type of search engine to be used
Note: currently I only support
typesense
, in the future I will supportelasticsearch
2. Field Typesense API Key
This field is configured in env. Any change to the value in this field will be invalid.
3. Field Typesense Urls
This field specifies the URLs of the typesense
service. These services must all share the same API key configured in env
4. Field Typesense Indexing
The processing flow here will be: get data in the query configured in query
and collection
, then process the data with Javascript in Function Parse
so that the output matches the schema configured in Schema
4.1. Query data
In this step, we will get data with directus
sdk
query (collection & query). The returned response will be the input (data
) of the Function Parse
field to run the script.
See more: https://docs.directus.io/reference/items.html
4.2 Parse data & index schema
The above data will be put into Function Parse
with the variable data
and processed. The data needs to be processed to match the schema configured in the schema
field.
Config schema: https://typesense.org/docs/0.25.2/api/collections.html#create-a-collection
III. Router search
1. Search with collection index
POST <CMS url>/search/typesense/search-collection/:collection
Authorization: <user token>
Params: collection
Body
{
"q" : "stark",
"query_by" : "title"
}
Body config: https://typesense.org/docs/0.25.2/api/search.html#query-parameters
Docs: https://typesense.org/docs/0.25.2/api/search.html
2. Multi-search
POST <CMS url>/search/typesense/multi-search
Authorization: <user token>
Query params
{
"query_by": "name",
}
Note: query params will be used as
commonSearchParams
intypesense
(https://typesense.org/docs/0.25.2/api/federated-multi-search.html#multi-search-parameters)
Body
{
"q" : "stark",
"query_by" : "title"
}
Note: this body will be used as
searchRequests
intypesense
(https://typesense.org/docs/0.25.2/api/federated-multi-search.html#multi-search-parameters)
Body config: https://typesense.org/docs/0.25.2/api/search.html#query-parameters
Docs: https://typesense.org/docs/0.25.2/api/search.html
3. Re-index data (Clear and re-index)
POST <CMS url>/search/typesense/refresh-index
Authorization: <admin token>
4. Data Indexing (with collections)
POST <CMS url>/search/typesense/index-data
Authorization: <admin token>
Body
{
"collections": ["news"]
}
Note: If
collections
does not receive a value or the value is incorrect, collections will be assigned all configured values.
5. Clear data index (with collections)
POST <CMS url>/search/typesense/clear-collections
Authorization: <admin token>
Body
{
"collections": ["news"]
}