mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
feat: improve indexing perf with native indexer (#14066)
fix #12132, #14006, #13496, #12375, #12132 The previous idb indexer generated a large number of scattered writes when flushing to disk, which caused CPU and disk write spikes. If the document volume is extremely large, the accumulation of write transactions will cause memory usage to continuously increase. This PR introduces batch writes to mitigate write performance on the web side, and adds a native indexer on the Electron side to greatly improve performance. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Full-text search (FTS) added across storage layers and native plugins: indexing, search, document retrieval, match ranges, and index flushing. * New SQLite-backed indexer storage, streaming search/aggregate APIs, and in-memory index with node-building and highlighting. * **Performance** * Indexing rewritten for batched, concurrent writes and parallel metadata updates. * Search scoring enhanced to consider multiple term positions and aggregated term data. * **Other** * Configurable refresh interval and indexer version bump. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -155,4 +155,33 @@ export interface NbStorePlugin {
|
||||
id: string;
|
||||
docId: string;
|
||||
}) => Promise<CrawlResult>;
|
||||
ftsAddDocument: (options: {
|
||||
id: string;
|
||||
indexName: string;
|
||||
docId: string;
|
||||
text: string;
|
||||
index: boolean;
|
||||
}) => Promise<void>;
|
||||
ftsDeleteDocument: (options: {
|
||||
id: string;
|
||||
indexName: string;
|
||||
docId: string;
|
||||
}) => Promise<void>;
|
||||
ftsSearch: (options: {
|
||||
id: string;
|
||||
indexName: string;
|
||||
query: string;
|
||||
}) => Promise<{ id: string; score: number }[]>;
|
||||
ftsGetDocument: (options: {
|
||||
id: string;
|
||||
indexName: string;
|
||||
docId: string;
|
||||
}) => Promise<{ text: string | null }>;
|
||||
ftsGetMatches: (options: {
|
||||
id: string;
|
||||
indexName: string;
|
||||
docId: string;
|
||||
query: string;
|
||||
}) => Promise<Array<{ start: number; end: number }>>;
|
||||
ftsFlushIndex: (options: { id: string }) => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -339,4 +339,71 @@ export const NbStoreNativeDBApis: NativeDBApis = {
|
||||
crawlDocData: async function (id: string, docId: string) {
|
||||
return NbStore.crawlDocData({ id, docId });
|
||||
},
|
||||
ftsAddDocument: async function (
|
||||
id: string,
|
||||
indexName: string,
|
||||
docId: string,
|
||||
text: string,
|
||||
index: boolean
|
||||
): Promise<void> {
|
||||
await NbStore.ftsAddDocument({
|
||||
id,
|
||||
indexName,
|
||||
docId,
|
||||
text,
|
||||
index,
|
||||
});
|
||||
},
|
||||
ftsDeleteDocument: async function (
|
||||
id: string,
|
||||
indexName: string,
|
||||
docId: string
|
||||
): Promise<void> {
|
||||
await NbStore.ftsDeleteDocument({
|
||||
id,
|
||||
indexName,
|
||||
docId,
|
||||
});
|
||||
},
|
||||
ftsSearch: async function (
|
||||
id: string,
|
||||
indexName: string,
|
||||
query: string
|
||||
): Promise<{ id: string; score: number }[]> {
|
||||
return await NbStore.ftsSearch({
|
||||
id,
|
||||
indexName,
|
||||
query,
|
||||
});
|
||||
},
|
||||
ftsGetDocument: async function (
|
||||
id: string,
|
||||
indexName: string,
|
||||
docId: string
|
||||
): Promise<string | null> {
|
||||
const result = await NbStore.ftsGetDocument({
|
||||
id,
|
||||
indexName,
|
||||
docId,
|
||||
});
|
||||
return result.text;
|
||||
},
|
||||
ftsGetMatches: async function (
|
||||
id: string,
|
||||
indexName: string,
|
||||
docId: string,
|
||||
query: string
|
||||
): Promise<{ start: number; end: number }[]> {
|
||||
return await NbStore.ftsGetMatches({
|
||||
id,
|
||||
indexName,
|
||||
docId,
|
||||
query,
|
||||
});
|
||||
},
|
||||
ftsFlushIndex: async function (id: string): Promise<void> {
|
||||
await NbStore.ftsFlushIndex({
|
||||
id,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user