Indexing fixes

pull/532/head
Zef Hemel 2023-10-13 16:33:37 +02:00
parent f7b664aad3
commit 13903a3e30
4 changed files with 16 additions and 15 deletions

View File

@ -176,6 +176,6 @@ export async function objectSourceProvider({
export async function discoverSources() { export async function discoverSources() {
return (await datastore.query({ prefix: [indexKey, "tag"] })).map(( return (await datastore.query({ prefix: [indexKey, "tag"] })).map((
{ key }, { value },
) => key[2]); ) => value.name);
} }

View File

@ -32,6 +32,8 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
continue; continue;
} }
const tags = new Set<string>(["item"]);
const item: ItemObject = { const item: ItemObject = {
ref: `${name}@${n.from}`, ref: `${name}@${n.from}`,
tags: [], tags: [],
@ -44,7 +46,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
collectNodesOfType(n, "Hashtag").forEach((h) => { collectNodesOfType(n, "Hashtag").forEach((h) => {
// Push tag to the list, removing the initial # // Push tag to the list, removing the initial #
item.tags.push(h.children![0].text!.substring(1)); tags.add(h.children![0].text!.substring(1));
}); });
for (const child of n.children!.slice(1)) { for (const child of n.children!.slice(1)) {
@ -62,12 +64,10 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
} }
item.name = textNodes.map(renderToText).join("").trim(); item.name = textNodes.map(renderToText).join("").trim();
item.tags = [...tags.values()];
if (item.tags.length > 0) {
// Only index items with tags
items.push(item); items.push(item);
} }
}
// console.log("Found", items, "item(s)"); // console.log("Found", items, "item(s)");
await indexObjects(name, items); await indexObjects(name, items);
} }

View File

@ -8,15 +8,16 @@ import {
traverseTreeAsync, traverseTreeAsync,
} from "$sb/lib/tree.ts"; } from "$sb/lib/tree.ts";
import { extractAttributes } from "$sb/lib/attribute.ts"; import { extractAttributes } from "$sb/lib/attribute.ts";
import { ObjectValue } from "$sb/types.ts";
/** ParagraphObject An index object for the top level text nodes */ /** ParagraphObject An index object for the top level text nodes */
export type ParagraphObject = { export type ParagraphObject = ObjectValue<
ref: string; {
tags: string[];
text: string; text: string;
page: string; page: string;
pos: number; pos: number;
} & Record<string, any>; } & Record<string, any>
>;
export async function indexParagraphs({ name: page, tree }: IndexTreeEvent) { export async function indexParagraphs({ name: page, tree }: IndexTreeEvent) {
const objects: ParagraphObject[] = []; const objects: ParagraphObject[] = [];

View File

@ -43,7 +43,7 @@ export async function indexTags({ name, tree }: IndexTreeEvent) {
[...tags].map((tag) => { [...tags].map((tag) => {
const [tagName, parent] = tag.split(":"); const [tagName, parent] = tag.split(":");
return { return {
ref: tagName, ref: tag,
tags: ["tag"], tags: ["tag"],
name: tagName, name: tagName,
page: name, page: name,