-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move support for NOCONTENT search option from client.search to client…
….searchNoContent
- Loading branch information
1 parent
e9ee84c
commit 08cb648
Showing
5 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 SearchNonContentReply { | ||
total: number; | ||
documents: Array<string>; | ||
}; | ||
|
||
export function transformReply(reply: SearchRawReply): SearchNonContentReply { | ||
return { | ||
total: reply[0], | ||
documents: reply.slice(1) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters