mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 19:02:23 +08:00
fix(nbstore): fix indexer cache not working (#11922)
This commit is contained in:
@@ -265,40 +265,47 @@ export class DataStruct {
|
|||||||
if (cached) {
|
if (cached) {
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
using _ = await this.measure(`query[${query.type}]`);
|
|
||||||
if (query.type === 'match') {
|
const result = await (async () => {
|
||||||
const iidx = this.invertedIndex.get(table)?.get(query.field as string);
|
using _ = await this.measure(`query[${query.type}]`);
|
||||||
if (!iidx) {
|
if (query.type === 'match') {
|
||||||
return new Match();
|
const iidx = this.invertedIndex.get(table)?.get(query.field as string);
|
||||||
|
if (!iidx) {
|
||||||
|
return new Match();
|
||||||
|
}
|
||||||
|
return await iidx.match(trx, query.match);
|
||||||
|
} else if (query.type === 'boolean') {
|
||||||
|
const weights = [];
|
||||||
|
for (const q of query.queries) {
|
||||||
|
weights.push(await this.queryRaw(trx, table, q, cache));
|
||||||
|
}
|
||||||
|
if (query.occur === 'must') {
|
||||||
|
return weights.reduce((acc, w) => acc.and(w));
|
||||||
|
} else if (query.occur === 'must_not') {
|
||||||
|
const total = weights.reduce((acc, w) => acc.and(w));
|
||||||
|
return (await this.matchAll(trx, table)).exclude(total);
|
||||||
|
} else if (query.occur === 'should') {
|
||||||
|
return weights.reduce((acc, w) => acc.or(w));
|
||||||
|
}
|
||||||
|
} else if (query.type === 'all') {
|
||||||
|
return await this.matchAll(trx, table);
|
||||||
|
} else if (query.type === 'boost') {
|
||||||
|
return (await this.queryRaw(trx, table, query.query, cache)).boost(
|
||||||
|
query.boost
|
||||||
|
);
|
||||||
|
} else if (query.type === 'exists') {
|
||||||
|
const iidx = this.invertedIndex.get(table)?.get(query.field as string);
|
||||||
|
if (!iidx) {
|
||||||
|
return new Match();
|
||||||
|
}
|
||||||
|
return await iidx.all(trx);
|
||||||
}
|
}
|
||||||
return await iidx.match(trx, query.match);
|
throw new Error(`Query type '${query.type}' not supported`);
|
||||||
} else if (query.type === 'boolean') {
|
})();
|
||||||
const weights = [];
|
|
||||||
for (const q of query.queries) {
|
cache.set(query, result);
|
||||||
weights.push(await this.queryRaw(trx, table, q, cache));
|
|
||||||
}
|
return result;
|
||||||
if (query.occur === 'must') {
|
|
||||||
return weights.reduce((acc, w) => acc.and(w));
|
|
||||||
} else if (query.occur === 'must_not') {
|
|
||||||
const total = weights.reduce((acc, w) => acc.and(w));
|
|
||||||
return (await this.matchAll(trx, table)).exclude(total);
|
|
||||||
} else if (query.occur === 'should') {
|
|
||||||
return weights.reduce((acc, w) => acc.or(w));
|
|
||||||
}
|
|
||||||
} else if (query.type === 'all') {
|
|
||||||
return await this.matchAll(trx, table);
|
|
||||||
} else if (query.type === 'boost') {
|
|
||||||
return (await this.queryRaw(trx, table, query.query, cache)).boost(
|
|
||||||
query.boost
|
|
||||||
);
|
|
||||||
} else if (query.type === 'exists') {
|
|
||||||
const iidx = this.invertedIndex.get(table)?.get(query.field as string);
|
|
||||||
if (!iidx) {
|
|
||||||
return new Match();
|
|
||||||
}
|
|
||||||
return await iidx.all(trx);
|
|
||||||
}
|
|
||||||
throw new Error(`Query type '${query.type}' not supported`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async clear(trx: DataStructRWTransaction) {
|
async clear(trx: DataStructRWTransaction) {
|
||||||
|
|||||||
Reference in New Issue
Block a user