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

fix(core): various fixes and improvements to studio search [v2] #4704

Merged
merged 21 commits into from
Jul 20, 2023

Conversation

robinpyon
Copy link
Contributor

@robinpyon robinpyon commented Jul 17, 2023

Description

This PR brings a number of fixes and minor improvements to studio search in v2. Please refer to the internal slack thread for more context.

Search path generation:

  • The maximum traversal depth (SEARCH_DEPTH_LIMIT) has increased significantly (now 15, up from 4)
  • To compensate for this, we've introduced a maximum cap on search paths (SEARCH_PATH_LIMIT) generated per root-level object (defaults to 500)
  • When sorting paths for truncation, we sort by path length (shortest to longest) and then by name (alphabetically), meaning longer paths will be removed first.

These changes help ensure that deeper fields are more easily searchable, whilst the path limit per object ensures a reasonable cap when dealing with recursive structures, preventing the client from hanging when generating these on studio initialisation.

Search query generation:

  • We set a maximum cap on unique attributes (SEARCH_ATTR_LIMIT) included in search queries (defaults to 1000).
  • This provides some limited protection from ensuring we don't generate search queries that are too large and are likely to timeout
  • User created __experimental_search paths are always included, regardless of the limit defined above
  • Unnecessary whitespace has been reduced to slightly reduce request payload size
  • We no longer unnecessarily include _id and _type fields twice in object projections, also reducing response sizes slightly
  • We now export the internal createSearchQuery function (in addition to the existing createWeightedSearch)

Combined with the changes to search path generation, this should mean that type-constrained searches (e.g. filtering by document types) should be able to access much more deeply nested fields. In most 'regular' cases (i.e. studio schema without recursive / circular structures), users should be able to search beyond the original 4 level limit we had before, even when searching across all document types.

Search weighting / scoring:

  • Search stories included in each WeightedHit now also includes indices – a value which indicates any matching array indices, where applicable. Custom search implementations can use this to visually surface additional context.
  • We now correctly assign search scores to partial word matches
  • Fixed an issue where array items beyond the first index weren't being assigned the correct score included when using array paths in __experimental_search

New unstable environment variables (which override the above):

  • SANITY_STUDIO_UNSTABLE_SEARCH_ATTR_LIMIT
  • SANITY_STUDIO_UNSTABLE_SEARCH_DEPTH_LIMIT
  • SANITY_STUDIO_UNSTABLE_SEARCH_PATH_LIMIT

What to review

  • Partial word searches (e.g. fo, tes on the test studio) – these should now be ordered much more intuitively
  • Search payloads should have whitespace reduced and should generally be smaller, due to changes in path generation
  • It should be possible to search for deeply nested fields when constraining search (in the test studio, try search for "can you see me" with the "Recursive Objects Test" type selected.)

Notes for release

  • Minor fixes and improvements to studio search

…isplay skipped paths in generated search specs
…d support for defining MAX_UNIQUE_ATTRIBUTES via env var
@vercel
Copy link

vercel bot commented Jul 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Jul 20, 2023 3:02pm
studio-workshop ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 3:02pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 3:02pm

@robinpyon robinpyon added the v2 label Jul 17, 2023
…exclude _id from whole word score generation
@robinpyon robinpyon marked this pull request as ready for review July 17, 2023 12:27
@robinpyon robinpyon changed the title fix(core): various fixes and improvements to studio search fix(core): various fixes and improvements to studio search [v2] Jul 17, 2023
Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

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

Really excellent work @robinpyon!

Left a few comments inline, nothing big, so good to merge from what I can tell.

if (childType.jsonType === 'string') {
return [...acc, {path, weight: 1}]
}
if (isPortableTextArray(childType)) {
Copy link
Member

Choose a reason for hiding this comment

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

good catch - should we "forwardport" this to current?

packages/@sanity/schema/src/legacy/searchConfig/resolve.ts Outdated Show resolved Hide resolved
packages/@sanity/schema/src/legacy/searchConfig/resolve.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants