@openstax/ts-utils 1.26.1 → 1.26.2
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/cjs/coolFile.d.ts +1 -0
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.d.ts +1 -0
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.js +1 -0
- package/dist/cjs/services/searchProvider/openSearch.d.ts +1 -0
- package/dist/cjs/services/searchProvider/openSearch.js +12 -1
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.d.ts +1 -0
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.js +1 -0
- package/dist/esm/services/searchProvider/openSearch.d.ts +1 -0
- package/dist/esm/services/searchProvider/openSearch.js +12 -1
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
content
|
|
@@ -7,6 +7,7 @@ export declare const memorySearchTheBadWay: () => <T>({ store }: {
|
|
|
7
7
|
deleteIndexIfExists: () => Promise<undefined>;
|
|
8
8
|
ensureIndexCreated: () => Promise<undefined>;
|
|
9
9
|
index: (_options: IndexOptions<T>) => Promise<undefined>;
|
|
10
|
+
bulkIndex: (_items: IndexOptions<T>[]) => Promise<undefined>;
|
|
10
11
|
search: (options: SearchOptions) => Promise<{
|
|
11
12
|
items: T[];
|
|
12
13
|
pageSize: number;
|
|
@@ -45,6 +45,7 @@ const memorySearchTheBadWay = () => ({ store }) => {
|
|
|
45
45
|
deleteIndexIfExists: async () => undefined,
|
|
46
46
|
ensureIndexCreated: async () => undefined,
|
|
47
47
|
index: async (_options) => undefined,
|
|
48
|
+
bulkIndex: async (_items) => undefined,
|
|
48
49
|
search: async (options) => {
|
|
49
50
|
const results = (await store.loadAllDocumentsTheBadWay())
|
|
50
51
|
.map(document => {
|
|
@@ -19,6 +19,7 @@ export declare const openSearchService: <C extends string = "deployed">(initiali
|
|
|
19
19
|
ensureIndexCreated: () => Promise<void>;
|
|
20
20
|
deleteIndexIfExists: () => Promise<void>;
|
|
21
21
|
index: (params: IndexOptions<T>) => Promise<void>;
|
|
22
|
+
bulkIndex: (items: IndexOptions<T>[]) => Promise<void>;
|
|
22
23
|
search: (options: SearchOptions) => Promise<{
|
|
23
24
|
items: Exclude<T, undefined>[];
|
|
24
25
|
pageSize: number;
|
|
@@ -63,6 +63,17 @@ const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
63
63
|
refresh: true
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
|
+
const bulkIndex = async (items) => {
|
|
67
|
+
const openSearchClient = await client();
|
|
68
|
+
await openSearchClient.bulk({
|
|
69
|
+
index: indexConfig.name,
|
|
70
|
+
body: items.flatMap((item) => [
|
|
71
|
+
{ index: { _id: item.id } },
|
|
72
|
+
item.body
|
|
73
|
+
]),
|
|
74
|
+
refresh: true
|
|
75
|
+
});
|
|
76
|
+
};
|
|
66
77
|
const search = async (options) => {
|
|
67
78
|
const body = {
|
|
68
79
|
query: { bool: {} },
|
|
@@ -112,7 +123,7 @@ const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
112
123
|
const totalPages = Math.ceil(totalItems / pageSize) || 1;
|
|
113
124
|
return { items, pageSize, currentPage, totalItems, totalPages };
|
|
114
125
|
};
|
|
115
|
-
return { ensureIndexCreated, deleteIndexIfExists, index, search };
|
|
126
|
+
return { ensureIndexCreated, deleteIndexIfExists, index, bulkIndex, search };
|
|
116
127
|
};
|
|
117
128
|
};
|
|
118
129
|
exports.openSearchService = openSearchService;
|