You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am upgrading FlexSearch from v0.6.30 to the latest version, 0.7.31. I am testing import and export functionality in Node.
I want to write FlexSearch data to IndexedDB via export, and I want to import data from IndexedDB to new instances of FlexSearch.
My understanding is that the library was completely rewritten and many aspects of the API have changed. Our old application of the import/export functionality no longer works.
Here's a simplified summary of how we were importing/exporting before:
// v0.6.30 import/export implementation// example initializationconstindex=newFlexSearch({encode: "simple",//phonetic normalizationstokenize: "forward",//match substring beginning of wordthreshold: 2,//exclude scores below this numberresolution: 9,//how many steps in the scoring algorithmdepth: 4,//how far around words to search for adjacent matches. Disabled for titledoc: {id: "id",field: "data"}});// example import from IndexedDB to FlexSearchlocalforage.getItem("INDEX_KEY").then(cachedIndexData=>{index.import(cachedIndexData);});// example export from FlexSearch to IndexedDBlocalforage.setItem(INDEX_KEY,this.index.export());
We've moved to the Document implementation because we are handling multiple indexes. Here is a working example:
constDexie=require('dexie');constFlexSearch=require('flexsearch');const{ indexedDB, IDBKeyRange }=require('fake-indexeddb');const{ Document }=FlexSearch;
constINDEX_KEY='book-index-key';constindexeddb=newDexie("BookDatabase",{indexedDB: indexedDB,IDBKeyRange: IDBKeyRange});indexeddb.version(1).stores({books: '++id, title, author, year',attackIndex: '++key,data'});constbookData=[{id: 1,title: 'The Great Gatsby',author: 'F. Scott Fitzgerald',year: 1925},{id: 2,title: 'Jane Eyre',author: 'Charlotte Bronte',year: 1847},{id: 3,title: 'Pride and Prejudice',author: 'Jane Austen',year: 1813},{id: 4,title: 'Nineteen Eighty-Four',author: 'George Orwell',year: 1949},{id: 5,title: 'The Hobbit',author: 'J. R. R. Tolkien',year: 1937}]constfsDocument=newDocument({id: 'id',index: [{field: 'title',tokenize: 'forward',optimize: true},{field: 'author',tokenize: 'forward',optimize: true,minlength: 3,context: {depth: 3,resolution: 2,},},],});// add book data to indexeddbbookData.forEach(async(book)=>awaitindexeddb.books.put(book));
// retrieve data by IDconstresult=awaitindexeddb.books.get(1);console.log(`Dexie Book Test: ${JSON.stringify(result)}\n`)}
export gave us a ton of trouble however. No matter what we try, the second console.log statement below -- the one that that prints the export results -- always executes beforefsExport is done.
Since the document.export function is designed to work asynchronously using setTimeout, and it doesn't provide any clear indication when all of the keys have been processed, we had to devise a different approach.
The only potential problem with this solution is that it presupposes that we always know the value of totalKeys, which in this example is 9.
We did some testing and deduced that FlexSearch will always iterate (3 * numIndexes) + 3 times during an export call. Our Document index contains two indexes, so that's (3 * 2) + 3 = 9 as we can see in the output above, e.g., reg, title.cfg, title.map, etc.
Can we assume this is always true?
Are we missing something? Is there an easier way?
We've also yet to figure out an import solution (i.e., importing data from IndexedDB to FlexSearch) so any pointers there is appreciated.
The text was updated successfully, but these errors were encountered:
I don't have all the answers you are looking for, but check out the issue I wrote #384 . I have a different problem but I posted a mostly working solution for importing/exporting... Maybe that helps
I am upgrading FlexSearch from v0.6.30 to the latest version, 0.7.31. I am testing
import
andexport
functionality in Node.I want to write FlexSearch data to IndexedDB via export, and I want to import data from IndexedDB to new instances of FlexSearch.
My understanding is that the library was completely rewritten and many aspects of the API have changed. Our old application of the import/export functionality no longer works.
Here's a simplified summary of how we were importing/exporting before:
We've moved to the
Document
implementation because we are handling multiple indexes. Here is a working example:export
gave us a ton of trouble however. No matter what we try, the secondconsole.log
statement below -- the one that that prints the export results -- always executes beforefsExport
is done.We did end up managing to make it work. Here is the solution we devised as well as all of the other attempts that failed.
When it works, it outputs:
Since the
document.export
function is designed to work asynchronously usingsetTimeout
, and it doesn't provide any clear indication when all of the keys have been processed, we had to devise a different approach.The only potential problem with this solution is that it presupposes that we always know the value of
totalKeys
, which in this example is9
.We did some testing and deduced that FlexSearch will always iterate
(3 * numIndexes) + 3
times during anexport
call. OurDocument
index contains two indexes, so that's(3 * 2) + 3 = 9
as we can see in the output above, e.g.,reg
,title.cfg
,title.map
, etc.Can we assume this is always true?
Are we missing something? Is there an easier way?
We've also yet to figure out an
import
solution (i.e., importing data from IndexedDB to FlexSearch) so any pointers there is appreciated.The text was updated successfully, but these errors were encountered: