Studio

Studio search configuration

Global search for Sanity Studio allows content search, can hide specific documents, and allows custom field weighting.

Experimental feature

The global search for Sanity Studio lets you search your Content Lake dataset for any document that matches your term, or narrow down by filtering your query by schema types. You can activate the global search from the 🔍 icon in the top toolbar, or with the ctrl/cmd + k hotkey.

Hide documents from global search

There may be instances where you want to keep specific documents from appearing in the search results. To hide search results for a particular document type and remove it as a selectable filter, set the __experimental_omnisearch_visibility property to false on the document type:

{
  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,
  // ...
}

Some example use cases:

  • 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

Define custom weighting on fields

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 },
        // ...
      }
    }
    // ...
  ],
  // ...
}

Selecting a search strategy

Define your desired search strategy in the sanity.config.js|ts file. Accepted values are groqLegacy, groq2024, and textSearch.

You must be on Studio version v3.70.0 or greater to define strategy and opt-in to groq2024.

import { defineConfig } from 'sanity`

export default defineConfig({
 search: {
   strategy: 'groq2024'
 },
})

groqLegacy

Default search strategy in current studio versions.

groq2024

Considered experimental and opt-in only until the underlying API is moved to a versioned endpoint.

Updates compared to groqLegacy search:

  • Improved performance for large datasets.
  • The ability to search deeply nested content beyond the default five levels that groqLegacy is restricted to today.
  • The ability to search all Portable Text content.
  • Support for “Google-style” query string parsing. In the below query string, wine, good vintage, and fruit* must all be present in order for the query to match. In other words, there is an implicit “and” between the words. Results with beer in will be omitted.
wine -beer "good vintage" fruit*

Tokenization and word handling in groq2024

  • Text search operates on all tokens that are 1 character or longer, up to 255 character maximum.
  • _ is not a word-breaking character.
  • Punctuation is ignored.
  • Apostrophes are not word-breaking: bob does not match bob's or vice versa.
  • All words and phrases (with/without wildcards) must appear in at least one attribute value.
  • Negations do not match any attribute values.
  • Phrases must not match across attribute values (i.e. half matching one value and another half matching another value).

Exact matching rules for groq2024

ScenarioSearch TermBehaviourShould Match Should Not Match
Numbers1234Match numbers that are separated by punctuation or spaceThe number is 1234!X1234Y
Floating point numbers3.145MatchesThe answer is 3.145The answer is 3 145
Currency numbers$100Match number only (not currency)The price is $100-
Prefixco*Match prefix of wordsco, covid, corvetteAnything not starting with “co”
Prefix + wildcardco*eMatch prefix and suffixcorvetteAnything not having “co” prefix and “e” suffix
Middle wildcard*co*Match substrings inside wordscorvette, acorn, texacoAnything not containing the substring “co”
Special symbols (not punctuation)®️, ™️Match exactly--
Underscoresfoo_barMatch exactly; underscores are part of the wordfoo_barfoo bar
Phrases“hello world”Match exactly the sequence of words, ignoring punctuation"hello world", "hello, world"hello to the world hey world, hello!
Phrases with wildcard at the end“hello world*”Match exactly the sequence of words, ignoring punctuation, with wildcard match on the last word"hello world", "hello worlds"hello to the world hey world, hello!
Negationfoo -barSearch excludes what you specify

textSearch

Search strategy some customers may use for historic purposes but not a recommended strategy. This will likely be deprecated in the future.

Gotcha

A few things to note

  • 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 the author type has a weight of 4, 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 of 10, while the subtitle field gets a weight of 5.
    • Any user-specified weight overrides default settings, ensuring custom search relevance can be achieved as needed.
    • If you have customized the preview options using a prepare function search weights cannot be inferred from the preview configuration so explicit custom field weights must be used if you want to boost specific fields.
    • If you have a reusable custom type you need to define search weighting on the type definition itself.
    • Fields marked as hidden: true in the preview config are scored lower to push them lower in the result set.

Protip

Was this page helpful?