Studio search config
Omnisearch allows content search, can hide specific documents, and allows custom field weighting.
The global studio search panel (omnisearch) lets you search your content lake for any document that matches your term, or narrow down by filtering your query by schema types.
There may be instances where you don’t want specific documents from appearing in omnisearch.
To hide search results for a particular document type and remove it as a selectable filter:
{
type: 'document',
name: 'author',
fields: [
{name: 'name', type: 'string'},
// ...
],
// Hide all results for authors (and the author document type filter) in omnisearch
__experimental_omnisearch_visibility: false,
// ...
}
- You have workflow-related documents that you don’t wish to expose editors to.
- You want to hide documents that are less frequently used by editors.
- You’re an author of a Sanity plugin that registers its own document schema and would prefer it doesn't appear in user's studios.
Protip
This only affects visibility within the global studio search (‘omnisearch’). Visibility in both reference and cross dataset reference input fields is unaffected.
You can define specific weights on searchable fields for document types.
Search weights are configurable via options.search.weight
. Here's an example:
{
type: 'document',
name: 'author',
fields: [
{
name: 'name',
type: 'string',
options: {
search: { weight: 10 },
// ...
}
},
{
name: 'description',
type: 'array',
of: [{type: 'block'}],
options: {
search: { weight: 10 },
// ...
}
}
// ...
],
// ...
}
As of v3.38.0 the studio search is powered by a new backend API that enables a significant performance boost and advanced features such as support for wildcard (*
) and negation (-
) tokens. This API is currently undocumented and marked as internal
which means it is prone to change and that custom code relying on it is likely to break.
If, for any reason, you need to revert to the previous search behavior using the GROQ Query API, you can disable the new search functionality by setting search.enableLegacySearch
to true
in your configuration.
// ./sanity.config.ts|js
import {defineConfig} from 'sanity'
export default defineConfig({
// ...rest of config
search: {
enableLegacySearch: true,
}
})
- Supported fields for search configuration: Only string fields and portable text arrays are eligible for the new search configuration. These are the only fields that we currently index and thus are the only ones searchable. Searching within other field types or fields nested deeply in portable text arrays are currently not supported.
- Global weight multiplier: Search weights act as global multipliers across all document types. For instance, if the name field in the customer type has a weight of
2
, and in the author type has a weight of4
, then author documents will rank higher than customer documents for identical name matches in search results. - Default search configuration:
- The field designated as the
title
in the preview config automatically receives a search weight of10
, while thesubtitle
field gets a weight of5
. - Fields marked as
hidden: true
in the preview config are assigned a weight of0
, effectively excluding them from search results. - Any user-specified weight overrides default settings, ensuring custom search relevance can be achieved as needed.
- The field designated as the