Skip to content

Commit e3b26ab

Browse files
committed
fix(doctests): update imports and replace deprecated methods in remaining files
- Update imports to use SCHEMA_FIELD_TYPE and SCHEMA_VECTOR_FIELD_ALGORITHM constants - Replace deprecated disconnect() and quit() methods with close() - Fix assertion in search-quickstart.js to use correct bicycle ID
1 parent da0e77c commit e3b26ab

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

doctests/query-range.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// HIDE_START
33
import assert from 'node:assert';
44
import fs from 'node:fs';
5-
import { createClient, SchemaFieldTypes, AggregateGroupByReducers, AggregateSteps} from 'redis';
5+
import { createClient, SCHEMA_FIELD_TYPE,} from 'redis';
66

77
const client = createClient();
88

@@ -11,15 +11,15 @@ await client.connect().catch(console.error);
1111
// create index
1212
await client.ft.create('idx:bicycle', {
1313
'$.description': {
14-
type: SchemaFieldTypes.TEXT,
14+
type: SCHEMA_FIELD_TYPE.TEXT,
1515
AS: 'description'
1616
},
1717
'$.price': {
18-
type: SchemaFieldTypes.NUMERIC,
18+
type: SCHEMA_FIELD_TYPE.NUMERIC,
1919
AS: 'price'
2020
},
2121
'$.condition': {
22-
type: SchemaFieldTypes.TAG,
22+
type: SCHEMA_FIELD_TYPE.TAG,
2323
AS: 'condition'
2424
}
2525
}, {
@@ -94,5 +94,5 @@ assert.strictEqual(res4.total, 7);
9494
// REMOVE_START
9595
// destroy index and data
9696
await client.ft.dropIndex('idx:bicycle', { DD: true });
97-
await client.disconnect();
97+
await client.close();
9898
// REMOVE_END

doctests/query-vector.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import assert from 'node:assert';
44
import fs from 'node:fs';
55
import { createClient } from 'redis';
6-
import { SchemaFieldTypes, VectorAlgorithms } from '@redis/search';
6+
import { SCHEMA_FIELD_TYPE, SCHEMA_VECTOR_FIELD_ALGORITHM } from '@redis/search';
77
import { pipeline } from '@xenova/transformers';
88

99
function float32Buffer(arr) {
@@ -26,22 +26,21 @@ async function embedText(sentence) {
2626
return embedding;
2727
}
2828

29-
let query = 'Bike for small kids';
30-
let vector_query = float32Buffer(await embedText('That is a very happy person'));
29+
const vector_query = float32Buffer(await embedText('That is a very happy person'));
3130

3231
const client = createClient();
3332
await client.connect().catch(console.error);
3433

3534
// create index
3635
await client.ft.create('idx:bicycle', {
3736
'$.description': {
38-
type: SchemaFieldTypes.TEXT,
37+
type: SCHEMA_FIELD_TYPE.TEXT,
3938
AS: 'description'
4039
},
4140
'$.description_embeddings': {
42-
type: SchemaFieldTypes.VECTOR,
41+
type: SCHEMA_FIELD_TYPE.VECTOR,
4342
TYPE: 'FLOAT32',
44-
ALGORITHM: VectorAlgorithms.FLAT,
43+
ALGORITHM: SCHEMA_VECTOR_FIELD_ALGORITHM.FLAT,
4544
DIM: 384,
4645
DISTANCE_METRIC: 'COSINE',
4746
AS: 'vector'
@@ -107,5 +106,5 @@ assert.strictEqual(res2.total, 1);
107106
// REMOVE_START
108107
// destroy index and data
109108
await client.ft.dropIndex('idx:bicycle', { DD: true });
110-
await client.disconnect();
109+
await client.close();
111110
// REMOVE_END

doctests/search-quickstart.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import assert from 'assert';
44
// REMOVE_END
55
// HIDE_START
6-
import { AggregateGroupByReducers, AggregateSteps, createClient, SchemaFieldTypes } from 'redis';
6+
import { createClient, SCHEMA_FIELD_TYPE } from 'redis';
77
// HIDE_END
88
// STEP_START connect
99
const client = createClient();
@@ -95,24 +95,24 @@ const bicycles = [
9595
// STEP_START create_index
9696
const schema = {
9797
'$.brand': {
98-
type: SchemaFieldTypes.TEXT,
98+
type: SCHEMA_FIELD_TYPE.TEXT,
9999
SORTABLE: true,
100100
AS: 'brand'
101101
},
102102
'$.model': {
103-
type: SchemaFieldTypes.TEXT,
103+
type: SCHEMA_FIELD_TYPE.TEXT,
104104
AS: 'model'
105105
},
106106
'$.description': {
107-
type: SchemaFieldTypes.TEXT,
107+
type: SCHEMA_FIELD_TYPE.TEXT,
108108
AS: 'description'
109109
},
110110
'$.price': {
111-
type: SchemaFieldTypes.NUMERIC,
111+
type: SCHEMA_FIELD_TYPE.NUMERIC,
112112
AS: 'price'
113113
},
114114
'$.condition': {
115-
type: SchemaFieldTypes.TAG,
115+
type: SCHEMA_FIELD_TYPE.TAG,
116116
AS: 'condition'
117117
}
118118
};
@@ -158,7 +158,7 @@ console.log(JSON.stringify(result, null, 2));
158158
// STEP_END
159159

160160
// REMOVE_START
161-
assert.equal(result.documents[0].id, 'bicycle:1');
161+
assert.equal(result.documents[0].id, 'bicycle:0');
162162
// REMOVE_END
163163

164164
// STEP_START query_single_term
@@ -228,4 +228,4 @@ console.log(JSON.stringify(result, null, 2));
228228
assert.equal(result.documents[0].id, 'bicycle:4');
229229
// REMOVE END
230230

231-
await client.quit();
231+
await client.close();

doctests/string-set-get-example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ await client.del('bike:1');
2323
//REMOVE_END
2424

2525
// HIDE_START
26-
await client.quit();
26+
await client.close();
2727
// HIDE_END

0 commit comments

Comments
 (0)