Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit dbb0781

Browse files
committed
Config file has shards and replicas
1 parent 8badfd8 commit dbb0781

File tree

8 files changed

+150
-20
lines changed

8 files changed

+150
-20
lines changed

dist/apisearch.js

Lines changed: 38 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Config/Config.d.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import { Synonym } from "./Synonym";
2+
export declare const DEFAULT_SHARDS = 1;
3+
export declare const DEFAULT_REPLICAS = 0;
24
/**
35
* Result class
46
*/
57
export declare class Config {
68
private language;
79
private storeSearchableMetadata;
810
private synonyms;
11+
private shards;
12+
private replicas;
913
/**
1014
* Constructor
1115
*
1216
* @param language
1317
* @param storeSearchableMetadata
18+
* @param shards
19+
* @param replicas
1420
*/
15-
constructor(language?: string, storeSearchableMetadata?: boolean);
21+
constructor(language?: string, storeSearchableMetadata?: boolean, shards?: number, replicas?: number);
1622
/**
1723
* Get language
1824
*
@@ -37,6 +43,18 @@ export declare class Config {
3743
* @return {Synonym[]}
3844
*/
3945
getSynonyms(): Synonym[];
46+
/**
47+
* Get shards
48+
*
49+
* @return {number}
50+
*/
51+
getShards(): number;
52+
/**
53+
* Get replicas
54+
*
55+
* @return {number}
56+
*/
57+
getReplicas(): number;
4058
/**
4159
* to array
4260
*/
@@ -46,6 +64,8 @@ export declare class Config {
4664
synonyms: {
4765
words: string[];
4866
}[];
67+
shards: number;
68+
replicas: number;
4969
};
5070
/**
5171
* Create from array

lib/Config/Config.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"use strict";
22
exports.__esModule = true;
33
var Synonym_1 = require("./Synonym");
4+
exports.DEFAULT_SHARDS = 1;
5+
exports.DEFAULT_REPLICAS = 0;
46
/**
57
* Result class
68
*/
@@ -10,13 +12,19 @@ var Config = /** @class */ (function () {
1012
*
1113
* @param language
1214
* @param storeSearchableMetadata
15+
* @param shards
16+
* @param replicas
1317
*/
14-
function Config(language, storeSearchableMetadata) {
18+
function Config(language, storeSearchableMetadata, shards, replicas) {
1519
if (language === void 0) { language = null; }
1620
if (storeSearchableMetadata === void 0) { storeSearchableMetadata = true; }
21+
if (shards === void 0) { shards = exports.DEFAULT_SHARDS; }
22+
if (replicas === void 0) { replicas = exports.DEFAULT_REPLICAS; }
1723
this.synonyms = [];
1824
this.language = language;
1925
this.storeSearchableMetadata = storeSearchableMetadata;
26+
this.shards = shards;
27+
this.replicas = replicas;
2028
}
2129
/**
2230
* Get language
@@ -50,28 +58,52 @@ var Config = /** @class */ (function () {
5058
Config.prototype.getSynonyms = function () {
5159
return this.synonyms;
5260
};
61+
/**
62+
* Get shards
63+
*
64+
* @return {number}
65+
*/
66+
Config.prototype.getShards = function () {
67+
return this.shards;
68+
};
69+
/**
70+
* Get replicas
71+
*
72+
* @return {number}
73+
*/
74+
Config.prototype.getReplicas = function () {
75+
return this.replicas;
76+
};
5377
/**
5478
* to array
5579
*/
5680
Config.prototype.toArray = function () {
5781
return {
5882
language: this.language,
5983
store_searchable_metadata: this.storeSearchableMetadata,
60-
synonyms: this.synonyms.map(function (synonym) { return synonym.toArray(); })
84+
synonyms: this.synonyms.map(function (synonym) { return synonym.toArray(); }),
85+
shards: this.shards,
86+
replicas: this.replicas
6187
};
6288
};
6389
/**
6490
* Create from array
6591
*/
6692
Config.createFromArray = function (array) {
67-
var immutableConfig = new Config(array.language ? array.language : null, typeof array.store_searchable_metadata == "boolean"
93+
var config = new Config(array.language ? array.language : null, typeof array.store_searchable_metadata == "boolean"
6894
? array.store_searchable_metadata
6995
: true);
7096
if (array.synonyms instanceof Array &&
7197
array.synonyms.length > 0) {
72-
immutableConfig.synonyms = array.synonyms.map(function (synonym) { return Synonym_1.Synonym.createFromArray(synonym); });
98+
config.synonyms = array.synonyms.map(function (synonym) { return Synonym_1.Synonym.createFromArray(synonym); });
7399
}
74-
return immutableConfig;
100+
config.shards = typeof array.shards == "number"
101+
? array.shards
102+
: exports.DEFAULT_SHARDS;
103+
config.replicas = typeof array.replicas == "number"
104+
? array.replicas
105+
: exports.DEFAULT_REPLICAS;
106+
return config;
75107
};
76108
return Config;
77109
}());

src/Config/Config.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import {Synonym} from "./Synonym";
22

3+
export const DEFAULT_SHARDS = 1;
4+
export const DEFAULT_REPLICAS = 0;
5+
36
/**
47
* Result class
58
*/
@@ -8,19 +11,27 @@ export class Config {
811
private language: string;
912
private storeSearchableMetadata: boolean;
1013
private synonyms: Synonym[] = [];
14+
private shards: number;
15+
private replicas: number;
1116

1217
/**
1318
* Constructor
1419
*
1520
* @param language
1621
* @param storeSearchableMetadata
22+
* @param shards
23+
* @param replicas
1724
*/
1825
constructor(
1926
language: string = null,
2027
storeSearchableMetadata: boolean = true,
28+
shards: number = DEFAULT_SHARDS,
29+
replicas: number = DEFAULT_REPLICAS
2130
) {
2231
this.language = language;
2332
this.storeSearchableMetadata = storeSearchableMetadata;
33+
this.shards = shards;
34+
this.replicas = replicas;
2435
}
2536

2637
/**
@@ -59,6 +70,24 @@ export class Config {
5970
return this.synonyms;
6071
}
6172

73+
/**
74+
* Get shards
75+
*
76+
* @return {number}
77+
*/
78+
public getShards(): number {
79+
return this.shards;
80+
}
81+
82+
/**
83+
* Get replicas
84+
*
85+
* @return {number}
86+
*/
87+
public getReplicas(): number {
88+
return this.replicas;
89+
}
90+
6291
/**
6392
* to array
6493
*/
@@ -67,14 +96,16 @@ export class Config {
6796
language: this.language,
6897
store_searchable_metadata: this.storeSearchableMetadata,
6998
synonyms: this.synonyms.map((synonym) => synonym.toArray()),
99+
shards: this.shards,
100+
replicas: this.replicas
70101
};
71102
}
72103

73104
/**
74105
* Create from array
75106
*/
76107
public static createFromArray(array: any): Config {
77-
const immutableConfig = new Config(
108+
const config = new Config(
78109
array.language ? array.language : null,
79110
typeof array.store_searchable_metadata == "boolean"
80111
? array.store_searchable_metadata
@@ -85,9 +116,17 @@ export class Config {
85116
array.synonyms instanceof Array &&
86117
array.synonyms.length > 0
87118
) {
88-
immutableConfig.synonyms = array.synonyms.map((synonym) => Synonym.createFromArray(synonym));
119+
config.synonyms = array.synonyms.map((synonym) => Synonym.createFromArray(synonym));
89120
}
90121

91-
return immutableConfig;
122+
config.shards = typeof array.shards== "number"
123+
? array.shards
124+
: DEFAULT_SHARDS;
125+
126+
config.replicas = typeof array.replicas== "number"
127+
? array.replicas
128+
: DEFAULT_REPLICAS;
129+
130+
return config;
92131
}
93132
}

test/Config/Config.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { expect } from 'chai';
22
import {Synonym} from "../../src/Config/Synonym";
3-
import {Config} from "../../src/Config/Config";
3+
import {
4+
Config, DEFAULT_SHARDS,
5+
DEFAULT_REPLICAS
6+
} from "../../src/Config/Config";
47

58
describe('Config/', () => {
69
describe('Config', () => {
@@ -51,6 +54,8 @@ describe('Config/', () => {
5154
expect(config.getLanguage()).to.be.null;
5255
expect(config.shouldSearchableMetadataBeStored()).to.be.true;
5356
expect(config.getSynonyms()).to.be.deep.equal([]);
57+
expect(config.getShards()).to.be.equal(DEFAULT_SHARDS);
58+
expect(config.getReplicas()).to.be.equal(DEFAULT_REPLICAS);
5459
})
5560
});
5661

@@ -61,7 +66,9 @@ describe('Config/', () => {
6166
'synonyms': [
6267
{'words': ['a', 'b']},
6368
{'words': ['b', 'c']},
64-
]
69+
],
70+
'shards': 5,
71+
'replicas': 8
6572
};
6673

6774
it('should work properly', () => {

0 commit comments

Comments
 (0)