-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a method for exporting an index as a single json object? #299
Comments
function exportIndex(flexSearchIndex) {
// https://github.com/nextapps-de/flexsearch/issues/299
// https://github.com/nextapps-de/flexsearch/issues/274
return new Promise((res, rej) => {
let pkg = [];
const expected = new Set([
"reg",
"reg.cfg",
"reg.cfg.map",
"reg.cfg.map.ctx"
]);
const received = new Set();
const setsEq = (a, b) => {
if (a.size != b.size) {
return false;
}
return Array.from(a).every(el => b.has(el));
};
flexSearchIndex.export((key, data) => {
// https://github.com/nextapps-de/flexsearch/issues/290
// https://github.com/nextapps-de/flexsearch/issues/273
pkg.push([
key
.toString()
.split(".")
.pop(),
data
]);
received.add(key);
if (setsEq(expected, received)) {
res(JSON.stringify(pkg));
}
});
});
} |
Just add a version implemented by ts function exportIndex(flexSearchIndex: Index) {
// https://github.com/nextapps-de/flexsearch/issues/299
// https://github.com/nextapps-de/flexsearch/issues/274
return new Promise<[string, any][]>((res, rej) => {
const pkg: [string, any][] = []
const expected = new Set([
'reg',
'reg.cfg',
'reg.cfg.map',
'reg.cfg.map.ctx',
])
const received = new Set<string>()
const setsEq = (a: Set<string>, b: Set<string>) => {
if (a.size != b.size) {
return false
}
return Array.from(a).every((el) => b.has(el))
}
flexSearchIndex.export((key, data) => {
// https://github.com/nextapps-de/flexsearch/issues/290
// https://github.com/nextapps-de/flexsearch/issues/273
pkg.push([key.toString().split('.').pop()!, data])
received.add(key as string)
if (setsEq(expected, received)) {
res(pkg)
}
})
})
} |
There will be an update in the next version which returns promises instead of applying inline awaits. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to store index as an object in browser caches but not found a method which could help with it
The text was updated successfully, but these errors were encountered: