Query fixes (#5660)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-05-27 14:38:46 +05:00 committed by GitHub
parent 8c6a5f4e9d
commit dff3ccd4a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View File

@ -1296,12 +1296,12 @@ export class LiveQuery implements WithTx, Client {
// We need to add trigger once more, since elastic could have a huge lag with document availability.
if (trigger || this.triggerCounter > 0) {
if (trigger) {
this.triggerCounter = 5 // Schedule 5 refreshes on every 5 seconds.
this.triggerCounter = 2 // Schedule 2 refreshes on every 10 seconds.
}
setTimeout(() => {
this.triggerCounter--
void this.checkUpdateEvents(evt, false)
}, 5000)
}, 10000)
}
const h = this.client.getHierarchy()
@ -1319,6 +1319,15 @@ export class LiveQuery implements WithTx, Client {
Analytics.handleError(err)
console.error(err)
}
} else {
const queries = this.queries.get(q._class)
const pos = queries?.indexOf(q) ?? -1
if (pos >= 0 && queries !== undefined) {
queries.splice(pos, 1)
if (queries?.length === 0) {
this.queries.delete(q._class)
}
}
}
}
}

View File

@ -248,16 +248,13 @@ export class FullTextIndex implements WithFind {
// Just assign scores based on idex
result.forEach((it) => {
const idDoc = indexedDocMap.get(it._id)
const { _score, id, _class, ...extra } = idDoc as any
const { _score } = idDoc as any
it.$source = {
...extra,
$score: _score
}
})
if (scoreSearch !== undefined) {
result.sort((a, b) => scoreSearch * ((a.$source?.$score ?? 0) - (b.$source?.$score ?? 0)))
}
if (scoreSearch !== undefined) {
if (options?.limit !== undefined && options?.limit < result.length) {
result = toFindResult(result.slice(0, options?.limit), result.total)
}