Skip to content

Commit

Permalink
Indexing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed Oct 13, 2023
1 parent f7b664a commit 13903a3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions plugs/index/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,6 @@ export async function objectSourceProvider({

export async function discoverSources() {
return (await datastore.query({ prefix: [indexKey, "tag"] })).map((
{ key },
) => key[2]);
{ value },
) => value.name);
}
10 changes: 5 additions & 5 deletions plugs/index/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
continue;
}

const tags = new Set<string>(["item"]);

const item: ItemObject = {
ref: `${name}@${n.from}`,
tags: [],
Expand All @@ -44,7 +46,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {

collectNodesOfType(n, "Hashtag").forEach((h) => {
// 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)) {
Expand All @@ -62,11 +64,9 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
}

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)");
await indexObjects(name, items);
Expand Down
15 changes: 8 additions & 7 deletions plugs/index/paragraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import {
traverseTreeAsync,
} from "$sb/lib/tree.ts";
import { extractAttributes } from "$sb/lib/attribute.ts";
import { ObjectValue } from "$sb/types.ts";

/** ParagraphObject An index object for the top level text nodes */
export type ParagraphObject = {
ref: string;
tags: string[];
text: string;
page: string;
pos: number;
} & Record<string, any>;
export type ParagraphObject = ObjectValue<
{
text: string;
page: string;
pos: number;
} & Record<string, any>
>;

export async function indexParagraphs({ name: page, tree }: IndexTreeEvent) {
const objects: ParagraphObject[] = [];
Expand Down
2 changes: 1 addition & 1 deletion plugs/index/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function indexTags({ name, tree }: IndexTreeEvent) {
[...tags].map((tag) => {
const [tagName, parent] = tag.split(":");
return {
ref: tagName,
ref: tag,
tags: ["tag"],
name: tagName,
page: name,
Expand Down

0 comments on commit 13903a3

Please sign in to comment.