skyeye-svc-common-utils 2.0.0-dev0.18 → 2.0.0-dev0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/azure/cognitiveSearch/QueryType.d.ts +8 -0
- package/dist/lib/azure/cognitiveSearch/QueryType.js +13 -0
- package/dist/lib/azure/cognitiveSearch/QueryType.js.map +1 -0
- package/dist/lib/azure/cognitiveSearch/SearchClient.d.ts +42 -0
- package/dist/lib/azure/cognitiveSearch/SearchClient.js +166 -0
- package/dist/lib/azure/cognitiveSearch/SearchClient.js.map +1 -0
- package/dist/lib/azure/cognitiveSearch/SearchFacets.d.ts +16 -0
- package/dist/lib/azure/cognitiveSearch/SearchFacets.js +3 -0
- package/dist/lib/azure/cognitiveSearch/SearchFacets.js.map +1 -0
- package/dist/lib/azure/cognitiveSearch/SearchFilter.d.ts +68 -0
- package/dist/lib/azure/cognitiveSearch/SearchFilter.js +125 -0
- package/dist/lib/azure/cognitiveSearch/SearchFilter.js.map +1 -0
- package/dist/lib/azure/cognitiveSearch/SearchMode.d.ts +9 -0
- package/dist/lib/azure/cognitiveSearch/SearchMode.js +14 -0
- package/dist/lib/azure/cognitiveSearch/SearchMode.js.map +1 -0
- package/dist/lib/azure/cognitiveSearch/SearchOption.d.ts +88 -0
- package/dist/lib/azure/cognitiveSearch/SearchOption.js +104 -0
- package/dist/lib/azure/cognitiveSearch/SearchOption.js.map +1 -0
- package/dist/lib/azure/cognitiveSearch/SearchOrder.d.ts +9 -0
- package/dist/lib/azure/cognitiveSearch/SearchOrder.js +3 -0
- package/dist/lib/azure/cognitiveSearch/SearchOrder.js.map +1 -0
- package/dist/lib/azure/cognitiveSearch/index.d.ts +7 -0
- package/dist/lib/azure/cognitiveSearch/index.js +24 -0
- package/dist/lib/azure/cognitiveSearch/index.js.map +1 -0
- package/dist/lib/azure/index.d.ts +7 -0
- package/dist/lib/azure/index.js +24 -0
- package/dist/lib/azure/index.js.map +1 -0
- package/dist/lib/fetch/index.d.ts +2 -0
- package/dist/lib/fetch/index.js +19 -0
- package/dist/lib/fetch/index.js.map +1 -0
- package/dist/lib/fetch/sendRequest.d.ts +7 -0
- package/dist/lib/fetch/sendRequest.js +25 -0
- package/dist/lib/fetch/sendRequest.js.map +1 -0
- package/dist/lib/fetch/sendRequest.test.d.ts +1 -0
- package/dist/lib/fetch/sendRequest.test.js +27 -0
- package/dist/lib/fetch/sendRequest.test.js.map +1 -0
- package/dist/lib/fetch/sendRequestWithTimeout.d.ts +9 -0
- package/dist/lib/fetch/sendRequestWithTimeout.js +53 -0
- package/dist/lib/fetch/sendRequestWithTimeout.js.map +1 -0
- package/dist/lib/fetch/sendRequestWithTimeout.test.d.ts +1 -0
- package/dist/lib/fetch/sendRequestWithTimeout.test.js +43 -0
- package/dist/lib/fetch/sendRequestWithTimeout.test.js.map +1 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.js +21 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/logger/index.d.ts +2 -0
- package/dist/lib/logger/index.js +19 -0
- package/dist/lib/logger/index.js.map +1 -0
- package/dist/lib/logger/logger.d.ts +16 -0
- package/dist/lib/logger/logger.js +120 -0
- package/dist/lib/logger/logger.js.map +1 -0
- package/dist/lib/logger/morganLogger.d.ts +4 -0
- package/dist/lib/logger/morganLogger.js +27 -0
- package/dist/lib/logger/morganLogger.js.map +1 -0
- package/dist/lib/teams/LogMessage.d.ts +51 -0
- package/dist/lib/teams/LogMessage.js +33 -0
- package/dist/lib/teams/LogMessage.js.map +1 -0
- package/dist/lib/teams/broadcastLogMessage.d.ts +8 -0
- package/dist/lib/teams/broadcastLogMessage.js +81 -0
- package/dist/lib/teams/broadcastLogMessage.js.map +1 -0
- package/dist/lib/teams/broadcastLogMessage.test.d.ts +1 -0
- package/dist/lib/teams/broadcastLogMessage.test.js +25 -0
- package/dist/lib/teams/broadcastLogMessage.test.js.map +1 -0
- package/dist/lib/teams/index.d.ts +2 -0
- package/dist/lib/teams/index.js +19 -0
- package/dist/lib/teams/index.js.map +1 -0
- package/dist/test/setup-tests.d.ts +0 -0
- package/dist/test/setup-tests.js +3 -0
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/types/ServiceResponse.d.ts +16 -0
- package/dist/types/ServiceResponse.js +3 -0
- package/dist/types/ServiceResponse.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/baseClass/appDataSource.d.ts +7 -0
- package/dist/utils/baseClass/appDataSource.js +31 -0
- package/dist/utils/baseClass/appDataSource.js.map +1 -0
- package/dist/utils/baseClass/baseController.js +8 -8
- package/dist/utils/baseClass/baseController.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/middleware/loadConfig.d.ts +128 -0
- package/dist/utils/middleware/loadConfig.js +143 -0
- package/dist/utils/middleware/loadConfig.js.map +1 -0
- package/dist/utils/middleware/startdbConnection.js +2 -4
- package/dist/utils/middleware/startdbConnection.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -2
- package/src/utils/baseClass/appDataSource.ts +23 -0
- package/src/utils/baseClass/baseController.ts +9 -9
- package/dist/utils/baseClass/dataSourceManager.d.ts +0 -11
- package/dist/utils/baseClass/dataSourceManager.js +0 -59
- package/dist/utils/baseClass/dataSourceManager.js.map +0 -1
- package/src/utils/baseClass/dataSourceManager.ts +0 -49
- package/src/utils/middleware/startdbConnection.ts +0 -20
package/dist/index.d.ts
CHANGED
|
@@ -7,10 +7,9 @@ export * from './utils/logger/morganLogger';
|
|
|
7
7
|
export * from './utils/middleware/handleError';
|
|
8
8
|
export * from './utils/middleware/isPublicUser';
|
|
9
9
|
export * from './utils/middleware/overwriteConst';
|
|
10
|
-
export * from './utils/middleware/startdbConnection';
|
|
11
10
|
export * from './utils/baseClass/baseController';
|
|
12
11
|
export * from './utils/baseClass/baseService';
|
|
13
|
-
export * from './utils/baseClass/
|
|
12
|
+
export * from './utils/baseClass/appDataSource';
|
|
14
13
|
export * from './interfaces/index';
|
|
15
14
|
export * from './lib/azure/azureKeyVault';
|
|
16
15
|
export * from './lib/azure/azureServiceBusClient';
|
package/dist/index.js
CHANGED
|
@@ -23,10 +23,9 @@ __exportStar(require("./utils/logger/morganLogger"), exports);
|
|
|
23
23
|
__exportStar(require("./utils/middleware/handleError"), exports);
|
|
24
24
|
__exportStar(require("./utils/middleware/isPublicUser"), exports);
|
|
25
25
|
__exportStar(require("./utils/middleware/overwriteConst"), exports);
|
|
26
|
-
__exportStar(require("./utils/middleware/startdbConnection"), exports);
|
|
27
26
|
__exportStar(require("./utils/baseClass/baseController"), exports);
|
|
28
27
|
__exportStar(require("./utils/baseClass/baseService"), exports);
|
|
29
|
-
__exportStar(require("./utils/baseClass/
|
|
28
|
+
__exportStar(require("./utils/baseClass/appDataSource"), exports);
|
|
30
29
|
__exportStar(require("./interfaces/index"), exports);
|
|
31
30
|
__exportStar(require("./lib/azure/azureKeyVault"), exports);
|
|
32
31
|
__exportStar(require("./lib/azure/azureServiceBusClient"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,sDAAoC;AACpC,8DAA4C;AAC5C,wDAAsC;AACtC,8DAA4C;AAC5C,iEAA+C;AAC/C,kEAAgD;AAChD,oEAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,sDAAoC;AACpC,8DAA4C;AAC5C,wDAAsC;AACtC,8DAA4C;AAC5C,iEAA+C;AAC/C,kEAAgD;AAChD,oEAAkD;AAClD,mEAAiD;AACjD,gEAA8C;AAC9C,kEAAgD;AAChD,qDAAmC;AACnC,4DAA0C;AAC1C,oEAAkD;AAClD,gEAA8C;AAC9C,mEAAiD;AACjD,gEAA8C;AAC9C,+DAA6C;AAC7C,gEAA8C;AAC9C,mDAAiC;AACjC,yDAAuC;AACvC,mEAAiD;AACjD,2CAAyB;AACzB,oDAAkC;AAClC,uDAAqC;AACrC,mEAAiD;AACjD,+DAA6C;AAC7C,4EAA0D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @description Specifies whether simple or full of query type must be matched
|
|
6
|
+
* @see https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents
|
|
7
|
+
*/
|
|
8
|
+
var QueryType;
|
|
9
|
+
(function (QueryType) {
|
|
10
|
+
QueryType["simple"] = "simple";
|
|
11
|
+
QueryType["full"] = "full";
|
|
12
|
+
})(QueryType = exports.QueryType || (exports.QueryType = {}));
|
|
13
|
+
//# sourceMappingURL=QueryType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryType.js","sourceRoot":"","sources":["../../../../src/lib/azure/cognitiveSearch/QueryType.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,IAAY,SAGX;AAHD,WAAY,SAAS;IACjB,8BAAiB,CAAA;IACjB,0BAAa,CAAA;AACjB,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ServiceResponse } from '../../../interfaces';
|
|
2
|
+
import { AzureSearchIndex } from '../../../utils';
|
|
3
|
+
/**
|
|
4
|
+
* @classdesc SearchClient as an adaptor to bind the third-party library
|
|
5
|
+
* (@azure/search-documents) with the internal application. That is to say, the
|
|
6
|
+
* class is aim to enhance dev's maintenance between lib and the exact usage.
|
|
7
|
+
* @property {SearchClient} instance - Singleton instance
|
|
8
|
+
* @property {string} endpoint - Azure cognitive search's request endpoint
|
|
9
|
+
* @property {string} credential - Azure cognitive search's API key
|
|
10
|
+
* @property {Semaphore} semaphore - to ensure not too many requests are sent to Azure cognitive search
|
|
11
|
+
* @property {Record<AzureSearchIndex, string>} indexMap - to store the index's alias
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const client = await SearchClient.getInstance();
|
|
15
|
+
* const searchOption = new SearchOption( { top: 1 });
|
|
16
|
+
* console.log(JSON.stringify(await client.query(AzureSearchIndex.company, '*', searchOption.value())));
|
|
17
|
+
*/
|
|
18
|
+
export declare class SearchClient {
|
|
19
|
+
private static instance;
|
|
20
|
+
private static endpoint;
|
|
21
|
+
private static credential;
|
|
22
|
+
private static indexMap;
|
|
23
|
+
/**
|
|
24
|
+
* @description To retrieve the instance in the Singleton pattern
|
|
25
|
+
* @returns {SearchClient} the singleton instance of SearchClient
|
|
26
|
+
*/
|
|
27
|
+
static getInstance(): Promise<SearchClient>;
|
|
28
|
+
/**
|
|
29
|
+
* @description To query the Azure cognitive search
|
|
30
|
+
* @param {AzureSearchIndex} index - to retrieve the document
|
|
31
|
+
* @param {string} keyword - as the prop 'search'
|
|
32
|
+
* @param {any} options - additional option for the search
|
|
33
|
+
* @param {number} retryTimes - specify how many times if Azure cognitive search returns a bad request
|
|
34
|
+
* @returns {ServiceResponse} a serviceResponse, noted that data is stated in `data.document`
|
|
35
|
+
*/
|
|
36
|
+
query(index: AzureSearchIndex, keyword?: string, options?: any, retryTimes?: number, tracking?: number): Promise<ServiceResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* @description To postpone for specific millisecond
|
|
39
|
+
* @param {number} ms - millisecond to wait for
|
|
40
|
+
*/
|
|
41
|
+
private sleep;
|
|
42
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.SearchClient = void 0;
|
|
20
|
+
const search_documents_1 = require("@azure/search-documents");
|
|
21
|
+
const logger_1 = require("../../logger");
|
|
22
|
+
const azureKeyVault_1 = require("../../azure/azureKeyVault");
|
|
23
|
+
const utils_1 = require("../../../utils");
|
|
24
|
+
const loadConfig_1 = require("../../../utils/middleware/loadConfig");
|
|
25
|
+
/**
|
|
26
|
+
* @classdesc SearchClient as an adaptor to bind the third-party library
|
|
27
|
+
* (@azure/search-documents) with the internal application. That is to say, the
|
|
28
|
+
* class is aim to enhance dev's maintenance between lib and the exact usage.
|
|
29
|
+
* @property {SearchClient} instance - Singleton instance
|
|
30
|
+
* @property {string} endpoint - Azure cognitive search's request endpoint
|
|
31
|
+
* @property {string} credential - Azure cognitive search's API key
|
|
32
|
+
* @property {Semaphore} semaphore - to ensure not too many requests are sent to Azure cognitive search
|
|
33
|
+
* @property {Record<AzureSearchIndex, string>} indexMap - to store the index's alias
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const client = await SearchClient.getInstance();
|
|
37
|
+
* const searchOption = new SearchOption( { top: 1 });
|
|
38
|
+
* console.log(JSON.stringify(await client.query(AzureSearchIndex.company, '*', searchOption.value())));
|
|
39
|
+
*/
|
|
40
|
+
class SearchClient {
|
|
41
|
+
/**
|
|
42
|
+
* @description To retrieve the instance in the Singleton pattern
|
|
43
|
+
* @returns {SearchClient} the singleton instance of SearchClient
|
|
44
|
+
*/
|
|
45
|
+
static getInstance() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
if (!!SearchClient.instance) {
|
|
48
|
+
return SearchClient.instance;
|
|
49
|
+
}
|
|
50
|
+
SearchClient.instance = new SearchClient();
|
|
51
|
+
/**
|
|
52
|
+
* When the keyVaultName is empty, loadConfig() should be called in order to fetch the value as possible
|
|
53
|
+
* since we are not using lazy-loading here. It would be better to transform into a lazy-loading mechanism.
|
|
54
|
+
*/
|
|
55
|
+
if (loadConfig_1.appConfig === undefined) {
|
|
56
|
+
try {
|
|
57
|
+
yield (0, loadConfig_1.loadConfig)();
|
|
58
|
+
if (loadConfig_1.appConfig.keyVaultName === undefined) {
|
|
59
|
+
throw new Error('SearchClient/getInstance: empty keyVaultName');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const credentialResp = yield (0, azureKeyVault_1.getKeyVault)(loadConfig_1.appConfig.keyVaultName, utils_1.AzureSearchConfig.credentialSecretName);
|
|
67
|
+
if (credentialResp.isSuccess === false) {
|
|
68
|
+
throw new Error('/SearchClient/getInstance(): retrieve search credential failed');
|
|
69
|
+
}
|
|
70
|
+
const secret = credentialResp.data;
|
|
71
|
+
const indexMapResp = yield (0, azureKeyVault_1.getKeyVault)(loadConfig_1.appConfig.keyVaultName, utils_1.AzureSearchConfig.indexSecretName);
|
|
72
|
+
if (indexMapResp.isSuccess === false) {
|
|
73
|
+
throw new Error('/SearchClient/getInstance(): retrieve search indexMap failed');
|
|
74
|
+
}
|
|
75
|
+
SearchClient.indexMap = indexMapResp.data;
|
|
76
|
+
SearchClient.endpoint = secret.endpoint;
|
|
77
|
+
SearchClient.credential = secret.credential;
|
|
78
|
+
return SearchClient.instance;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @description To query the Azure cognitive search
|
|
83
|
+
* @param {AzureSearchIndex} index - to retrieve the document
|
|
84
|
+
* @param {string} keyword - as the prop 'search'
|
|
85
|
+
* @param {any} options - additional option for the search
|
|
86
|
+
* @param {number} retryTimes - specify how many times if Azure cognitive search returns a bad request
|
|
87
|
+
* @returns {ServiceResponse} a serviceResponse, noted that data is stated in `data.document`
|
|
88
|
+
*/
|
|
89
|
+
query(index, keyword = '*', options, retryTimes = utils_1.AzureSearchConfig.queryRetryDefault, tracking = Math.floor(Math.random() * 100000000000)) {
|
|
90
|
+
var _a, e_1, _b, _c;
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
logger_1.logger.verbose(`start SearchClient/query: ${tracking}`);
|
|
93
|
+
let serviceResponse = { isSuccess: false };
|
|
94
|
+
let searchResults;
|
|
95
|
+
let curRetry = 0;
|
|
96
|
+
try {
|
|
97
|
+
const client = new search_documents_1.SearchClient(SearchClient.endpoint, SearchClient.indexMap[index], new search_documents_1.AzureKeyCredential(SearchClient.credential));
|
|
98
|
+
while (curRetry < retryTimes) {
|
|
99
|
+
try {
|
|
100
|
+
logger_1.logger.verbose(`SearchClient/query before sending : ${curRetry}|${tracking}`);
|
|
101
|
+
searchResults = yield client.search(keyword, options);
|
|
102
|
+
logger_1.logger.verbose(`SearchClient/query after sending : ${curRetry}|${tracking}`);
|
|
103
|
+
serviceResponse.data = { document: [] };
|
|
104
|
+
try {
|
|
105
|
+
for (var _d = true, _e = (e_1 = void 0, __asyncValues(searchResults.results)), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
|
|
106
|
+
_c = _f.value;
|
|
107
|
+
_d = false;
|
|
108
|
+
try {
|
|
109
|
+
const result = _c;
|
|
110
|
+
result.document.score = result.score;
|
|
111
|
+
result.document.highlights = result.highlights;
|
|
112
|
+
serviceResponse.data.document.push(result.document);
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
_d = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
120
|
+
finally {
|
|
121
|
+
try {
|
|
122
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
123
|
+
}
|
|
124
|
+
finally { if (e_1) throw e_1.error; }
|
|
125
|
+
}
|
|
126
|
+
logger_1.logger.verbose(`SearchClient/query after processing : ${curRetry}|${tracking}`);
|
|
127
|
+
if (!!searchResults.facets) {
|
|
128
|
+
serviceResponse.data.facets = searchResults.facets;
|
|
129
|
+
}
|
|
130
|
+
if (!!searchResults.count) {
|
|
131
|
+
serviceResponse.data.count = searchResults.count;
|
|
132
|
+
}
|
|
133
|
+
serviceResponse.isSuccess = true;
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
logger_1.logger.error(`SearchClient/query: fail - ${err}`);
|
|
137
|
+
}
|
|
138
|
+
if (!serviceResponse.isSuccess) {
|
|
139
|
+
logger_1.logger.info(`SearchClient/query: retry - ${curRetry}`);
|
|
140
|
+
++curRetry;
|
|
141
|
+
yield this.sleep(utils_1.AzureSearchConfig.retryIntervalSecond * 1000);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
logger_1.logger.error(`SearchClient/query: ${err}`);
|
|
150
|
+
}
|
|
151
|
+
logger_1.logger.verbose(`end SearchClient/query : ${curRetry}|${serviceResponse.data.document.length}|${tracking}`);
|
|
152
|
+
return serviceResponse;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @description To postpone for specific millisecond
|
|
157
|
+
* @param {number} ms - millisecond to wait for
|
|
158
|
+
*/
|
|
159
|
+
sleep(ms) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
yield new Promise(_ => setTimeout(_, ms));
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.SearchClient = SearchClient;
|
|
166
|
+
//# sourceMappingURL=SearchClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchClient.js","sourceRoot":"","sources":["../../../../src/lib/azure/cognitiveSearch/SearchClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,8DAAmG;AACnG,yCAAsC;AACtC,6DAAwD;AAExD,0CAAqE;AACrE,qEAA6E;AAG7E;;;;;;;;;;;;;;GAcG;AACH,MAAa,YAAY;IAMrB;;;OAGG;IACH,MAAM,CAAO,WAAW;;YACpB,IAAI,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE;gBAAE,OAAO,YAAY,CAAC,QAAQ,CAAC;aAAE;YAE9D,YAAY,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;YAE3C;;;eAGG;YACH,IAAI,sBAAS,KAAK,SAAS,EAAE;gBACzB,IAAI;oBACA,MAAM,IAAA,uBAAU,GAAE,CAAC;oBACnB,IAAI,sBAAS,CAAC,YAAY,KAAK,SAAS,EAAE;wBACtC,MAAM,IAAI,KAA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I,CAAC;qBACpC;oBAAC,OAAO,GAAG,EAAE;wBACV,eAAM,CAAC,KAAK,CAAC,8BAA8B,GAAG,EAAE,CAAC,CAAC;qBACrD;oBAED,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE;wBAC5B,eAAM,CAAC,IAAI,CAAC,+BAA+B,QAAQ,EAAE,CAAC,CAAC;wBACvD,EAAE,QAAQ,CAAC;wBACX,MAAM,IAAI,CAAC,KAAK,CAAC,yBAAiB,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;qBAClE;yBAAM;wBACH,MAAM;qBACT;iBACJ;aACJ;YAAC,OAAO,GAAG,EAAE;gBACV,eAAM,CAAC,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;aAC9C;YACD,eAAM,CAAC,OAAO,CAAC,4BAA4B,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC,CAAC;YAC3G,OAAO,eAAe,CAAC;;KAC1B;IAED;;;OAGG;IACW,KAAK,CAAC,EAAU;;YAC1B,MAAM,IAAI,OAAO,CAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC/C,CAAC;KAAA;CACJ;AA7HD,oCA6HC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description SearchFacets as a type is to wrap facets for @azure/search-documents
|
|
3
|
+
* @see https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents
|
|
4
|
+
* @property {string} attr - attribute/prop to reach
|
|
5
|
+
* @property {number} count - volume of the search
|
|
6
|
+
* @property {enum} sort - order
|
|
7
|
+
* @property {enum | number} interval - interval greater than 0 for numbers for date time values
|
|
8
|
+
* @property {string} timeoffset - specifying a dynamic set of facet entry values
|
|
9
|
+
*/
|
|
10
|
+
export type SearchFacets = {
|
|
11
|
+
attr: string;
|
|
12
|
+
count?: number;
|
|
13
|
+
sort?: 'count' | '-count' | 'value' | '-value';
|
|
14
|
+
interval?: number | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
15
|
+
timeoffset?: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchFacets.js","sourceRoot":"","sources":["../../../../src/lib/azure/cognitiveSearch/SearchFacets.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @classdesc SearchFilter is the object to construct the Filter when using Azure cognitive search
|
|
3
|
+
* @property {string} attr - the attribute, so called props, to be filtered by the condition
|
|
4
|
+
* @property {SearchFilterCondition} condition - the condition to filter, see enum @SearchFilter for more information
|
|
5
|
+
* @property {any} value - attr should under the condition with value
|
|
6
|
+
* @property {boolean} isCollection - true if the filed is defined as a collection in Azure Cognitive Search
|
|
7
|
+
* @property {'any' | 'all'} collectionOperation - collection search settings
|
|
8
|
+
* @see https://docs.microsoft.com/en-us/azure/search/search-query-understand-collection-filters
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const primaryFilter = new SearchFilter('isPrimary', EQUAL, true);
|
|
13
|
+
* const mentionedCompanyListFilter = new SearchFilter('companyMentioned', CONTAINS, [...]);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class SearchFilter {
|
|
17
|
+
attr: string;
|
|
18
|
+
condition: SearchFilterCondition;
|
|
19
|
+
value: any;
|
|
20
|
+
isCollection: boolean;
|
|
21
|
+
collectionOperation: 'any' | 'all';
|
|
22
|
+
constructor(attr: string, condition: SearchFilterCondition, value: any, isCollection?: boolean, collectionOperation?: 'any' | 'all');
|
|
23
|
+
/**
|
|
24
|
+
* @description flatten is to compose the instance into a string when using Search
|
|
25
|
+
* @returns {string} the composite of the instance
|
|
26
|
+
*/
|
|
27
|
+
flatten(): string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @description The condition when filtering an params.
|
|
31
|
+
*/
|
|
32
|
+
export declare enum SearchFilterCondition {
|
|
33
|
+
contains = "",
|
|
34
|
+
exclude = "not",
|
|
35
|
+
equal = "eq",
|
|
36
|
+
notEqual = "ne",
|
|
37
|
+
lessThanOrEqual = "le",
|
|
38
|
+
greaterThanOrEqual = "ge"
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @description The following const params is a easy-to-use type when implementing a SearchFilter,
|
|
42
|
+
* so that the developers no longer need to call the enum with the class reference
|
|
43
|
+
*/
|
|
44
|
+
export declare const CONTAINS = SearchFilterCondition.contains;
|
|
45
|
+
export declare const EXCLUDE = SearchFilterCondition.exclude;
|
|
46
|
+
export declare const EQUAL = SearchFilterCondition.equal;
|
|
47
|
+
export declare const NOT_EQUAL = SearchFilterCondition.notEqual;
|
|
48
|
+
export declare const LESS_THAN_OR_EQUAL = SearchFilterCondition.lessThanOrEqual;
|
|
49
|
+
export declare const GREATER_THAN_OR_EQUAL = SearchFilterCondition.greaterThanOrEqual;
|
|
50
|
+
/**
|
|
51
|
+
* @description describe types of combination
|
|
52
|
+
*/
|
|
53
|
+
export declare const enum CombinationType {
|
|
54
|
+
and = "and",
|
|
55
|
+
or = "or"
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @description AND helps developers to compose a nested filter for condition AND.
|
|
59
|
+
* @param {Array<Array<string | SearchFilter>>} args - the arguments which need to be construct into string
|
|
60
|
+
* @returns {string} aggregation of the given args
|
|
61
|
+
*/
|
|
62
|
+
export declare const AND: (...args: Array<string | SearchFilter>) => string;
|
|
63
|
+
/**
|
|
64
|
+
* @description OR helps developers to compose a nested filter for condition OR.
|
|
65
|
+
* @param {Array<Array<string | SearchFilter>>} args - the arguments which need to be construct into string
|
|
66
|
+
* @returns {string} aggregation of the given args
|
|
67
|
+
*/
|
|
68
|
+
export declare const OR: (...args: Array<string | SearchFilter>) => string;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OR = exports.AND = exports.GREATER_THAN_OR_EQUAL = exports.LESS_THAN_OR_EQUAL = exports.NOT_EQUAL = exports.EQUAL = exports.EXCLUDE = exports.CONTAINS = exports.SearchFilterCondition = exports.SearchFilter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @classdesc SearchFilter is the object to construct the Filter when using Azure cognitive search
|
|
6
|
+
* @property {string} attr - the attribute, so called props, to be filtered by the condition
|
|
7
|
+
* @property {SearchFilterCondition} condition - the condition to filter, see enum @SearchFilter for more information
|
|
8
|
+
* @property {any} value - attr should under the condition with value
|
|
9
|
+
* @property {boolean} isCollection - true if the filed is defined as a collection in Azure Cognitive Search
|
|
10
|
+
* @property {'any' | 'all'} collectionOperation - collection search settings
|
|
11
|
+
* @see https://docs.microsoft.com/en-us/azure/search/search-query-understand-collection-filters
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const primaryFilter = new SearchFilter('isPrimary', EQUAL, true);
|
|
16
|
+
* const mentionedCompanyListFilter = new SearchFilter('companyMentioned', CONTAINS, [...]);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
class SearchFilter {
|
|
20
|
+
constructor(attr, condition, value, isCollection = false, collectionOperation = 'any') {
|
|
21
|
+
this.isCollection = false;
|
|
22
|
+
this.collectionOperation = 'any';
|
|
23
|
+
this.attr = attr;
|
|
24
|
+
this.condition = condition;
|
|
25
|
+
this.value = value;
|
|
26
|
+
this.isCollection = isCollection;
|
|
27
|
+
this.collectionOperation = collectionOperation;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @description flatten is to compose the instance into a string when using Search
|
|
31
|
+
* @returns {string} the composite of the instance
|
|
32
|
+
*/
|
|
33
|
+
flatten() {
|
|
34
|
+
if (this.isCollection) {
|
|
35
|
+
switch (this.condition) {
|
|
36
|
+
case exports.CONTAINS:
|
|
37
|
+
return `${this.attr}/${this.collectionOperation}(i: search.in(i,'${this.value.toString()}', ','))`;
|
|
38
|
+
case exports.EXCLUDE:
|
|
39
|
+
return `${this.attr}/${this.collectionOperation}(i: not search.in(i,'${this.value.toString()}', ','))`;
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`SearchFilter/flatten: Unknown condition for collection`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
switch (this.condition) {
|
|
46
|
+
case exports.EQUAL:
|
|
47
|
+
case exports.NOT_EQUAL:
|
|
48
|
+
case exports.LESS_THAN_OR_EQUAL:
|
|
49
|
+
case exports.GREATER_THAN_OR_EQUAL:
|
|
50
|
+
return `${this.attr} ${this.condition} ${typeof (this.value) === 'string' ? `'${this.value}'` : this.value}`;
|
|
51
|
+
case exports.CONTAINS:
|
|
52
|
+
return `search.in(${this.attr}, '${this.value.toString()}', ',')`;
|
|
53
|
+
case exports.EXCLUDE:
|
|
54
|
+
return `${this.condition} search.in(${this.attr}, '${this.value.toString()}', ',')`;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`SearchFilter/flatten: Unknown condition`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.SearchFilter = SearchFilter;
|
|
62
|
+
/**
|
|
63
|
+
* @description The condition when filtering an params.
|
|
64
|
+
*/
|
|
65
|
+
var SearchFilterCondition;
|
|
66
|
+
(function (SearchFilterCondition) {
|
|
67
|
+
SearchFilterCondition["contains"] = "";
|
|
68
|
+
SearchFilterCondition["exclude"] = "not";
|
|
69
|
+
SearchFilterCondition["equal"] = "eq";
|
|
70
|
+
SearchFilterCondition["notEqual"] = "ne";
|
|
71
|
+
SearchFilterCondition["lessThanOrEqual"] = "le";
|
|
72
|
+
SearchFilterCondition["greaterThanOrEqual"] = "ge";
|
|
73
|
+
})(SearchFilterCondition = exports.SearchFilterCondition || (exports.SearchFilterCondition = {}));
|
|
74
|
+
/**
|
|
75
|
+
* @description The following const params is a easy-to-use type when implementing a SearchFilter,
|
|
76
|
+
* so that the developers no longer need to call the enum with the class reference
|
|
77
|
+
*/
|
|
78
|
+
exports.CONTAINS = SearchFilterCondition.contains;
|
|
79
|
+
exports.EXCLUDE = SearchFilterCondition.exclude;
|
|
80
|
+
exports.EQUAL = SearchFilterCondition.equal;
|
|
81
|
+
exports.NOT_EQUAL = SearchFilterCondition.notEqual;
|
|
82
|
+
exports.LESS_THAN_OR_EQUAL = SearchFilterCondition.lessThanOrEqual;
|
|
83
|
+
exports.GREATER_THAN_OR_EQUAL = SearchFilterCondition.greaterThanOrEqual;
|
|
84
|
+
;
|
|
85
|
+
/**
|
|
86
|
+
* combination is a function ONLY be used for constructing two function: AND and OR,
|
|
87
|
+
* then it would be express into a string.
|
|
88
|
+
* @param {CombinationType} type - to indicate the combination type
|
|
89
|
+
* @param {Array<Array<string | SearchFilter>>} args - the arguments which need to be construct into string
|
|
90
|
+
* @returns {string} aggregation of the given args
|
|
91
|
+
*/
|
|
92
|
+
const combination = (type, ...args) => {
|
|
93
|
+
if (args.length === 0) {
|
|
94
|
+
return '';
|
|
95
|
+
}
|
|
96
|
+
function flatten(obj) {
|
|
97
|
+
return typeof (obj) === 'string' ? obj : obj.flatten();
|
|
98
|
+
}
|
|
99
|
+
let res = !!args[0] ? flatten(args[0]) : '';
|
|
100
|
+
for (let i = 1; i < args.length; ++i) {
|
|
101
|
+
if (!!args) {
|
|
102
|
+
res += ` ${type} ${flatten(args[i])}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return `(${res})`;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* @description AND helps developers to compose a nested filter for condition AND.
|
|
109
|
+
* @param {Array<Array<string | SearchFilter>>} args - the arguments which need to be construct into string
|
|
110
|
+
* @returns {string} aggregation of the given args
|
|
111
|
+
*/
|
|
112
|
+
const AND = (...args) => {
|
|
113
|
+
return combination("and" /* CombinationType.and */, ...args);
|
|
114
|
+
};
|
|
115
|
+
exports.AND = AND;
|
|
116
|
+
/**
|
|
117
|
+
* @description OR helps developers to compose a nested filter for condition OR.
|
|
118
|
+
* @param {Array<Array<string | SearchFilter>>} args - the arguments which need to be construct into string
|
|
119
|
+
* @returns {string} aggregation of the given args
|
|
120
|
+
*/
|
|
121
|
+
const OR = (...args) => {
|
|
122
|
+
return combination("or" /* CombinationType.or */, ...args);
|
|
123
|
+
};
|
|
124
|
+
exports.OR = OR;
|
|
125
|
+
//# sourceMappingURL=SearchFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchFilter.js","sourceRoot":"","sources":["../../../../src/lib/azure/cognitiveSearch/SearchFilter.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACF,MAAa,YAAY;IAOtB,YACI,IAAY,EACZ,SAAgC,EAChC,KAAU,EACV,eAAwB,KAAK,EAC7B,sBAAqC,KAAK;QAR9C,iBAAY,GAAY,KAAK,CAAC;QAC9B,wBAAmB,GAAkB,KAAK,CAAC;QAQvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,OAAO;QACH,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,QAAQ,IAAI,CAAC,SAAS,EAAE;gBACpB,KAAK,gBAAQ;oBACT,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,mBAAmB,oBAAoB,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC;gBACvG,KAAK,eAAO;oBACR,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,mBAAmB,wBAAwB,IAAI,CAAC,KAAK,CAAC,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
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Specifies whether any or all of the search terms must be matched
|
|
3
|
+
* in order to count the document as a match.
|
|
4
|
+
* @see https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents
|
|
5
|
+
*/
|
|
6
|
+
export declare enum SearchMode {
|
|
7
|
+
all = "all",
|
|
8
|
+
any = "any"
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SearchMode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @description Specifies whether any or all of the search terms must be matched
|
|
6
|
+
* in order to count the document as a match.
|
|
7
|
+
* @see https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents
|
|
8
|
+
*/
|
|
9
|
+
var SearchMode;
|
|
10
|
+
(function (SearchMode) {
|
|
11
|
+
SearchMode["all"] = "all";
|
|
12
|
+
SearchMode["any"] = "any";
|
|
13
|
+
})(SearchMode = exports.SearchMode || (exports.SearchMode = {}));
|
|
14
|
+
//# sourceMappingURL=SearchMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchMode.js","sourceRoot":"","sources":["../../../../src/lib/azure/cognitiveSearch/SearchMode.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,IAAY,UAGX;AAHD,WAAY,UAAU;IAClB,yBAAW,CAAA;IACX,yBAAW,CAAA;AACf,CAAC,EAHW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAGrB"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { CombinationType, SearchFilter } from './SearchFilter';
|
|
2
|
+
import { SearchFacets } from './SearchFacets';
|
|
3
|
+
import { SearchOrder } from './SearchOrder';
|
|
4
|
+
import { SearchMode } from './SearchMode';
|
|
5
|
+
import { QueryType } from './QueryType';
|
|
6
|
+
/**
|
|
7
|
+
* @description SearchOptionType is the interface to connect with the library
|
|
8
|
+
* @azure/search-documents, it would only be initiated when creating an instance
|
|
9
|
+
* of class @SearchOption, none of the other functions should access this type declaration.
|
|
10
|
+
* @property {Array<string>} select - optional, to indicate the select attributes/props.
|
|
11
|
+
* @property {string | Array<string | SearchFilter>} filter - optional, search with the filter
|
|
12
|
+
* @property {CombinationType} filterCombinationType - optional, combination type of the filters
|
|
13
|
+
* @property {Array<SearchOrder>} orderBy - optional, return order
|
|
14
|
+
* @property {boolean} count - optional, if true, return with the count of the documents.
|
|
15
|
+
* @property {number} top - optional, total volume when retrieving the data
|
|
16
|
+
* @property {number} skip - optional, skip how many document
|
|
17
|
+
* @property {Array<SearchFacets>} facets - optional, retrieve data's facets
|
|
18
|
+
* @property {SearchMode} searchMode - required, different mode for search
|
|
19
|
+
*/
|
|
20
|
+
type SearchOptionType = {
|
|
21
|
+
select?: string[];
|
|
22
|
+
filter?: string | Array<string | SearchFilter>;
|
|
23
|
+
filterCombinationType?: CombinationType;
|
|
24
|
+
orderBy?: SearchOrder[];
|
|
25
|
+
count?: boolean;
|
|
26
|
+
top?: number;
|
|
27
|
+
skip?: number;
|
|
28
|
+
facets?: SearchFacets[];
|
|
29
|
+
searchMode?: SearchMode;
|
|
30
|
+
searchFields?: string[];
|
|
31
|
+
scoringProfile?: string;
|
|
32
|
+
highlightFields?: string;
|
|
33
|
+
highlightPreTag?: string;
|
|
34
|
+
highlightPostTag?: string;
|
|
35
|
+
queryType?: QueryType;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* @classdesc the class is to wrap an option when retrieving the data from
|
|
39
|
+
* @azure/search-documents/query
|
|
40
|
+
* @property searchOptionType - to store the interface of the option, noted that
|
|
41
|
+
* when calling the query, you should use SearchOption.value() instead of using
|
|
42
|
+
* this attribute.
|
|
43
|
+
*/
|
|
44
|
+
export declare class SearchOption {
|
|
45
|
+
searchOptionType?: SearchOptionType;
|
|
46
|
+
/**
|
|
47
|
+
* @description when initializing a SearchOption, the defaultSearchOption
|
|
48
|
+
* will override the undefined props
|
|
49
|
+
*/
|
|
50
|
+
static defaultSearchOption: SearchOptionType;
|
|
51
|
+
constructor(searchOptionType?: SearchOptionType);
|
|
52
|
+
/**
|
|
53
|
+
* @description to compose flatten-filter string for @azure/search-documents
|
|
54
|
+
* @returns {string} flatten-filter string
|
|
55
|
+
*/
|
|
56
|
+
private composeFilter;
|
|
57
|
+
/**
|
|
58
|
+
* @description to compose flatten-order string for @azure/search-documents
|
|
59
|
+
* @returns {Array<string>} flatten-order string
|
|
60
|
+
*/
|
|
61
|
+
private composeOrder;
|
|
62
|
+
/**
|
|
63
|
+
* @description to compose flatten-facets string for @azure/search-documents
|
|
64
|
+
* @returns {Array<string>} flatten-facets string
|
|
65
|
+
*/
|
|
66
|
+
private composeFacets;
|
|
67
|
+
/**
|
|
68
|
+
* @description as an adaptor to transform the type for @azure/search-documents
|
|
69
|
+
* @returns {Object} object which can be accepted by @azure/search-documents
|
|
70
|
+
*/
|
|
71
|
+
value: () => {
|
|
72
|
+
select?: string[];
|
|
73
|
+
filter?: string;
|
|
74
|
+
orderBy?: string[];
|
|
75
|
+
includeTotalCount?: boolean;
|
|
76
|
+
top?: number;
|
|
77
|
+
skip?: number;
|
|
78
|
+
facets?: string[];
|
|
79
|
+
searchMode?: string;
|
|
80
|
+
searchFields?: string[];
|
|
81
|
+
scoringProfile?: string;
|
|
82
|
+
highlightFields?: string;
|
|
83
|
+
highlightPreTag?: string;
|
|
84
|
+
highlightPostTag?: string;
|
|
85
|
+
queryType?: string;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export {};
|