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(core): integrate with Text Search API ordering #6001

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

juice49
Copy link
Contributor

@juice49 juice49 commented Mar 14, 2024

Description

This branch finalises the Text Search API ordering integration. Ordering is now formatted correctly and is included in Text Search API requests.

Note: The Text Search API functionality to support this has not yet been deployed to production.

It also includes a fix for global search results not resetting after ordering has changed. We didn't catch this before because ordering wasn't working at all.

What to review

Does ordering results from global search and document lists work as expected?

Testing

The packages/sanity/src/core/search/text-search/createTextSearch.test.ts test suite ensures ordering requests are formatted correctly.

Copy link

vercel bot commented Mar 14, 2024

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

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Mar 14, 2024 4:53pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 14, 2024 4:53pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Mar 14, 2024 4:53pm

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Mar 14, 2024

Component Testing Report Updated Mar 14, 2024 4:57 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 34s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 13s 3 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 13s 4 2 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 32s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 59s 15 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 1s 18 0 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 20s 9 0 0

Copy link
Contributor

@ricokahler ricokahler left a comment

Choose a reason for hiding this comment

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

Looks good. I just had one non-blocking comment.

@@ -73,12 +73,11 @@ export function getDocumentTypeConfiguration(
}, {})
}

export function getSort(sort: SearchSort[] = []): TextSearchSort[] {
return sort.map<TextSearchSort>(
export function getOrder(sort: SearchSort[] = []): TextSearchOrder[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that the shape of the ordering lines up better with the params we send to the text search API, would it be better to remove this function and inline the logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see any strong reason to do so, but I'm happy to follow your advice 🙂. One advantage to getOrder being an individual function is that we can export it in order to unit test it (which we do).

I've followed this same style for the prefix search integration (#6010), which is unit tested in the same way.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

My preference for inline-it vs abstraction boils down to how complex the abstraction is. My preference is to inline it if I find it easier to understand what's going on by reading the contents of the abstraction rather than reading the name of the function. This is more of an art than a science for sure.

Regarding testing, I prefer to unit test at a higher level if possible and try to preserve the behavior at that level. In this case, I would test the createTextSearch function as a whole and mock out client.observable.request and capture the params that were sent to it and expect it to match a certain value vs testing the smaller parts of createTextSearch.

I kinda subscribe to the philosophy "write tests, not too many, mostly integration". I like this because if the implementation details change, the tests do not. However, this comes at the cost of the test itself being harder to write and requires more mocking.

At the end of the day this is an opinion and I'm not very dogmatic so feel free to merge 😇

Copy link
Contributor Author

@juice49 juice49 Mar 18, 2024

Choose a reason for hiding this comment

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

Thank you for explaining 🙏.

My preference for inline-it vs abstraction boils down to how complex the abstraction is.

That's a great point. There's a (somewhat fuzzy) threshold of complexity at which the cognitive cost of context switching to the abstraction becomes lesser than the cost of reading the implementation inline. I think you're probably right about the threshold not being met in this case.

In this case, I would test the createTextSearch function as a whole

Another great point. I really love testing small units precisely because the tests are simpler to write. createTextSearch isn't tested at the moment—it probably should be—but we'd then be testing the same implementation at two different levels. That's not necessarily a problem, but I think you have a good point that it'd be better to simply invest in testing createTextSearch itself in the first place.

At the end of the day this is an opinion and I'm not very dogmatic so feel free to merge 😇

I think merging is probably the pragmatic thing to do, only because I'm not sure we get a lot of value from changing our approach at this stage. However, I do think these are great points, and they'll certainly shape how I work in the future 🙂. Depending on the time we have available, I may make tweaks here and request another review.

@juice49 juice49 marked this pull request as ready for review March 19, 2024 09:13
@juice49 juice49 requested review from a team and hermanwikner and removed request for a team March 19, 2024 09:13
@juice49 juice49 added this pull request to the merge queue Mar 19, 2024
Merged via the queue into next with commit a59f4bc Mar 19, 2024
36 checks passed
@juice49 juice49 deleted the feat/sdx-1144-text-search-ordering branch March 19, 2024 09:14
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.

2 participants