1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-29 16:50:13 +02:00

update readme part 1 of 2

This commit is contained in:
Thomas Wilkerling
2025-03-27 21:04:06 +01:00
parent 5abd01a3c5
commit 2b1771fd6d
12 changed files with 2745 additions and 2699 deletions

View File

@@ -26,6 +26,7 @@ for(let i = 0; i < files.length; i++){
> You'll need to use the same configuration as you used before the export. Any changes on the configuration needs to be re-indexed.
<a name="serialize"></a>
## Fast-Boot Serialization for Server-Side-Rendering (PHP, Python, Ruby, Rust, Java, Go, Node.js, ...)
> This is an experimental feature with limited support which probably might drop in future release. You're welcome to give some feedback.
@@ -97,3 +98,93 @@ This function is callable like the above example:
const index = new Index();
inject(index);
```
<a name="export"></a>
## Export / Import (In-Memory)
### Node.js
> Persistent-Indexes and Worker-Indexes don't support Import/Export.
Export an `Index` or `Document-Index` to the folder `/export/`:
```js
import { promises as fs } from "fs";
await index.export(async function(key, data){
await fs.writeFile("./export/" + key, data, "utf8");
});
```
Import from folder `/export/` into an `Index` or `Document-Index`:
```js
const index = new Index({/* keep old config and place it here */});
const files = await fs.readdir("./export/");
for(let i = 0; i < files.length; i++){
const data = await fs.readFile("./export/" + files[i], "utf8");
await index.import(files[i], data);
}
```
> You'll need to use the same configuration as you used before the export. Any changes on the configuration needs to be re-indexed.
### Browser
```js
index.export(function(key, data){
// you need to store both the key and the data!
// e.g. use the key for the filename and save your data
localStorage.setItem(key, data);
});
```
> The size of the export corresponds to the memory consumption of the library. To reduce export size you have to use a configuration which has less memory footprint (use the table at the bottom to get information about configs and its memory allocation).
When your save routine runs asynchronously you have to use `async/await` or return a promise:
```js
index.export(function(key, data){
return new Promise(function(resolve){
// do the saving as async
resolve();
});
});
```
Before you can import data, you need to create your index first. For document indexes provide the same document descriptor you used when export the data. This configuration isn't stored in the export.
```js
const index = new Index({/* keep old config and place it here */});
```
To import the data just pass a key and data:
```
const data = localStorage.getItem(key);
index.import(key, data);
```
You need to import every key! Otherwise, your index does not work. You need to store the keys from the export and use this keys for the import (the order of the keys can differ).
> The feature "fastupdate" is automatically disabled on import.
This is just for demonstration and is not recommended, because you might have other keys in your localStorage which aren't supported as an import:
```js
var keys = Object.keys(localStorage);
for(let i = 0, key, data; i < keys.length; i++){
key = keys[i]
data = localStorage.getItem(key);
index.import(key, data);
}
```