sanity
sanity copied to clipboard
feat(default-layout): sortable search results, search phrases, experimental config

Description
Features
- Order search results by relevance, created and last updated date.
- Search for documents containing an exact phrase by wrapping text inside double quotes.
- Add
__experimental_omnisearch_visibility: trueto your document schemas to hide them from omnisearch. Perfect for hiding workflow-related documents or configuration singletons that don’t need to be accessed frequently. - View relevance scores for search results via a debug flag (
#_debug_search_score)
Bug fixes
- Fixes an issue where the scroll position of search results wasn’t being correctly retained in some instances.
- Fixes an issue where search would cause the studio to crash if Local Storage is unavailable.
What to review
Notable changes
-
Taking cues from the reference and cross dataset reference input components – the function to generate weighted search is now colocated within
default-layoutrather than being an export of@sanity/base/search- Similar to reference / cross reference input components, this now imports from
@sanity/base/_internal - ~~Given that
part:@sanity/base/searchandpart:@sanity/base/search/weightedare not being used anywhere else in the studio, they’ve been removed~~
- Similar to reference / cross reference input components, this now imports from
-
Logic for how we extract search queries and calculate scores has been expanded to accommodate searching for phrases in wrapped quotes:
- Fundamentally, this is handled in a very similar way to how search worked prior. My understanding of search, and how phrases come into play can be found here (internal doc)
- The important thing to note is that how we handle non-quoted text searches hasn’t changed. If you don’t engage with this feature then you won’t notice a difference here.
-
A few more comments are now attached with each search query for measurement. Full example:
// findability-mvi:2 // findability-recent-search:4 // findability-selected-types:2 // findability-sort:relevanceIn the above example,
findability-recent-search:4indicates that this was the 5th item clicked in recent searches. All these comments will be removed once client-side instrumentation is in place. -
In the test studio: a debug schema
experimentalOmnisearchVisibilityTesthas been added. These documents have__experimental_omnisearch_visibility:falseand won’t appear in omnisearch. -
Sorting by relevance will now sort by
_updatedAt descin GROQ before applying scoring on the client, leaning towards more recent documents in general. Previously, omnisearch was sorting on_id asc.- Search within reference + cross dataset reference fields are unchanged, and will continue to sort on
_id asc.
- Search within reference + cross dataset reference fields are unchanged, and will continue to sort on
-
Notable refactoring:
- Simplified
createWeightedSearchsignature slightly, and have moved more into theSearchOptionstype - Some unused dev dependencies were removed from
default-layout(mocha,nyc) and it now usesreact-testing-library. default-layoutwas also added to the root leveljest.config.js- Search related tests in
@sanity/baseare now colocated and have been expanded on slightly. - Quite a bit of code was touched to ensure this is valid once we can enable
strictNullChecks: true.
- Simplified
Things to test
- Change the sorting of search results:
- Does this work and make sense to you? Bearing in mind scoring isn’t taken into consideration when not sorting on relevance.
- Search on phrases with quoted text:
- View relevance scoring in debug mode – do these scores seem reasonable to you?
- Try search for strings with special characters – some good candidates to compare and contrast (test studio):
"winnie-the-pooh"vswinnie-the-pooh"go, team. go!"vsgo, team. go!
Notes for release
TBD
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Updated |
|---|---|---|---|
| studio-workshop | ✅ Ready (Inspect) | Visit Preview | Sep 20, 2022 at 0:54AM (UTC) |
| test-studio | ✅ Ready (Inspect) | Visit Preview | Sep 20, 2022 at 0:54AM (UTC) |
Thanks @snorrees!
Re: scores: I agree! Especially with how search will use preview fields (which can be automatically inferred if you don't have a preview configuration) .... mix in the interplay between __experimental_search and it can all seem a bit much. It begs the question of whether this needs to be surfaced in documentation more.