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