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

feat: support search weight configuration for slug fields #7852

Open
wants to merge 8 commits into
base: next
Choose a base branch
from

Conversation

juice49
Copy link
Contributor

@juice49 juice49 commented Nov 20, 2024

Description

  • Search weight can now be assigned to slug fields using the options.search.weight option. It was previously not permitted by the types, nor had any impact if set.
  • These weights will now be reflected in global search results when "Best match" sorting is selected and in reference search results.
  • As a consequence of this change, search queries no longer attempt to match on the deprecated slug source field, resulting in slightly smaller search queries. Matching only occurs on the slug object's current field.

Global Search Example

Imagine two different document types:

  • book contains a title field that is implicitly given a weight of 10 because it's selected as the list preview title.
  • author contains a slug field that is explicitly given a weight of 1_000 via the options.search.weight option.
Global Search - next Global Search - fix/sapp-34/slug-field-weights
global-search-next global-search-sapp-34
Reference Search - next Reference Search - fix/sapp-34/slug-field-weights
reference-search-next reference-search-sapp-34

Both book.title and author.slug contain an exact match for the term "xoxoxo". With the changes introduced in this branch, the weighting set for author.slug is respected, and the author document is therefore recognised as more relevant than the book document.

What to review

  • The order of global Studio search results when sorting by "Best match" and in reference search.
  • Setting options.search.weight on a slug (or slug-based/aliased) field.

Testing

  • Updated unit tests in packages/sanity/src/core/search/common/__tests__/deriveSearchWeightsFromType.test.ts.

Notes for release

It's now possible to configure search weights for slug fields using the options.search.weight field option:

defineField({
  name: 'slug',
  type: 'slug',
+ options: {
+   search: {
+     weight: 50,
+   },
+ },
}),

The slug field's weight will now be respected when using global search with "Best match" sorting selected, and when using reference search.

stipsan and others added 5 commits November 19, 2024 09:01
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Copy link

vercel bot commented Nov 20, 2024

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

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 2:39pm
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 2:39pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 2:39pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 2:39pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Nov 20, 2024 2:39pm

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Nov 20, 2024

Component Testing Report Updated Nov 20, 2024 2:32 PM (UTC)

❌ Failed Tests (1) -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 47s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 9s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 32s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 40s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 11s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 3m 0s 0 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 47s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 50s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 19s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 9s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 27s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 19s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ❌ Failed (Inspect) 47s 11 0 1
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

Copy link
Contributor

github-actions bot commented Nov 20, 2024

⚡️ Editor Performance Report

Updated Wed, 20 Nov 2024 14:34:43 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
article (title) 16.3 efps (62ms) 21.7 efps (46ms) -16ms (-25.2%)
article (body) 53.3 efps (19ms) 53.2 efps (19ms) +0ms (+0.3%)
article (string inside object) 18.2 efps (55ms) 23.5 efps (43ms) -13ms (-22.7%)
article (string inside array) 15.6 efps (64ms) 21.5 efps (47ms) -18ms (-27.3%)
recipe (name) 29.4 efps (34ms) 45.5 efps (22ms) -12ms (-35.3%)
recipe (description) 32.3 efps (31ms) 52.6 efps (19ms) -12ms (-38.7%)
recipe (instructions) 99.9+ efps (7ms) 99.9+ efps (6ms) -1ms (-/-%)
synthetic (title) 15.2 efps (66ms) 19.2 efps (52ms) -14ms (-21.2%)
synthetic (string inside object) 15.4 efps (65ms) 18.9 efps (53ms) -12ms (-18.5%)

efps — editor "frames per second". The number of updates assumed to be possible within a second.

Derived from input latency. efps = 1000 / input_latency

Detailed information

🏠 Reference result

The performance result of sanity@latest

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 62ms 70ms 93ms 300ms 675ms 13.8s
article (body) 19ms 23ms 45ms 195ms 313ms 6.1s
article (string inside object) 55ms 57ms 68ms 209ms 485ms 9.1s
article (string inside array) 64ms 71ms 83ms 228ms 863ms 9.7s
recipe (name) 34ms 36ms 47ms 83ms 0ms 8.9s
recipe (description) 31ms 32ms 34ms 61ms 0ms 6.0s
recipe (instructions) 7ms 9ms 11ms 45ms 23ms 3.4s
synthetic (title) 66ms 70ms 78ms 173ms 1416ms 15.6s
synthetic (string inside object) 65ms 68ms 72ms 323ms 1030ms 9.9s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 46ms 53ms 65ms 348ms 462ms 12.0s
article (body) 19ms 22ms 31ms 174ms 203ms 5.9s
article (string inside object) 43ms 45ms 54ms 115ms 231ms 7.2s
article (string inside array) 47ms 48ms 57ms 270ms 391ms 7.8s
recipe (name) 22ms 26ms 30ms 48ms 0ms 7.4s
recipe (description) 19ms 21ms 24ms 38ms 0ms 4.8s
recipe (instructions) 6ms 8ms 9ms 11ms 0ms 3.1s
synthetic (title) 52ms 53ms 59ms 305ms 620ms 13.1s
synthetic (string inside object) 53ms 56ms 70ms 152ms 688ms 8.0s

📚 Glossary

column definitions

  • benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
  • latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
  • p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
  • p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
  • p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
  • blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
  • test duration — how long the test run took to complete.

@juice49 juice49 force-pushed the fix/sapp-34/slug-field-weights branch from 8e419cb to 6d3653d Compare November 20, 2024 14:20
@juice49 juice49 changed the title feat: support searching and weighting on slug fields feat: support search weight configuration for slug fields Nov 20, 2024
Copy link
Contributor

@RitaDias RitaDias left a comment

Choose a reason for hiding this comment

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

Just some comments to get some clarification before ✅ 🙏

const isSearchConfiguration = (options: unknown): options is SearchConfiguration =>
isRecord(options) && 'search' in options && isRecord(options.search)

function isSchemaType(input: SchemaType | CrossDatasetType | undefined): input is SchemaType {
return typeof input !== 'undefined' && 'name' in input
}

function getFullyQualifiedPath(schemaType: SchemaType, path: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we need to add a comment or maybe change the name? I'm just not sure what "fully qualified" would mean in this context 🥲

Could it be simplified to getFullPath or something similar?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or, since it seems to just be used when the field is a Slug as per line 83 maybe make it related to that? 🤔

Copy link
Contributor Author

@juice49 juice49 Nov 22, 2024

Choose a reason for hiding this comment

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

That's a good point. "Fully qualified name" lives in my brain for some reason, so it's intuitive for me. But I understand it may not be for everybody.

In this case, I think it makes sense. A selected path may point to a slug field, but the fully qualified path for searching and weighting is the field located at slug.current.

In a different branch, this function also automatically converts references the user has defined using dot notation e.g. some.reference.field becomes some.reference->field.

I think there is a some nuance between "full path" and "fully qualified path" but I am open to changing it. What do you think? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants