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

Score function not behaving as expected when using Sanity Client, vision, or sanity-cli #7496

Open
matt-koevort opened this issue Sep 11, 2024 · 0 comments

Comments

@matt-koevort
Copy link

Describe the bug

I'm running into an issue where I am frequently getting the following error:

score() function received unexpected expression

When using the score function.

As mentioned in the title, this error occurs in Sanity Studio Vision, the Sanity CLI using sanity documents query, as well as the Sanity Client in @sanity/client (obviously being the biggest issue).

What's interesting, is that groq-js evaluate produces correct results without errors.

Additionally, I would expect that running score against a regular array (not a document filter) should work. The following query:

[{ "title": "hello" }] | score(title match "hello")

produces the error

score() function cannot be used in its current position

(again, this works using groq-js)

To Reproduce

There are a number of combinations in which I have found this to be the case:

  1. When the value of the field being matched is null or an empty string:
*[]{
  "title": null,
  _score,
} | score(title match "hello")
  1. When the result doesn't match at all
*[]{
  "title": "no match",
  _score,
} | score(title match "hello")
  1. When there is a match, but the _score field is excluded from the projection.
*[]{
  "title": "hello",
} | score(title match "hello")

Expected behavior

The score function should not be erroring with simple, valid expressions passed to it.

Screenshots
If applicable, add screenshots to help explain your problem.

Which versions of Sanity are you using?

@sanity/cli (global)          3.56.0 (latest: 3.57.2)
@sanity/assist                 3.0.6 (up to date)
@sanity/dashboard              3.1.6 (latest: 4.0.0)
@sanity/eslint-config-studio   4.0.0 (up to date)
@sanity/vision                3.56.0 (latest: 3.57.2)
sanity                        3.56.0 (latest: 3.57.2)

What operating system are you using?

MacOS

Which versions of Node.js / npm are you running?

10.7.0
v20.14.0

Additional context

Add any other context about the problem here.

Security issue?

Any security issues should be submitted directly to [email protected]. In order to determine whether you are dealing with a security issue, ask yourself these two questions:

  • Can I access something that's not mine, or something I shouldn't have access to?
  • Can I disable something for other people? If the answer to either of those two questions are "yes", then you're probably dealing with a security issue. Note that even if you answer "no" to both questions, you may still be dealing with a security issue, so if you're unsure, just email us at [[email protected]](mailto:[email protected].
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

No branches or pull requests

1 participant