Describe the bug
With the new release of Lyra is not possible to restore an instance from a file.
/home/mateonunez/source/lyra/just/node_modules/.pnpm/@[email protected]/node_modules/@lyrasearch/lyra/dist/cjs/src/lyra.js:403
if (!(index in lyra.tokenOccurrencies))
^
TypeError: Cannot use 'in' operator to search for 'name' in undefined
at search (/home/mateonunez/source/lyra/just/node_modules/.pnpm/@[email protected]/node_modules/@lyrasearch/lyra/dist/cjs/src/lyra.js:403:21)
at Object.<anonymous> (/home/mateonunez/source/lyra/just/just.js:12:18)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
Node.js v18.12.1
To Reproduce
Steps to reproduce the behavior:
- Create a new project, add
lyra
and plugin-data-persistence
dependencies.
- Create a new instance of Lyra and save it to a file.
- Restore that file.
- Make a search.
or just copy this code:
const { create, insert, search } = require('@lyrasearch/lyra')
const { persistToFile, restoreFromFile } = require('@lyrasearch/plugin-data-persistence')
const db = create({ schema: { name: 'string', age: 'string' }})
insert(db, { name: 'john doe', age: '27' })
insert(db, { name: 'jenny doe', age: '27' })
const filePath = persistToFile(db, 'json', './db.json');
const results = search(db, { term: 'joh' });
const db2 = restoreFromFile('json', filePath);
const results2 = search(db2, { term: 'jen' });
console.log(results, filePath, results2)
Expected behavior
The plugin should restore a Lyra instance from a file.
Desktop:
- Node v18.12.1
- Lyra v0.3.1
- plugin-data-persistence v0.0.3