From 7b40de9c464eafa95ad9acf68624379be068301e Mon Sep 17 00:00:00 2001 From: akumatus Date: Fri, 21 Mar 2025 05:09:18 +0000 Subject: [PATCH] refactor(core): remove redundant unused implementation (#11042) Close [BS-2850](https://linear.app/affine-design/issue/BS-2850). --- .../docs-search/services/docs-search.ts | 234 ------------------ 1 file changed, 234 deletions(-) diff --git a/packages/frontend/core/src/modules/docs-search/services/docs-search.ts b/packages/frontend/core/src/modules/docs-search/services/docs-search.ts index cdf86a7327..e97692354f 100644 --- a/packages/frontend/core/src/modules/docs-search/services/docs-search.ts +++ b/packages/frontend/core/src/modules/docs-search/services/docs-search.ts @@ -26,106 +26,6 @@ export class DocsSearchService extends Service { this.indexer.startCrawling(); } - async search(query: string): Promise< - { - docId: string; - title: string; - score: number; - blockId?: string; - blockContent?: string; - }[] - > { - const { buckets } = await this.indexer.blockIndex.aggregate( - { - type: 'boolean', - occur: 'must', - queries: [ - { - type: 'match', - field: 'content', - match: query, - }, - { - type: 'boolean', - occur: 'should', - queries: [ - { - type: 'all', - }, - { - type: 'boost', - boost: 1.5, - query: { - type: 'match', - field: 'flavour', - match: 'affine:page', - }, - }, - ], - }, - ], - }, - 'docId', - { - pagination: { - limit: 50, - skip: 0, - }, - hits: { - pagination: { - limit: 2, - skip: 0, - }, - fields: ['blockId', 'flavour'], - highlights: [ - { - field: 'content', - before: '', - end: '', - }, - ], - }, - } - ); - - const docData = await this.indexer.docIndex.getAll( - buckets.map(bucket => bucket.key) - ); - - const result = []; - - for (const bucket of buckets) { - const firstMatchFlavour = bucket.hits.nodes[0]?.fields.flavour; - if (firstMatchFlavour === 'affine:page') { - // is title match - const blockContent = bucket.hits.nodes[1]?.highlights.content[0]; // try to get block content - result.push({ - docId: bucket.key, - title: bucket.hits.nodes[0].highlights.content[0], - score: bucket.score, - blockContent, - }); - } else { - const title = - docData.find(doc => doc.id === bucket.key)?.get('title') ?? ''; - const matchedBlockId = bucket.hits.nodes[0]?.fields.blockId; - // is block match - result.push({ - docId: bucket.key, - title: typeof title === 'string' ? title : title[0], - blockId: - typeof matchedBlockId === 'string' - ? matchedBlockId - : matchedBlockId[0], - score: bucket.score, - blockContent: bucket.hits.nodes[0]?.highlights.content[0], - }); - } - } - - return result; - } - search$(query: string): Observable< { docId: string; @@ -234,79 +134,6 @@ export class DocsSearchService extends Service { ); } - async searchRefsFrom(docId: string): Promise< - { - docId: string; - title: string; - }[] - > { - const { nodes } = await this.indexer.blockIndex.search( - { - type: 'boolean', - occur: 'must', - queries: [ - { - type: 'match', - field: 'docId', - match: docId, - }, - // Ignore if it is a link to the current document. - { - type: 'boolean', - occur: 'must_not', - queries: [ - { - type: 'match', - field: 'refDocId', - match: docId, - }, - ], - }, - { - type: 'exists', - field: 'refDocId', - }, - ], - }, - { - fields: ['refDocId', 'ref'], - pagination: { - limit: 100, - }, - } - ); - - const refs: ({ docId: string } & ReferenceParams)[] = nodes.flatMap( - node => { - const { ref } = node.fields; - return typeof ref === 'string' - ? [JSON.parse(ref)] - : ref.map(item => JSON.parse(item)); - } - ); - - const docData = await this.indexer.docIndex.getAll( - Array.from(new Set(refs.map(ref => ref.docId))) - ); - - return refs - .flatMap(ref => { - const doc = docData.find(doc => doc.id === ref.docId); - if (!doc) return null; - - const titles = doc.get('title'); - const title = (Array.isArray(titles) ? titles[0] : titles) ?? ''; - const params = omit(ref, ['docId']); - - return { - title, - docId: doc.id, - params: isEmpty(params) ? undefined : toURLSearchParams(params), - }; - }) - .filter(ref => !!ref); - } - watchRefsFrom(docId: string) { return this.indexer.blockIndex .search$( @@ -384,67 +211,6 @@ export class DocsSearchService extends Service { ); } - async searchRefsTo(docId: string): Promise< - { - docId: string; - blockId: string; - title: string; - }[] - > { - const { buckets } = await this.indexer.blockIndex.aggregate( - { - type: 'boolean', - occur: 'must', - queries: [ - { - type: 'match', - field: 'refDocId', - match: docId, - }, - // Ignore if it is a link to the current document. - { - type: 'boolean', - occur: 'must_not', - queries: [ - { - type: 'match', - field: 'docId', - match: docId, - }, - ], - }, - ], - }, - 'docId', - { - hits: { - fields: ['docId', 'blockId'], - pagination: { - limit: 1, - }, - }, - pagination: { - limit: 100, - }, - } - ); - - const docData = await this.indexer.docIndex.getAll( - buckets.map(bucket => bucket.key) - ); - - return buckets.map(bucket => { - const title = - docData.find(doc => doc.id === bucket.key)?.get('title') ?? ''; - const blockId = bucket.hits.nodes[0]?.fields.blockId ?? ''; - return { - docId: bucket.key, - blockId: typeof blockId === 'string' ? blockId : blockId[0], - title: typeof title === 'string' ? title : title[0], - }; - }); - } - watchRefsTo(docId: string) { return this.indexer.blockIndex .aggregate$(