fergiemcdowall / search-index

A persistent, network resilient, full text search library for the browser and Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flush db but still get record and a unhandle promise rejection

everlose opened this issue · comments

Hi,I found a touble in FLUSH db.

The second query appears to have a cache. and got a uncaught (in promise),try with following code,

const si = require('search-index')
let searchDB

si({
  name: 'SEARCH-DB',
  storeVectors: true
}).then((result) => {
  searchDB = result;
})

then

await searchDB.PUT([
  { _id: 'qwertyu', idx: 'q' },
  { _id: 'asdfgh', idx: 'a' }
]);

await searchDB.QUERY({
  SEARCH: ['q']
})
// {RESULT: Array(1), RESULT_LENGTH: 1}


await searchDB.FLUSH(); // or,await searchDB.INDEX.STORE.clear();

await searchDB.QUERY({
  SEARCH: ['q']
})
// {RESULT: Array(1), RESULT_LENGTH: 1}
//  Uncaught (in promise) err {type: "NotFoundError", name: "NotFoundError", cause: Error: NotFound: , message: "Key not found in database [○DOCUMENT_COUNT○]", stack: "NotFoundError: Key not found in database [○DOCUMEN…ch-demo/node_modules/encoding-down/index.js:75:21"}

It looks like a query for “DOCUMENT_COUNT ” throw the “Uncaught (in promise)”

By the way, to reproduce this problem, the first QUERY is necessary

Ah yes, nice find, FLUSH() should clear the cache but is not doing so. This line should look something like this:

FLUSH: c.flush().then(() => ops.fii.STORE.clear())

@everlose try it now with search-index@2.3.0

I'm going to go out on a limb and say that this is fixed 🙂

I have upgrade search-index to version 2.3.0, but the problem is still exist.
maybe the problem is in QUERY ? because the QUERY is still return resolved and a unhandle promise rejection.

I have upgrade search-index to version 2.3.0, but the problem is still exist.
maybe the problem is in QUERY ? because the QUERY is still return resolved and a unhandle promise rejection.

Oh, sorry
FLUSH is ok.
but INDEX.STORE.clear is still not work.

Yes, I should have noted this when I closed the issue- INDEX.STORE.clear() wont actually work, so use FLUSH()