Skip to content

Add support for FT.SEARCH NOCONTENT #2610

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

Merged
merged 7 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/search/lib/commands/SEARCH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;

export interface SearchOptions {
// NOCONTENT?: true; TODO
VERBATIM?: true;
NOSTOPWORDS?: true;
// WITHSCORES?: true;
Expand Down
45 changes: 45 additions & 0 deletions packages/search/lib/commands/SEARCH_NOCONTENT.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { strict as assert } from 'assert';
import { SchemaFieldTypes } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments, transformReply } from './SEARCH_NOCONTENT';

describe('SEARCH_NOCONTENT', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
transformArguments('index', 'query'),
['FT.SEARCH', 'index', 'query', 'NOCONTENT']
);
});
});

describe('transformReply', () => {
it('returns total and keys', () => {
assert.deepEqual(transformReply([3, '1', '2', '3']), {
total: 3,
documents: ['1', '2', '3']
})
});
});

describe('client.ft.searchNoContent', () => {
testUtils.testWithClient('returns total and keys', async client => {
await Promise.all([
client.ft.create('index', {
field: SchemaFieldTypes.TEXT
}),
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);
});
});
30 changes: 30 additions & 0 deletions packages/search/lib/commands/SEARCH_NOCONTENT.ts
Original file line number Diff line number Diff line change
@@ -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 SearchNoContentReply {
total: number;
documents: Array<string>;
};

export function transformReply(reply: SearchRawReply): SearchNoContentReply {
return {
total: reply[0],
documents: reply.slice(1)
};
}
3 changes: 3 additions & 0 deletions packages/search/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -80,6 +81,8 @@ export default {
profileAggregate: PROFILEAGGREGATE,
SEARCH,
search: SEARCH,
SEARCH_NOCONTENT,
searchNoContent: SEARCH_NOCONTENT,
SPELLCHECK,
spellCheck: SPELLCHECK,
SUGADD,
Expand Down