lucivy-wasm 0.3.0 → 0.4.0

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 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,14 @@ const results2 = await index.search(
91
93
  { highlights: true }
92
94
  );
93
95
 
96
+ // Return stored fields with results
97
+ const results3 = await index.search('programming', { fields: true });
98
+ for (const r of results3) {
99
+ console.log(r.fields.title, r.score); // stored field values
100
+ }
101
+
94
102
  // Pre-filtered by doc IDs
95
- const results3 = await index.searchFiltered('programming', [1, 3], { highlights: true });
103
+ const results4 = await index.searchFiltered('programming', [1, 3], { highlights: true, fields: true });
96
104
 
97
105
  // Metadata
98
106
  const count = await index.numDocs();
@@ -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
@@ -1,7 +1,7 @@
1
1
  /** Field definition for creating an index. */
2
2
  export interface FieldDef {
3
3
  name: string;
4
- type: 'text' | 'u64' | 'i64' | 'f64';
4
+ type: 'text' | 'string' | 'u64' | 'i64' | 'f64';
5
5
  }
6
6
 
7
7
  /** Search query — either a plain string or a structured query object. */
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucivy-wasm",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Fast BM25 full-text search for browsers — WASM build of Lucivy with threading, OPFS persistence, and LUCE snapshot support",
6
6
  "license": "MIT",
package/pkg/lucivy.wasm CHANGED
Binary file