fergiemcdowall / search-index

A persistent, network resilient, full text search library for the browser and Node.js
MIT License
1.39k stars 149 forks source link

Flush db but still get record and a unhandle promise rejection #535

Closed everlose closed 3 years ago

everlose commented 3 years ago

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"}
everlose commented 3 years ago

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

everlose commented 3 years ago

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

fergiemcdowall commented 3 years ago

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())
fergiemcdowall commented 3 years ago

@everlose try it now with search-index@2.3.0

fergiemcdowall commented 3 years ago

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

1eeing commented 3 years ago

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.

1eeing commented 3 years ago

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.

fergiemcdowall commented 3 years ago

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