mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 13:58:50 +08:00
feat(server): search blob names from indexer (#12822)
#### PR Dependency Tree * **PR #12822** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added the ability to search for blob names by their IDs within a workspace. - **Tests** - Introduced new test cases and snapshot tests to validate searching blob names and reading filenames from document snapshots. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -387,6 +387,52 @@ export class IndexerService {
|
||||
await searchProvider.deleteByQuery(table, dsl, options);
|
||||
}
|
||||
|
||||
async searchBlobNames(workspaceId: string, blobIds: string[]) {
|
||||
const result = await this.search({
|
||||
table: SearchTable.block,
|
||||
query: {
|
||||
type: SearchQueryType.boolean,
|
||||
occur: SearchQueryOccur.must,
|
||||
queries: [
|
||||
{
|
||||
type: SearchQueryType.match,
|
||||
field: 'workspaceId',
|
||||
match: workspaceId,
|
||||
},
|
||||
{
|
||||
type: SearchQueryType.match,
|
||||
field: 'flavour',
|
||||
match: 'affine:attachment',
|
||||
},
|
||||
{
|
||||
type: SearchQueryType.boolean,
|
||||
occur: SearchQueryOccur.should,
|
||||
queries: blobIds.map(blobId => ({
|
||||
type: SearchQueryType.match,
|
||||
field: 'blob',
|
||||
match: blobId,
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
options: {
|
||||
fields: ['blob', 'content'],
|
||||
pagination: {
|
||||
limit: 10000,
|
||||
},
|
||||
},
|
||||
});
|
||||
const blobNameMap = new Map<string, string>();
|
||||
for (const node of result.nodes) {
|
||||
const blobId = node.fields.blob[0] as string;
|
||||
const content = node.fields.content[0] as string;
|
||||
if (blobId && content) {
|
||||
blobNameMap.set(blobId, content);
|
||||
}
|
||||
}
|
||||
return blobNameMap;
|
||||
}
|
||||
|
||||
#formatSearchNodes(nodes: SearchNode[]) {
|
||||
return nodes.map(node => ({
|
||||
...node,
|
||||
|
||||
Reference in New Issue
Block a user