redis-om-node icon indicating copy to clipboard operation
redis-om-node copied to clipboard

Redis search: syntax error when query is `""`

Open Dhravya opened this issue 1 year ago • 6 comments

I have a search query that looks something like this:

  const image = await repository
    .search()
    .where("slug")
    .eq(slug)
    .and("domain")
    .eq(domain || "")
    .first();

However, upon running this, I receive the following error:

RedisError: The query to RediSearch had a syntax error: "Syntax error at offset 36 near domain".
This is often the result of using a stop word in the query. Either change the query to not use a stop word or change the stop words in the schema definition.

Most likely, the redis command generated is invalid because there's no value over there.

This is far from ideal, because in some cases, I would want to fallback to an empty string in the search query.

Dhravya avatar Aug 30 '22 13:08 Dhravya

Can you share your Schema here as well? I'm assuming that domain is a string given the error but would like to be sure. Thanks!

guyroyse avatar Aug 30 '22 13:08 guyroyse

Also, 99.9% certain this is a bug. Just need to add code to check when building the query for the special case of an empty string.

guyroyse avatar Aug 30 '22 13:08 guyroyse

yep

Dhravya avatar Sep 08 '22 15:09 Dhravya

This may not be immediately doable: https://forum.redis.com/t/how-to-query-for-absence-empty-field/147

it might be a case of storing a special value to signify "not set", such as an underscore (something that wouldn't normally be matched on) so it can then be searched on.

CaptainCodeman avatar Sep 27 '22 19:09 CaptainCodeman