fix(core): outgoing links cannot be displayed if document refers to itself (#11046)

Close [BS-2850](https://linear.app/affine-design/issue/BS-2850).

### What Changed?
- After flattening the search results, filter the current document.
- Remove duplicate results based on document id.
This commit is contained in:
akumatus
2025-03-21 05:09:19 +00:00
parent 7b40de9c46
commit 281951ecd1

View File

@@ -146,18 +146,6 @@ export class DocsSearchService extends Service {
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',
@@ -174,13 +162,18 @@ export class DocsSearchService extends Service {
.pipe(
switchMap(({ nodes }) => {
return fromPromise(async () => {
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 refs: ({ docId: string } & ReferenceParams)[] = Array.from(
new Map(
nodes
.flatMap(node => {
const { ref } = node.fields;
return typeof ref === 'string'
? [JSON.parse(ref)]
: ref.map(item => JSON.parse(item));
})
.filter(ref => ref.docId !== docId)
.map(ref => [ref.docId, ref])
).values()
);
const docData = await this.indexer.docIndex.getAll(