Skip to content

Commit

Permalink
fix: edgeless notes indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Nov 29, 2024
1 parent 157723b commit a180a76
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ const BlocksuiteTextRenderer = createReactComponentFromLit({
const CollapsibleSection = ({
title,
children,
length,
}: {
title: ReactNode;
children: ReactNode;
length?: number;
}) => {
const [open, setOpen] = useState(false);
return (
<Collapsible.Root open={open} onOpenChange={setOpen}>
<Collapsible.Trigger className={styles.link}>
{title}
<ToggleExpandIcon
className={styles.collapsedIcon}
data-collapsed={!open}
/>
{length ? (
<ToggleExpandIcon
className={styles.collapsedIcon}
data-collapsed={!open}
/>
) : null}
</Collapsible.Trigger>
<Collapsible.Content>{children}</Collapsible.Content>
</Collapsible.Root>
Expand Down Expand Up @@ -152,15 +156,28 @@ export const BiDirectionalLinkPanel = () => {
<CollapsibleSection
key={linkGroup.docId}
title={<AffinePageReference pageId={linkGroup.docId} />}
length={linkGroup.links.length}
>
<div className={styles.linkPreviewContainer}>
{linkGroup.links.map(link => {
if (!link.markdownPreview) {
return null;
}
const searchParams = new URLSearchParams();
searchParams.set('mode', link.displayMode || 'page');

// if note has displayMode === 'edgeless' && has noteBlockId,
// set noteBlockId as blockId
searchParams.set(
'blockIds',
link.displayMode === 'edgeless' && link.noteBlockId
? link.noteBlockId
: link.blockId
);

const to = {
pathname: '/' + linkGroup.docId,
search: `?blockIds=${link.blockId}`,
search: '?' + searchParams.toString(),
hash: '',
};
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface Backlink {
docId: string;
blockId: string;
title: string;
noteBlockId?: string;
displayMode?: string;
markdownPreview?: string;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/core/src/modules/docs-search/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type DocIndexSchema = typeof docIndexSchema;
export const blockIndexSchema = defineSchema({
docId: 'String',
blockId: 'String',
// note id of the block. used for focusing the note in edgeless mode
noteBlockId: 'String',
content: 'FullText',
flavour: 'String',
blob: 'String',
Expand All @@ -29,6 +31,8 @@ export const blockIndexSchema = defineSchema({
// { "databaseName": "xxx" }
additional: { type: 'String', index: false },
markdownPreview: { type: 'String', index: false },
// display mode of the block, value could be 'page' or 'edgeless' or 'both'
displayMode: 'String',
});

export type BlockIndexSchema = typeof blockIndexSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,13 @@ export class DocsSearchService extends Service {
'docId',
{
hits: {
fields: ['docId', 'blockId', 'markdownPreview'],
fields: [
'docId',
'blockId',
'noteBlockId',
'markdownPreview',
'displayMode',
],
pagination: {
limit: 5, // the max number of backlinks to show for each doc
},
Expand All @@ -502,6 +508,9 @@ export class DocsSearchService extends Service {
return bucket.hits.nodes.map(node => {
const blockId = node.fields.blockId ?? '';
const markdownPreview = node.fields.markdownPreview ?? '';
const displayMode = node.fields.displayMode ?? '';
const noteBlockId = node.fields.noteBlockId ?? '';

return {
docId: bucket.key,
blockId: typeof blockId === 'string' ? blockId : blockId[0],
Expand All @@ -510,6 +519,14 @@ export class DocsSearchService extends Service {
typeof markdownPreview === 'string'
? markdownPreview
: markdownPreview[0],
displayMode:
typeof displayMode === 'string'
? displayMode
: displayMode[0],
noteBlockId:
typeof noteBlockId === 'string'
? noteBlockId
: noteBlockId[0],
};
});
});
Expand Down
Loading

0 comments on commit a180a76

Please sign in to comment.