Skip to content

Commit 8cc710f

Browse files
committed
Move support for NOCONTENT search option from client.search to client.searchNoContent
1 parent e9ee84c commit 8cc710f

File tree

5 files changed

+69
-12
lines changed

5 files changed

+69
-12
lines changed

packages/search/lib/commands/SEARCH.spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ describe('SEARCH', () => {
1212
);
1313
});
1414

15-
it('with NOCONTENT', () => {
16-
assert.deepEqual(
17-
transformArguments('index', 'query', { NOCONTENT: true }),
18-
['FT.SEARCH', 'index', 'query', 'NOCONTENT']
19-
);
20-
});
21-
2215
it('with VERBATIM', () => {
2316
assert.deepEqual(
2417
transformArguments('index', 'query', { VERBATIM: true }),

packages/search/lib/commands/SEARCH.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export const FIRST_KEY_INDEX = 1;
66
export const IS_READ_ONLY = true;
77

88
export interface SearchOptions {
9-
NOCONTENT?: true;
109
VERBATIM?: true;
1110
NOSTOPWORDS?: true;
1211
// WITHSCORES?: true;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { strict as assert } from 'assert';
2+
import { SchemaFieldTypes } from '.';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { transformArguments } from './SEARCH_NOCONTENT';
5+
6+
describe('SEARCH_NOCONTENT', () => {
7+
describe('transformArguments', () => {
8+
it('without options', () => {
9+
assert.deepEqual(
10+
transformArguments('index', 'query'),
11+
['FT.SEARCH', 'index', 'query', 'NOCONTENT']
12+
);
13+
});
14+
});
15+
16+
describe('client.ft.searchNoContent', () => {
17+
testUtils.testWithClient('returns total and keys', async client => {
18+
await Promise.all([
19+
client.ft.create('index', {
20+
field: SchemaFieldTypes.NUMERIC
21+
}),
22+
client.hSet('1', 'field', 'field1'),
23+
client.hSet('2', 'field', 'field2'),
24+
client.hSet('3', 'field', 'field3')
25+
]);
26+
27+
assert.deepEqual(
28+
await client.ft.searchNoContent('index', '*'),
29+
{
30+
total: 3,
31+
documents: ['1','2','3']
32+
}
33+
);
34+
}, GLOBAL.SERVERS.OPEN);
35+
});
36+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { RedisCommandArguments } from "@redis/client/dist/lib/commands";
2+
import { pushSearchOptions } from ".";
3+
import { SearchOptions, SearchRawReply } from "./SEARCH";
4+
5+
export const FIRST_KEY_INDEX = 1;
6+
7+
export const IS_READ_ONLY = true;
8+
9+
export function transformArguments(
10+
index: string,
11+
query: string,
12+
options?: SearchOptions
13+
): RedisCommandArguments {
14+
return pushSearchOptions(
15+
['FT.SEARCH', index, query, 'NOCONTENT'],
16+
options
17+
);
18+
}
19+
20+
export interface SearchNonContentReply {
21+
total: number;
22+
documents: Array<string>;
23+
};
24+
25+
export function transformReply(reply: SearchRawReply): SearchNonContentReply {
26+
return {
27+
total: reply[0],
28+
documents: reply.splice(0)
29+
};
30+
}

packages/search/lib/commands/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as INFO from './INFO';
2020
import * as PROFILESEARCH from './PROFILE_SEARCH';
2121
import * as PROFILEAGGREGATE from './PROFILE_AGGREGATE';
2222
import * as SEARCH from './SEARCH';
23+
import * as SEARCH_NOCONTENT from './SEARCH_NOCONTENT';
2324
import * as SPELLCHECK from './SPELLCHECK';
2425
import * as SUGADD from './SUGADD';
2526
import * as SUGDEL from './SUGDEL';
@@ -80,6 +81,8 @@ export default {
8081
profileAggregate: PROFILEAGGREGATE,
8182
SEARCH,
8283
search: SEARCH,
84+
SEARCH_NOCONTENT,
85+
searchNoContent: SEARCH_NOCONTENT,
8386
SPELLCHECK,
8487
spellCheck: SPELLCHECK,
8588
SUGADD,
@@ -395,10 +398,6 @@ export function pushSearchOptions(
395398
args: RedisCommandArguments,
396399
options?: SearchOptions
397400
): RedisCommandArguments {
398-
if (options?.NOCONTENT) {
399-
args.push('NOCONTENT');
400-
}
401-
402401
if (options?.VERBATIM) {
403402
args.push('VERBATIM');
404403
}

0 commit comments

Comments
 (0)