From e9ee84cc08b0960003fbb292da8dd78f4baca6a5 Mon Sep 17 00:00:00 2001 From: Brett Burch Date: Fri, 8 Sep 2023 14:48:03 -0600 Subject: [PATCH 1/6] Add support for NOCONTENT in FT.SEARCH --- packages/search/lib/commands/SEARCH.spec.ts | 7 +++++++ packages/search/lib/commands/SEARCH.ts | 2 +- packages/search/lib/commands/index.ts | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/search/lib/commands/SEARCH.spec.ts b/packages/search/lib/commands/SEARCH.spec.ts index 931458b3a25..2b0e6588fb1 100644 --- a/packages/search/lib/commands/SEARCH.spec.ts +++ b/packages/search/lib/commands/SEARCH.spec.ts @@ -12,6 +12,13 @@ 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 ef6c0d5c2d1..77eddef107b 100644 --- a/packages/search/lib/commands/SEARCH.ts +++ b/packages/search/lib/commands/SEARCH.ts @@ -6,7 +6,7 @@ export const FIRST_KEY_INDEX = 1; export const IS_READ_ONLY = true; export interface SearchOptions { - // NOCONTENT?: true; TODO + NOCONTENT?: true; VERBATIM?: true; NOSTOPWORDS?: true; // WITHSCORES?: true; diff --git a/packages/search/lib/commands/index.ts b/packages/search/lib/commands/index.ts index 0470aff213f..b9c6a3b95d9 100644 --- a/packages/search/lib/commands/index.ts +++ b/packages/search/lib/commands/index.ts @@ -395,6 +395,10 @@ export function pushSearchOptions( args: RedisCommandArguments, options?: SearchOptions ): RedisCommandArguments { + if (options?.NOCONTENT) { + args.push('NOCONTENT'); + } + if (options?.VERBATIM) { args.push('VERBATIM'); } From 08cb64815e8897595a286c15e55fe025c6c08631 Mon Sep 17 00:00:00 2001 From: Brett Burch Date: Wed, 13 Sep 2023 21:56:26 -0600 Subject: [PATCH 2/6] Move support for NOCONTENT search option from client.search to client.searchNoContent --- packages/search/lib/commands/SEARCH.spec.ts | 7 ---- packages/search/lib/commands/SEARCH.ts | 1 - .../lib/commands/SEARCH_NOCONTENT.spec.ts | 36 +++++++++++++++++++ .../search/lib/commands/SEARCH_NOCONTENT.ts | 30 ++++++++++++++++ packages/search/lib/commands/index.ts | 7 ++-- 5 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts create mode 100644 packages/search/lib/commands/SEARCH_NOCONTENT.ts 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'); } From 29239bfd86cb853ba1dd33df7a42b27a09f0a0a9 Mon Sep 17 00:00:00 2001 From: Brett Burch Date: Thu, 14 Sep 2023 14:35:42 -0600 Subject: [PATCH 3/6] Add test for SEARCH_NOCONTENT#transformReply --- .../search/lib/commands/SEARCH_NOCONTENT.spec.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts b/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts index de0e7c36229..205dda97c09 100644 --- a/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts +++ b/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts @@ -1,7 +1,7 @@ import { strict as assert } from 'assert'; import { SchemaFieldTypes } from '.'; import testUtils, { GLOBAL } from '../test-utils'; -import { transformArguments } from './SEARCH_NOCONTENT'; +import { transformArguments, transformReply } from './SEARCH_NOCONTENT'; describe('SEARCH_NOCONTENT', () => { describe('transformArguments', () => { @@ -13,7 +13,16 @@ describe('SEARCH_NOCONTENT', () => { }); }); - describe('client.ft.searchNoContent', () => { + describe('transformReply', () => { + it('returns total and keys', () => { + assert.deepEqual(transformReply([3, '1', '2', '3']), { + total: 3, + documents: ['1', '2', '3'] + }) + }); + }); + + describe.skip('client.ft.searchNoContent', () => { testUtils.testWithClient('returns total and keys', async client => { await Promise.all([ client.ft.create('index', { From 32c78807e4efb8e2df0921aa8ab5e9f3b92c5dd9 Mon Sep 17 00:00:00 2001 From: Brett Burch Date: Thu, 14 Sep 2023 14:35:50 -0600 Subject: [PATCH 4/6] Fix typo --- packages/search/lib/commands/SEARCH_NOCONTENT.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/search/lib/commands/SEARCH_NOCONTENT.ts b/packages/search/lib/commands/SEARCH_NOCONTENT.ts index 133308720bb..ab50ae2b9ff 100644 --- a/packages/search/lib/commands/SEARCH_NOCONTENT.ts +++ b/packages/search/lib/commands/SEARCH_NOCONTENT.ts @@ -17,12 +17,12 @@ export function transformArguments( ); } -export interface SearchNonContentReply { +export interface SearchNoContentReply { total: number; documents: Array; }; -export function transformReply(reply: SearchRawReply): SearchNonContentReply { +export function transformReply(reply: SearchRawReply): SearchNoContentReply { return { total: reply[0], documents: reply.slice(1) From 78e6c35e67bed7f0046cd76cf690abdf11f921be Mon Sep 17 00:00:00 2001 From: Brett Burch Date: Thu, 14 Sep 2023 15:26:28 -0600 Subject: [PATCH 5/6] Enable test --- packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts b/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts index 205dda97c09..02781f78086 100644 --- a/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts +++ b/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts @@ -22,7 +22,7 @@ describe('SEARCH_NOCONTENT', () => { }); }); - describe.skip('client.ft.searchNoContent', () => { + describe('client.ft.searchNoContent', () => { testUtils.testWithClient('returns total and keys', async client => { await Promise.all([ client.ft.create('index', { From 85c3fb05819f8cf48b89c019b7f2b02fd9cd783b Mon Sep 17 00:00:00 2001 From: Brett Burch Date: Thu, 14 Sep 2023 16:29:43 -0600 Subject: [PATCH 6/6] Update test field type --- packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts b/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts index 02781f78086..da5a6feaba7 100644 --- a/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts +++ b/packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts @@ -26,7 +26,7 @@ describe('SEARCH_NOCONTENT', () => { testUtils.testWithClient('returns total and keys', async client => { await Promise.all([ client.ft.create('index', { - field: SchemaFieldTypes.NUMERIC + field: SchemaFieldTypes.TEXT }), client.hSet('1', 'field', 'field1'), client.hSet('2', 'field', 'field2'),