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
34 changes: 28 additions & 6 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,6 +773,31 @@ curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -X POST \
</template>
</Tabs>

:::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:

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

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.
:::

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

The only requirement is that for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tharropoulos This part now conflicts with some information in the changes above. Could you edit this as needed? Or may be even delete it if not needed, with the new information above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting this section altogether at 9ae2277

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like GitHub is not rendering my comment against the right line in this PR view.

My comment was about the following paragraph, not the one you deleted in 9ae2277. (Let's add that back in).

Screenshot 2024-09-19 at 3 50 42 PM

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 235aaad resolving this?

Expand Down