diff --git a/packages/search/lib/commands/SEARCH.spec.ts b/packages/search/lib/commands/SEARCH.spec.ts index 2b0e6588fb1..931458b3a25 100644 --- a/packages/search/lib/commands/SEARCH.spec.ts +++ b/packages/search/lib/commands/SEARCH.spec.ts @@ -12,13 +12,6 @@ describe('SEARCH', () => { ); }); - it('with NOCONTENT', () => { - assert.deepEqual( - transformArguments('index', 'query', { NOCONTENT: true }), - ['FT.SEARCH', 'index', 'query', 'NOCONTENT'] - ); - }); - it('with VERBATIM', () => { assert.deepEqual( transformArguments('index', 'query', { VERBATIM: true }), diff --git a/packages/search/lib/commands/SEARCH.ts b/packages/search/lib/commands/SEARCH.ts index 77eddef107b..ff7ab7e201d 100644 --- a/packages/search/lib/commands/SEARCH.ts +++ b/packages/search/lib/commands/SEARCH.ts @@ -6,7 +6,6 @@ export const FIRST_KEY_INDEX = 1; export const IS_READ_ONLY = true; export interface SearchOptions { - NOCONTENT?: true; VERBATIM?: true; NOSTOPWORDS?: true; // WITHSCORES?: true; diff --git a/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts b/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts new file mode 100644 index 00000000000..de0e7c36229 --- /dev/null +++ b/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts @@ -0,0 +1,36 @@ +import { strict as assert } from 'assert'; +import { SchemaFieldTypes } from '.'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './SEARCH_NOCONTENT'; + +describe('SEARCH_NOCONTENT', () => { + describe('transformArguments', () => { + it('without options', () => { + assert.deepEqual( + transformArguments('index', 'query'), + ['FT.SEARCH', 'index', 'query', 'NOCONTENT'] + ); + }); + }); + + describe('client.ft.searchNoContent', () => { + testUtils.testWithClient('returns total and keys', async client => { + await Promise.all([ + client.ft.create('index', { + field: SchemaFieldTypes.NUMERIC + }), + client.hSet('1', 'field', 'field1'), + client.hSet('2', 'field', 'field2'), + client.hSet('3', 'field', 'field3') + ]); + + assert.deepEqual( + await client.ft.searchNoContent('index', '*'), + { + total: 3, + documents: ['1','2','3'] + } + ); + }, GLOBAL.SERVERS.OPEN); + }); +}); diff --git a/packages/search/lib/commands/SEARCH_NOCONTENT.ts b/packages/search/lib/commands/SEARCH_NOCONTENT.ts new file mode 100644 index 00000000000..133308720bb --- /dev/null +++ b/packages/search/lib/commands/SEARCH_NOCONTENT.ts @@ -0,0 +1,30 @@ +import { RedisCommandArguments } from "@redis/client/dist/lib/commands"; +import { pushSearchOptions } from "."; +import { SearchOptions, SearchRawReply } from "./SEARCH"; + +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + +export function transformArguments( + index: string, + query: string, + options?: SearchOptions +): RedisCommandArguments { + return pushSearchOptions( + ['FT.SEARCH', index, query, 'NOCONTENT'], + options + ); +} + +export interface SearchNonContentReply { + total: number; + documents: Array; +}; + +export function transformReply(reply: SearchRawReply): SearchNonContentReply { + return { + total: reply[0], + documents: reply.slice(1) + }; +} diff --git a/packages/search/lib/commands/index.ts b/packages/search/lib/commands/index.ts index b9c6a3b95d9..75a2b4e380a 100644 --- a/packages/search/lib/commands/index.ts +++ b/packages/search/lib/commands/index.ts @@ -20,6 +20,7 @@ import * as INFO from './INFO'; import * as PROFILESEARCH from './PROFILE_SEARCH'; import * as PROFILEAGGREGATE from './PROFILE_AGGREGATE'; import * as SEARCH from './SEARCH'; +import * as SEARCH_NOCONTENT from './SEARCH_NOCONTENT'; import * as SPELLCHECK from './SPELLCHECK'; import * as SUGADD from './SUGADD'; import * as SUGDEL from './SUGDEL'; @@ -80,6 +81,8 @@ export default { profileAggregate: PROFILEAGGREGATE, SEARCH, search: SEARCH, + SEARCH_NOCONTENT, + searchNoContent: SEARCH_NOCONTENT, SPELLCHECK, spellCheck: SPELLCHECK, SUGADD, @@ -395,10 +398,6 @@ export function pushSearchOptions( args: RedisCommandArguments, options?: SearchOptions ): RedisCommandArguments { - if (options?.NOCONTENT) { - args.push('NOCONTENT'); - } - if (options?.VERBATIM) { args.push('VERBATIM'); }