Skip to content

ft.search exact match does not works with params ? #2922

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

Open
didierdemoniere opened this issue Apr 5, 2025 · 1 comment
Open

ft.search exact match does not works with params ? #2922

didierdemoniere opened this issue Apr 5, 2025 · 1 comment
Labels

Comments

@didierdemoniere
Copy link

Description

hello, i don't know why but exact match and params dont seems to works together.

Reproduction

import { createClient, SchemaFieldTypes } from 'redis';
import { GenericContainer } from 'testcontainers';

(async () => {
  const redisClient = await new GenericContainer(
    'redis/redis-stack-server:7.2.0-RC1-arm64'
  )
    .withExposedPorts(6379)
    .start()
    .then((container) => {
      const client = createClient({ url: `redis://${container.getHost()}:${container.getMappedPort(6379)}` });
      client.on('end', async () => await container.stop());
      client.on('error', (err) => console.log('Redis Client Error', err));
      return client.connect().then(() => client);
    });
  
  await redisClient.json.set(`noderedis:users:0`, '$', {
    name: 'Alice Johnson',
    age: 32,
    coins: 100
  });

  await redisClient.ft.create('idx:users', {
    '$.name': {
      type: SchemaFieldTypes.TEXT,
      SORTABLE: 'UNF',
      AS: 'name'
    },
    '$.age': {
      type: SchemaFieldTypes.NUMERIC,
      AS: 'age'
    },
    '$.coins': {
      type: SchemaFieldTypes.NUMERIC,
      AS: 'coins'
    }
  }, {
    ON: 'JSON',
    PREFIX: 'noderedis:users'
  });

  console.log({
    // ✅ works: 1 result
    bare: await redisClient.ft.search('idx:users', '@name:"Alice Johnson"', { DIALECT: 2 }),
    // ✅ works: 1 result
    withParamsNumber: await redisClient.ft.search('idx:users', '@age:[$age $age]', { DIALECT: 2, PARAMS: { age: 32 } }),
    // ❌ no results
    withParamsExactMatch1: await redisClient.ft.search('idx:users', '@name:"$name"', { DIALECT: 2, PARAMS: { name: 'Alice Johnson' } }),
    // ❌ no results
    withParamsExactMatch2: await redisClient.ft.search('idx:users', '@name:$name', { DIALECT: 2, PARAMS: { name: '"Alice Johnson"' } }),
    // ✅ works: 1 result
    withParamsMatch: await redisClient.ft.search('idx:users', '@name:($name)', { DIALECT: 2, PARAMS: { name: 'Alice' } }),
  })

  await redisClient.disconnect();
})();

Node.js Version

No response

Redis Server Version

No response

Node Redis Version

No response

Platform

No response

Logs

@didierdemoniere
Copy link
Author

i just found an interesting clue:

while

redisClient.ft.search('idx:users', '@name:"$name"', { DIALECT: 2, PARAMS: { name: 'Alice Johnson' } })

does not work.

redisClient.ft.search('idx:users', '@name:"$name1 $name2"', { DIALECT: 2, PARAMS: { name1: 'Alice', name2: 'Johnson' } })

works.

same thing for other type of match:

redisClient.ft.search('idx:users', '@name:($name)', { DIALECT: 2, PARAMS: { name: 'Alice Johnson' } })

does not work.

redisClient.ft.search('idx:users', '@name:($name1 $name2)', { DIALECT: 2, PARAMS: { name1: 'Alice', name2: 'Johnson' } })

works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant