@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
|
@@ -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;
|
|
@@ -42,6 +42,7 @@ export const memorySearchTheBadWay = () => ({ store }) => {
|
|
|
42
42
|
deleteIndexIfExists: async () => undefined,
|
|
43
43
|
ensureIndexCreated: async () => undefined,
|
|
44
44
|
index: async (_options) => undefined,
|
|
45
|
+
bulkIndex: async (_items) => undefined,
|
|
45
46
|
search: async (options) => {
|
|
46
47
|
const results = (await store.loadAllDocumentsTheBadWay())
|
|
47
48
|
.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;
|
|
@@ -60,6 +60,17 @@ export const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
60
60
|
refresh: true
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
|
+
const bulkIndex = async (items) => {
|
|
64
|
+
const openSearchClient = await client();
|
|
65
|
+
await openSearchClient.bulk({
|
|
66
|
+
index: indexConfig.name,
|
|
67
|
+
body: items.flatMap((item) => [
|
|
68
|
+
{ index: { _id: item.id } },
|
|
69
|
+
item.body
|
|
70
|
+
]),
|
|
71
|
+
refresh: true
|
|
72
|
+
});
|
|
73
|
+
};
|
|
63
74
|
const search = async (options) => {
|
|
64
75
|
const body = {
|
|
65
76
|
query: { bool: {} },
|
|
@@ -109,6 +120,6 @@ export const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
109
120
|
const totalPages = Math.ceil(totalItems / pageSize) || 1;
|
|
110
121
|
return { items, pageSize, currentPage, totalItems, totalPages };
|
|
111
122
|
};
|
|
112
|
-
return { ensureIndexCreated, deleteIndexIfExists, index, search };
|
|
123
|
+
return { ensureIndexCreated, deleteIndexIfExists, index, bulkIndex, search };
|
|
113
124
|
};
|
|
114
125
|
};
|