You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
* ft.alter * support paramas * remove only and skip * merge * fix imports * add Vector field * update version * push attributes * typo * test * version check * remove .only * remove unued import * add support for DIALECT * clean code Co-authored-by: Avital-Fine <avital.fine@redis.com> Co-authored-by: leibale <leibale1998@gmail.com>
81 lines
2.5 KiB
TypeScript
81 lines
2.5 KiB
TypeScript
import { strict as assert } from 'assert';
|
|
import testUtils, { GLOBAL } from '../test-utils';
|
|
import { SchemaFieldTypes } from '.';
|
|
import { transformArguments } from './SPELLCHECK';
|
|
|
|
describe('SPELLCHECK', () => {
|
|
describe('transformArguments', () => {
|
|
it('without options', () => {
|
|
assert.deepEqual(
|
|
transformArguments('index', 'query'),
|
|
['FT.SPELLCHECK', 'index', 'query']
|
|
);
|
|
});
|
|
|
|
it('with DISTANCE', () => {
|
|
assert.deepEqual(
|
|
transformArguments('index', 'query', { DISTANCE: 2 }),
|
|
['FT.SPELLCHECK', 'index', 'query', 'DISTANCE', '2']
|
|
);
|
|
});
|
|
|
|
describe('with TERMS', () => {
|
|
it('single', () => {
|
|
assert.deepEqual(
|
|
transformArguments('index', 'query', {
|
|
TERMS: {
|
|
mode: 'INCLUDE',
|
|
dictionary: 'dictionary'
|
|
}
|
|
}),
|
|
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'dictionary']
|
|
);
|
|
});
|
|
|
|
it('multiple', () => {
|
|
assert.deepEqual(
|
|
transformArguments('index', 'query', {
|
|
TERMS: [{
|
|
mode: 'INCLUDE',
|
|
dictionary: 'include'
|
|
}, {
|
|
mode: 'EXCLUDE',
|
|
dictionary: 'exclude'
|
|
}]
|
|
}),
|
|
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'include', 'TERMS', 'EXCLUDE', 'exclude']
|
|
);
|
|
});
|
|
});
|
|
|
|
it('with DIALECT', () => {
|
|
assert.deepEqual(
|
|
transformArguments('index', 'query', {
|
|
DIALECT: 1
|
|
}),
|
|
['FT.SPELLCHECK', 'index', 'query', 'DIALECT', '1']
|
|
);
|
|
});
|
|
});
|
|
|
|
testUtils.testWithClient('client.ft.spellCheck', async client => {
|
|
await Promise.all([
|
|
client.ft.create('index', {
|
|
field: SchemaFieldTypes.TEXT
|
|
}),
|
|
client.hSet('key', 'field', 'query')
|
|
]);
|
|
|
|
assert.deepEqual(
|
|
await client.ft.spellCheck('index', 'quer'),
|
|
[{
|
|
term: 'quer',
|
|
suggestions: [{
|
|
score: 1,
|
|
suggestion: 'query'
|
|
}]
|
|
}]
|
|
);
|
|
}, GLOBAL.SERVERS.OPEN);
|
|
});
|