redis / redis-om-node

Object mapping, and more, for Redis and Node.js. Written in TypeScript.
MIT License
1.18k stars 80 forks source link

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

Open Dhravya opened 2 years ago

Dhravya commented 2 years ago

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.

guyroyse commented 2 years ago

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 commented 2 years ago

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.

Dhravya commented 2 years ago

yep

CaptainCodeman commented 2 years ago

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.

guyroyse commented 1 year ago

What would we want to expected behavior to be here? Are you wanting to search where domain is an empty string, or do you just not want to include domain in the search if it is empty. I could certainly implement the latter, but, as @CaptainCodeman mentions, the former isn't terribly doable.

You could work around this as well, if you want the latter scenario, like this:

const search = repository.search();

search.where("slug").eq(slug);
if (domain) search.and("domain").eq(domain);

const image = search.return.first();
mendiu commented 11 months ago

it happens to me something very similar but when I search strings containing "@" I get this error: Syntax error at offset 27 near com ie: Page @email:(kikomen@gmail.com)

Pk13055 commented 2 weeks ago

Similar issue when searching for strings containing "-"