lucivy-wasm 0.3.1 → 0.4.1
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/README.md +19 -1
- package/js/lucivy-worker.js +3 -3
- package/js/lucivy.d.ts +4 -0
- package/js/lucivy.js +2 -0
- package/package.json +1 -1
- package/pkg/lucivy.wasm +0 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Fast BM25 full-text search for browsers — WASM build of Lucivy with **threading** (emscripten pthreads), OPFS persistence, and LUCE snapshot support. Runs in a Web Worker.
|
|
4
4
|
|
|
5
|
+
> **v0.4.0**: Search results can now include stored field values via `{ fields: true }` option.
|
|
6
|
+
>
|
|
5
7
|
> **v0.3.0 breaking change**: This package now uses the emscripten build with threading support. The API is now worker-based (async). See below for migration.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
@@ -91,8 +93,24 @@ const results2 = await index.search(
|
|
|
91
93
|
{ highlights: true }
|
|
92
94
|
);
|
|
93
95
|
|
|
96
|
+
// contains_split — each word becomes a separate contains query, OR'd together
|
|
97
|
+
const results5 = await index.search(
|
|
98
|
+
{ type: 'contains_split', field: 'body', value: 'rust safety' }
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// contains_split with fuzzy distance — each word gets fuzzy tolerance
|
|
102
|
+
const results6 = await index.search(
|
|
103
|
+
{ type: 'contains_split', field: 'body', value: 'memry safty', distance: 1 }
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Return stored fields with results
|
|
107
|
+
const results3 = await index.search('programming', { fields: true });
|
|
108
|
+
for (const r of results3) {
|
|
109
|
+
console.log(r.fields.title, r.score); // stored field values
|
|
110
|
+
}
|
|
111
|
+
|
|
94
112
|
// Pre-filtered by doc IDs
|
|
95
|
-
const
|
|
113
|
+
const results4 = await index.searchFiltered('programming', [1, 3], { highlights: true, fields: true });
|
|
96
114
|
|
|
97
115
|
// Metadata
|
|
98
116
|
const count = await index.numDocs();
|
package/js/lucivy-worker.js
CHANGED
|
@@ -265,7 +265,7 @@ self.onmessage = async (e) => {
|
|
|
265
265
|
const queryJson = typeof args.query === 'string' && !args.query.startsWith('{')
|
|
266
266
|
? JSON.stringify(args.query)
|
|
267
267
|
: (typeof args.query === 'object' ? JSON.stringify(args.query) : args.query);
|
|
268
|
-
const json = callStr('lucivy_search', ctx, queryJson, args.limit || 10, args.highlights ? 1 : 0);
|
|
268
|
+
const json = callStr('lucivy_search', ctx, queryJson, args.limit || 10, args.highlights ? 1 : 0, args.fields ? 1 : 0);
|
|
269
269
|
result = JSON.parse(json);
|
|
270
270
|
if (result.error) throw new Error(result.error);
|
|
271
271
|
break;
|
|
@@ -282,8 +282,8 @@ self.onmessage = async (e) => {
|
|
|
282
282
|
Module.HEAPU8.set(new Uint8Array(ids.buffer), idsPtr);
|
|
283
283
|
|
|
284
284
|
const resPtr = Module.ccall('lucivy_search_filtered', 'number',
|
|
285
|
-
['number', 'string', 'number', 'number', 'number', 'number'],
|
|
286
|
-
[ctx, queryJson, args.limit || 10, idsPtr, ids.length, args.highlights ? 1 : 0]);
|
|
285
|
+
['number', 'string', 'number', 'number', 'number', 'number', 'number'],
|
|
286
|
+
[ctx, queryJson, args.limit || 10, idsPtr, ids.length, args.highlights ? 1 : 0, args.fields ? 1 : 0]);
|
|
287
287
|
const json = Module.UTF8ToString(resPtr);
|
|
288
288
|
Module._free(idsPtr);
|
|
289
289
|
|
package/js/lucivy.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export type SearchQuery = string | {
|
|
|
18
18
|
export interface SearchOptions {
|
|
19
19
|
limit?: number;
|
|
20
20
|
highlights?: boolean;
|
|
21
|
+
/** Include stored fields in results. */
|
|
22
|
+
fields?: boolean;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/** A single search result. */
|
|
@@ -25,6 +27,8 @@ export interface SearchResult {
|
|
|
25
27
|
docId: number;
|
|
26
28
|
score: number;
|
|
27
29
|
highlights?: Record<string, [number, number][]>;
|
|
30
|
+
/** Stored field values (when `fields: true`). */
|
|
31
|
+
fields?: Record<string, string | number>;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/** Main-thread Promise API for lucivy-emscripten. */
|
package/js/lucivy.js
CHANGED
|
@@ -98,6 +98,7 @@ export class LucivyIndex {
|
|
|
98
98
|
query,
|
|
99
99
|
limit: options.limit,
|
|
100
100
|
highlights: options.highlights,
|
|
101
|
+
fields: options.fields,
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
|
|
@@ -108,6 +109,7 @@ export class LucivyIndex {
|
|
|
108
109
|
allowedIds,
|
|
109
110
|
limit: options.limit,
|
|
110
111
|
highlights: options.highlights,
|
|
112
|
+
fields: options.fields,
|
|
111
113
|
});
|
|
112
114
|
}
|
|
113
115
|
|
package/package.json
CHANGED
package/pkg/lucivy.wasm
CHANGED
|
Binary file
|