lucivy 0.1.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Luciform Research
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # lucivy
2
+
3
+ Fast BM25 full-text search for Node.js — with substring matching, fuzzy search, regex, and highlights. Powered by Rust via napi-rs.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install lucivy
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```javascript
14
+ const { Index } = require('lucivy');
15
+
16
+ const index = Index.create('./my_index', [
17
+ { name: 'title', type: 'text' },
18
+ { name: 'body', type: 'text' },
19
+ ]);
20
+
21
+ index.add(1, { title: 'Rust Programming', body: 'Systems programming with memory safety' });
22
+ index.add(2, { title: 'Python Guide', body: 'Data science and web development' });
23
+ index.commit();
24
+
25
+ let results = index.search('programming', { highlights: true });
26
+ for (const r of results) {
27
+ console.log(r.docId, r.score, r.highlights);
28
+ }
29
+ ```
30
+
31
+ ## API
32
+
33
+ ### Create / open
34
+
35
+ ```javascript
36
+ const index = Index.create('./my_index', [
37
+ { name: 'title', type: 'text' },
38
+ { name: 'body', type: 'text' },
39
+ { name: 'tag', type: 'keyword' },
40
+ { name: 'year', type: 'i64', indexed: true, fast: true },
41
+ ]);
42
+
43
+ const index2 = Index.open('./my_index');
44
+ ```
45
+
46
+ ### Add / update / delete
47
+
48
+ ```javascript
49
+ index.add(1, { title: 'Hello', body: 'World' });
50
+ index.addMany([
51
+ { docId: 2, title: 'Foo', body: 'Bar' },
52
+ { docId: 3, title: 'Baz', body: 'Qux' },
53
+ ]);
54
+ index.update(1, { title: 'Updated', body: 'Content' });
55
+ index.delete(2);
56
+ index.commit();
57
+ ```
58
+
59
+ ### Search
60
+
61
+ ```javascript
62
+ // String query — each word searched across all text fields (contains_split)
63
+ let results = index.search('rust async programming');
64
+
65
+ // Options
66
+ results = index.search('rust', { limit: 20, highlights: true, allowedIds: [1, 3] });
67
+ ```
68
+
69
+ #### contains — substring, fuzzy, regex (cross-token)
70
+
71
+ Searches **stored text**, not individual tokens. Handles multi-word phrases, substrings, typos, and regex across token boundaries.
72
+
73
+ ```javascript
74
+ // Substring — matches "programming", "programmer", etc.
75
+ index.search({ type: 'contains', field: 'body', value: 'program' });
76
+
77
+ // Multi-word phrase
78
+ index.search({ type: 'contains', field: 'body', value: 'memory safety' });
79
+
80
+ // Fuzzy (catches typos, distance=1 by default)
81
+ index.search({ type: 'contains', field: 'body', value: 'programing languag', distance: 1 });
82
+
83
+ // Regex on stored text
84
+ index.search({ type: 'contains', field: 'body', value: 'program.*language', regex: true });
85
+ ```
86
+
87
+ #### contains_split — one word = one contains query, OR'd together
88
+
89
+ ```javascript
90
+ // "rust safety" → contains("rust") OR contains("safety") on body
91
+ index.search({ type: 'contains_split', field: 'body', value: 'rust safety' });
92
+ ```
93
+
94
+ #### boolean — combine queries with must / should / must_not
95
+
96
+ ```javascript
97
+ index.search({
98
+ type: 'boolean',
99
+ must: [
100
+ { type: 'contains', field: 'body', value: 'rust' },
101
+ ],
102
+ should: [
103
+ { type: 'contains', field: 'title', value: 'guide' },
104
+ ],
105
+ must_not: [
106
+ { type: 'contains', field: 'body', value: 'deprecated' },
107
+ ],
108
+ });
109
+ ```
110
+
111
+ #### keyword / range — for non-text fields
112
+
113
+ ```javascript
114
+ index.search({ type: 'keyword', field: 'tag', value: 'rust' });
115
+ index.search({
116
+ type: 'contains', field: 'body', value: 'programming',
117
+ filters: [{ field: 'year', op: 'gte', value: 2023 }],
118
+ });
119
+ ```
120
+
121
+ ### Snapshots (export / import)
122
+
123
+ ```javascript
124
+ // Export to file
125
+ index.exportSnapshotTo('./backup.luce');
126
+
127
+ // Export to Buffer
128
+ const buf = index.exportSnapshot();
129
+
130
+ // Import from file
131
+ const restored = Index.importSnapshotFrom('./backup.luce', './restored_index');
132
+
133
+ // Import from Buffer
134
+ const restored2 = Index.importSnapshot(buf, './restored_index');
135
+ ```
136
+
137
+ ### Properties
138
+
139
+ ```javascript
140
+ index.numDocs // number of documents
141
+ index.path // index directory path
142
+ index.schema // array of field definitions
143
+ ```
144
+
145
+ ## License
146
+
147
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export interface SearchResult {
7
+ docId: number
8
+ score: number
9
+ highlights?: Record<string, Array<Array<number>>>
10
+ }
11
+ export interface FieldDef {
12
+ name: string
13
+ type: 'text' | 'string' | 'u64' | 'i64' | 'f64'
14
+ stored?: boolean
15
+ indexed?: boolean
16
+ fast?: boolean
17
+ }
18
+ export interface SearchOptions {
19
+ limit?: number
20
+ highlights?: boolean
21
+ allowedIds?: Array<number>
22
+ }
23
+ export declare class Index {
24
+ /** Create a new index at the given path. */
25
+ static create(path: string, fields: Array<FieldDef>, stemmer?: string | undefined | null): Index
26
+ /** Open an existing index at the given path. */
27
+ static open(path: string): Index
28
+ /** Add a document. `fields` is an object with field names as keys. */
29
+ add(docId: number, fields: Record<string, any>): void
30
+ /**
31
+ * Add multiple documents at once.
32
+ * Each element must have a `docId` key and field values.
33
+ */
34
+ addMany(docs: Array<Record<string, any>>): void
35
+ /** Delete a document by doc_id. */
36
+ delete(docId: number): void
37
+ /** Update a document (delete + re-add). */
38
+ update(docId: number, fields: Record<string, any>): void
39
+ /** Commit pending changes (makes added/deleted docs visible to searches). */
40
+ commit(): void
41
+ /** Rollback pending changes. */
42
+ rollback(): void
43
+ /**
44
+ * Search the index.
45
+ * `query` can be a string (contains_split on all text fields) or an object (QueryConfig).
46
+ */
47
+ search(query: any, options?: SearchOptions | undefined | null): Array<SearchResult>
48
+ /** Number of documents in the index. */
49
+ get numDocs(): number
50
+ /** Index path. */
51
+ get path(): string
52
+ /**
53
+ * Export this index as a LUCE snapshot (Buffer).
54
+ * Throws if there are uncommitted changes.
55
+ */
56
+ exportSnapshot(): Buffer
57
+ /** Export this index as a LUCE snapshot to a file. */
58
+ exportSnapshotTo(path: string): void
59
+ /**
60
+ * Import an index from a LUCE snapshot (Buffer).
61
+ * The snapshot must contain exactly one index.
62
+ */
63
+ static importSnapshot(data: Buffer, destPath?: string | undefined | null): Index
64
+ /** Import an index from a LUCE snapshot file. */
65
+ static importSnapshotFrom(path: string, destPath?: string | undefined | null): Index
66
+ /** Schema as a list of field definitions. */
67
+ get schema(): Array<FieldDef>
68
+ }
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ const { Index } = require('./lucivy.node');
2
+
3
+ module.exports = { Index };
package/lucivy.node ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "lucivy",
3
+ "version": "0.1.0",
4
+ "description": "Fast BM25 full-text search with substring matching, fuzzy search, and regex — powered by Rust",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "license": "MIT",
8
+ "author": "Luciform Research",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/L-Defraiteur/lucivy"
12
+ },
13
+ "keywords": [
14
+ "search",
15
+ "full-text",
16
+ "bm25",
17
+ "fuzzy",
18
+ "substring",
19
+ "fts",
20
+ "tantivy",
21
+ "rust"
22
+ ],
23
+ "napi": {
24
+ "name": "lucivy",
25
+ "triples": {
26
+ "defaults": true
27
+ }
28
+ },
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "lucivy.node",
33
+ "README.md"
34
+ ],
35
+ "devDependencies": {
36
+ "@napi-rs/cli": "^2.18.0"
37
+ },
38
+ "scripts": {
39
+ "build": "napi build --release",
40
+ "build:debug": "napi build"
41
+ }
42
+ }