Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(preset): update preset configuration documentation for search API #261

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
58 changes: 24 additions & 34 deletions docs-site/content/27.0/api/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ Let's create a preset with name `listing_view`.
```js
await client.presets().upsert("listing_view", {
value: {
searches: [{ collection: "products", q: "*", sort_by: "popularity" }],
collection: "products", q: "*", sort_by: "popularity",
},
});
```
Expand All @@ -727,9 +727,7 @@ Let's create a preset with name `listing_view`.
```dart
await client.presets.upsert('listing_view', {
'value': {
'searches': [
{'collection': 'products', 'q': '*','sort_by': 'popularity'}
]
'collection': 'products', 'q': '*','sort_by': 'popularity'
}
});
```
Expand All @@ -741,11 +739,10 @@ Let's create a preset with name `listing_view`.
curl "http://localhost:8108/presets/listing_view" -X PUT \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{"value": {"searches":[{"collection":"products","q":"*", "sort_by": "popularity"}]}}'
-d '{"value": {"collection":"products","q":"*", "sort_by": "popularity"}}'
```
</template>
</Tabs>

You can refer to this preset configuration during a search operation.

<Tabs :tabs="['JavaScript','Dart','Shell']">
Expand Down Expand Up @@ -776,37 +773,30 @@ curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -X POST \
</template>
</Tabs>

You can use the preset configuration for a `GET .../search` end-point as well.

The only requirement is that for
`GET .../search`, the stored preset value should be a simple dictionary of search configurations, like this.

<Tabs :tabs="['Dart','Shell']">
<template v-slot:Dart>
:::tip
The `value` key in the preset configuration can also match the search parameters for <RouterLink :to="`/${$site.themeConfig.typesenseLatestVersion}/api/federated-multi-search.html`">Federated / Multi Search</RouterLink>. For example:

```dart
await client.presets.upsert('listing_view', {
'value': {
{
'collection': 'products',
'q': '*',
'sort_by': 'popularity',
}
}
});
```js
await client.presets().upsert("listing_view", {
value: {
searches: [
{
collection: "products",
q: "*",
sort_by: "popularity",
},
{
collection: "blog_posts",
q: "*",
sort_by: "published_at:desc",
}
],
},
})
```
:::

</template>
<template v-slot:Shell>

```shell
curl "http://localhost:8108/presets/listing_view" -X PUT \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '
{"value": {"collection":"products","q":"*", "sort_by": "popularity"}}'
```
</template>
</Tabs>
It's generally recommended to use single-search presets for flexibility. You can then combine them in a multi-search request using the `preset` parameter.

:::tip
Explicit query parameters passed to the search end-point will override parameters stored in preset value.
Expand Down
51 changes: 22 additions & 29 deletions docs-site/content/27.1/api/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -776,38 +776,31 @@ curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -X POST \
</template>
</Tabs>

You can use the preset configuration for a `GET .../search` end-point as well.

The only requirement is that for
`GET .../search`, the stored preset value should be a simple dictionary of search configurations, like this.

<Tabs :tabs="['Dart','Shell']">
<template v-slot:Dart>
:::tip
The `value` key in the preset configuration can also match the search parameters for <RouterLink :to="`/${$site.themeConfig.typesenseLatestVersion}/api/federated-multi-search.html`">Federated / Multi Search</RouterLink>. For example:

```dart
await client.presets.upsert('listing_view', {
'value': {
{
'collection': 'products',
'q': '*',
'sort_by': 'popularity',
}
}
});
```js
await client.presets().upsert("listing_view", {
value: {
searches: [
{
collection: "products",
q: "*",
sort_by: "popularity",
},
{
collection: "blog_posts",
q: "*",
sort_by: "published_at:desc",
}
],
},
})
```
:::

</template>
<template v-slot:Shell>

```shell
curl "http://localhost:8108/presets/listing_view" -X PUT \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '
{"value": {"collection":"products","q":"*", "sort_by": "popularity"}}'
```
</template>
</Tabs>
It's generally recommended to use single-search presets for flexibility. You can then combine them in a multi-search request using the `preset` parameter.

:::tip
Explicit query parameters passed to the search end-point will override parameters stored in preset value.
:::
:::