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(sanity): switch to legacy search if custom GROQ filter contains incompatible operation #6566

Draft
wants to merge 5 commits into
base: next
Choose a base branch
from

Conversation

juice49
Copy link
Contributor

@juice49 juice49 commented May 3, 2024

Description

This branch adopts a hybrid approach for supporting the Text Search API alongside the GROQ Query API. This is applicable for parts of Studio that support custom GROQ filters, such as document lists and reference fields. Studio's filter API allows developers to use any GROQ operation, but unfortunately, the Text Search API does not provide a full GROQ implementation for filtering. Notably, it currently lacks support for dereferences, subqueries, and function calls.

With this change, Studio will fall back to the GROQ Query API if it detects any operation in the filter GROQ that is incompatible with the Text Search API. This makes it possible to enable Text Search API for Studios without the filter configuration leading to errors.

What to review

  • Does the incompatible GROQ operation detection seem reasonable?
  • We currently log a warning to the console when Text Search API is enabled and an incompatible GROQ operation causes Studio to fall back to the GROQ Query API. Should we consider a more prominent warning?

Testing

  • Unit tests for incompatible GROQ detection have been added in packages/sanity/src/core/search/utils/groq.test.ts.

In a Studio that has the Text Search API search strategy enabled, try using a document list or reference field that has an incompatible GROQ filter configured.

You can enable text search API by setting the search.enableLegacySearch Studio configuration property to false.

When navigating Studio, you should see data is generally sourced used the Text Search API (data/textsearch).

There is an example of an incompatible reference field in the test-studio named referenceWithSubqueryFilter. You can find it by navigating to http://localhost:3333/test/structure/input-standard;referenceTest;c5a278ae-f38c-47aa-b95f-f038db7d9c9f and scrolling to the "Subquery filter" field.

Copy link

vercel bot commented May 3, 2024

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

Name Status Preview Comments Updated (UTC)
page-building-studio ❌ Failed (Inspect) May 23, 2024 4:00pm
performance-studio ✅ Ready (Inspect) Visit Preview May 23, 2024 4:00pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2024 4:00pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2024 4:00pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview May 23, 2024 4:00pm

@juice49 juice49 changed the title fix(sanity): switch to legacy search if custom GROQ filter contains s… fix(sanity): switch to legacy search if custom GROQ filter contains subquery May 3, 2024
Copy link
Contributor

github-actions bot commented May 3, 2024

No changes to documentation

Copy link
Contributor

github-actions bot commented May 3, 2024

Component Testing Report Updated May 23, 2024 4:07 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 35s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 31s 11 7 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 9s 3 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 37s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 21s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 4s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 7s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 20s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 15s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 29s 12 0 0

@juice49 juice49 force-pushed the fix/sdx-1313-hybrid-search branch from 521a822 to 672cdd6 Compare May 3, 2024 16:03
@juice49 juice49 changed the title fix(sanity): switch to legacy search if custom GROQ filter contains subquery fix(sanity): switch to legacy search if custom GROQ filter contains incompatible operation May 3, 2024
@juice49 juice49 force-pushed the fix/sdx-1313-hybrid-search branch from 02f82f2 to f7e5fcb Compare May 22, 2024 10:54
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.

None yet

1 participant