gs-search 0.1.4 → 0.1.6
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.ja.md +1 -1
- package/README.ko.md +1 -1
- package/README.md +3 -3
- package/README.zh-CN.md +2 -2
- package/lib/browser.cjs +68 -1
- package/lib/browser.js +69 -1
- package/lib/core.cjs +504 -1
- package/lib/core.d.ts +5 -13
- package/lib/core.js +507 -1
- package/lib/index.cjs +38 -1
- package/lib/index.js +5 -1
- package/lib/node.cjs +99 -1
- package/lib/node.js +81 -1
- package/lib/simple.cjs +64 -1
- package/lib/simple.d.ts +5 -11
- package/lib/simple.js +67 -1
- package/lib/type.cjs +2 -0
- package/lib/type.d.ts +53 -10
- package/lib/type.js +1 -0
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -134,7 +134,7 @@ const engine = new SearchEngine({
|
|
|
134
134
|
|
|
135
135
|
### SearchEngine
|
|
136
136
|
|
|
137
|
-
- `constructor(options:
|
|
137
|
+
- `constructor(options: ISearchEngineOption)`: 新しいコアエンジンインスタンスを作成
|
|
138
138
|
- `init(): Promise<void>`: エンジンを初期化
|
|
139
139
|
- `addDocument(doc: IDocument): Promise<void>`: 単一ドキュメントを追加
|
|
140
140
|
- `addDocuments(docs: IDocument[]): Promise<void>`: 複数ドキュメントを追加
|
package/README.ko.md
CHANGED
|
@@ -134,7 +134,7 @@ const engine = new SearchEngine({
|
|
|
134
134
|
|
|
135
135
|
### SearchEngine
|
|
136
136
|
|
|
137
|
-
- `constructor(options:
|
|
137
|
+
- `constructor(options: ISearchEngineOption)`: 새로운 코어 엔진 인스턴스 생성
|
|
138
138
|
- `init(): Promise<void>`: 엔진 초기화
|
|
139
139
|
- `addDocument(doc: IDocument): Promise<void>`: 단일 문서 추가
|
|
140
140
|
- `addDocuments(docs: IDocument[]): Promise<void>`: 다중 문서 추가
|
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ const customTokenizer = (text: string): string[] => {
|
|
|
116
116
|
|
|
117
117
|
// Create engine with custom tokenizers
|
|
118
118
|
const engine = new SearchEngine({
|
|
119
|
-
|
|
119
|
+
storage: new BrowserStorage('search-data'),
|
|
120
120
|
indexingTokenizer: customTokenizer,
|
|
121
121
|
searchTokenizer: customTokenizer
|
|
122
122
|
});
|
|
@@ -127,7 +127,7 @@ const engine = new SearchEngine({
|
|
|
127
127
|
### SimpleSearch
|
|
128
128
|
|
|
129
129
|
**Static Methods (No instance creation required):**
|
|
130
|
-
- `configure(config: Partial<
|
|
130
|
+
- `configure(config: Partial<ISearchEngineOption>): void`: Configure the search engine
|
|
131
131
|
- `addDocument(doc: IDocument): Promise<void>`: Add a single document
|
|
132
132
|
- `addDocuments(docs: IDocument[]): Promise<void>`: Add multiple documents
|
|
133
133
|
- `addDocumentIfMissing(doc: IDocument): Promise<void>`: Add a single document if it doesn't exist
|
|
@@ -141,7 +141,7 @@ const engine = new SearchEngine({
|
|
|
141
141
|
|
|
142
142
|
### SearchEngine
|
|
143
143
|
|
|
144
|
-
- `constructor(options:
|
|
144
|
+
- `constructor(options: ISearchEngineOption)`: Create a new core engine instance
|
|
145
145
|
- `init(): Promise<void>`: Initialize the engine
|
|
146
146
|
- `addDocument(doc: IDocument): Promise<void>`: Add a single document
|
|
147
147
|
- `addDocuments(docs: IDocument[]): Promise<void>`: Add multiple documents
|
package/README.zh-CN.md
CHANGED
|
@@ -225,7 +225,7 @@ SimpleSearch.configure({
|
|
|
225
225
|
### SimpleSearch
|
|
226
226
|
|
|
227
227
|
**静态方法(无需实例创建):**
|
|
228
|
-
- `configure(config: Partial<
|
|
228
|
+
- `configure(config: Partial<ISearchEngineOption>): void`: 配置搜索引擎
|
|
229
229
|
- `addDocument(doc: IDocument): Promise<void>`: 添加单个文档
|
|
230
230
|
- `addDocuments(docs: IDocument[]): Promise<void>`: 添加多个文档
|
|
231
231
|
- `addDocumentIfMissing(doc: IDocument): Promise<void>`: 如果文档不存在则添加单个文档
|
|
@@ -239,7 +239,7 @@ SimpleSearch.configure({
|
|
|
239
239
|
|
|
240
240
|
### SearchEngine
|
|
241
241
|
|
|
242
|
-
- `constructor(options:
|
|
242
|
+
- `constructor(options: ISearchEngineOption)`: 创建一个新的核心引擎实例
|
|
243
243
|
- `init(): Promise<void>`: 初始化引擎
|
|
244
244
|
- `addDocument(doc: IDocument): Promise<void>`: 添加单个文档
|
|
245
245
|
- `addDocuments(docs: IDocument[]): Promise<void>`: 添加多个文档
|
package/lib/browser.cjs
CHANGED
|
@@ -1 +1,68 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
class BrowserStorage {
|
|
3
|
+
#baseDir;
|
|
4
|
+
constructor(baseDir) {
|
|
5
|
+
this.#baseDir = baseDir;
|
|
6
|
+
}
|
|
7
|
+
// 获取当前实例的专属目录句柄
|
|
8
|
+
async #getDirHandle() {
|
|
9
|
+
return await (await navigator.storage.getDirectory()).getDirectoryHandle(this.#baseDir, { create: !0 });
|
|
10
|
+
}
|
|
11
|
+
async write(filename, data) {
|
|
12
|
+
const writable = await (await (await this.#getDirHandle()).getFileHandle(filename, { create: !0 })).createWritable();
|
|
13
|
+
await writable.write(data), await writable.close();
|
|
14
|
+
}
|
|
15
|
+
async append(filename, data) {
|
|
16
|
+
const dir = await this.#getDirHandle();
|
|
17
|
+
let fileHandle;
|
|
18
|
+
try {
|
|
19
|
+
fileHandle = await dir.getFileHandle(filename, { create: !0 });
|
|
20
|
+
} catch {
|
|
21
|
+
fileHandle = await dir.getFileHandle(filename, { create: !0 });
|
|
22
|
+
}
|
|
23
|
+
const file = await fileHandle.getFile(), writable = await fileHandle.createWritable({ keepExistingData: !0 });
|
|
24
|
+
await writable.seek(file.size), await writable.write(data), await writable.close();
|
|
25
|
+
}
|
|
26
|
+
async read(filename) {
|
|
27
|
+
const dir = await this.#getDirHandle();
|
|
28
|
+
try {
|
|
29
|
+
return await (await (await dir.getFileHandle(filename)).getFile()).arrayBuffer();
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async readRange(filename, start, end) {
|
|
35
|
+
const dir = await this.#getDirHandle();
|
|
36
|
+
try {
|
|
37
|
+
return await (await (await dir.getFileHandle(filename)).getFile()).slice(start, end).arrayBuffer();
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async remove(filename) {
|
|
43
|
+
const dir = await this.#getDirHandle();
|
|
44
|
+
try {
|
|
45
|
+
await dir.removeEntry(filename);
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async listFiles() {
|
|
50
|
+
const dir = await this.#getDirHandle(), keys = [];
|
|
51
|
+
for await (const key of dir.keys()) keys.push(key);
|
|
52
|
+
return keys;
|
|
53
|
+
}
|
|
54
|
+
async clearAll() {
|
|
55
|
+
const dir = await this.#getDirHandle();
|
|
56
|
+
for await (const key of dir.keys())
|
|
57
|
+
await dir.removeEntry(key, { recursive: !0 });
|
|
58
|
+
}
|
|
59
|
+
async getFileSize(filename) {
|
|
60
|
+
const dir = await this.#getDirHandle();
|
|
61
|
+
try {
|
|
62
|
+
return (await (await dir.getFileHandle(filename)).getFile()).size;
|
|
63
|
+
} catch {
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.BrowserStorage = BrowserStorage;
|
package/lib/browser.js
CHANGED
|
@@ -1 +1,69 @@
|
|
|
1
|
-
class
|
|
1
|
+
class BrowserStorage {
|
|
2
|
+
#baseDir;
|
|
3
|
+
constructor(baseDir) {
|
|
4
|
+
this.#baseDir = baseDir;
|
|
5
|
+
}
|
|
6
|
+
// 获取当前实例的专属目录句柄
|
|
7
|
+
async #getDirHandle() {
|
|
8
|
+
return await (await navigator.storage.getDirectory()).getDirectoryHandle(this.#baseDir, { create: !0 });
|
|
9
|
+
}
|
|
10
|
+
async write(filename, data) {
|
|
11
|
+
const writable = await (await (await this.#getDirHandle()).getFileHandle(filename, { create: !0 })).createWritable();
|
|
12
|
+
await writable.write(data), await writable.close();
|
|
13
|
+
}
|
|
14
|
+
async append(filename, data) {
|
|
15
|
+
const dir = await this.#getDirHandle();
|
|
16
|
+
let fileHandle;
|
|
17
|
+
try {
|
|
18
|
+
fileHandle = await dir.getFileHandle(filename, { create: !0 });
|
|
19
|
+
} catch {
|
|
20
|
+
fileHandle = await dir.getFileHandle(filename, { create: !0 });
|
|
21
|
+
}
|
|
22
|
+
const file = await fileHandle.getFile(), writable = await fileHandle.createWritable({ keepExistingData: !0 });
|
|
23
|
+
await writable.seek(file.size), await writable.write(data), await writable.close();
|
|
24
|
+
}
|
|
25
|
+
async read(filename) {
|
|
26
|
+
const dir = await this.#getDirHandle();
|
|
27
|
+
try {
|
|
28
|
+
return await (await (await dir.getFileHandle(filename)).getFile()).arrayBuffer();
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async readRange(filename, start, end) {
|
|
34
|
+
const dir = await this.#getDirHandle();
|
|
35
|
+
try {
|
|
36
|
+
return await (await (await dir.getFileHandle(filename)).getFile()).slice(start, end).arrayBuffer();
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async remove(filename) {
|
|
42
|
+
const dir = await this.#getDirHandle();
|
|
43
|
+
try {
|
|
44
|
+
await dir.removeEntry(filename);
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async listFiles() {
|
|
49
|
+
const dir = await this.#getDirHandle(), keys = [];
|
|
50
|
+
for await (const key of dir.keys()) keys.push(key);
|
|
51
|
+
return keys;
|
|
52
|
+
}
|
|
53
|
+
async clearAll() {
|
|
54
|
+
const dir = await this.#getDirHandle();
|
|
55
|
+
for await (const key of dir.keys())
|
|
56
|
+
await dir.removeEntry(key, { recursive: !0 });
|
|
57
|
+
}
|
|
58
|
+
async getFileSize(filename) {
|
|
59
|
+
const dir = await this.#getDirHandle();
|
|
60
|
+
try {
|
|
61
|
+
return (await (await dir.getFileHandle(filename)).getFile()).size;
|
|
62
|
+
} catch {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
BrowserStorage
|
|
69
|
+
};
|