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 initialization
const index = new FlexSearch({
encode: "simple", //phonetic normalizations
tokenize: "forward", //match substring beginning of word
threshold: 2, //exclude scores below this number
resolution: 9, //how many steps in the scoring algorithm
depth: 4, //how far around words to search for adjacent matches. Disabled for title
doc: {
id: "id",
field: "data"
}
});
// example import from IndexedDB to FlexSearch
localforage.getItem("INDEX_KEY").then(cachedIndexData => {
index.import(cachedIndexData);
});
// example export from FlexSearch to IndexedDB
localforage.setItem(INDEX_KEY, this.index.export());
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 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.
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.