Update note_content_fulltext.ts

Mindmap search works now
This commit is contained in:
CobriMediaJulien
2024-12-13 13:28:58 +01:00
committed by GitHub
parent cf8ec5a286
commit 24d5311b9f

View File

@@ -12,6 +12,7 @@ import striptags from "striptags";
import utils from "../../utils.js";
import sql from "../../sql.js";
const ALLOWED_OPERATORS = ['=', '!=', '*=*', '*=', '=*', '%='];
const cachedRegexes: Record<string, RegExp> = {};
@@ -134,9 +135,55 @@ class NoteContentFulltextExp extends Expression {
content = content.replace(/&nbsp;/g, ' ');
}
else if (type === 'mindMap' && mime === 'application/json') {
let mindMapcontent = JSON.parse (content);
let topic = mindMapcontent.nodedata.topic;
content = utils.normalize(topic.toString());
// Define interfaces for the JSON structure
interface MindmapNode {
id: string;
topic: string;
children: MindmapNode[]; // Recursive structure
direction?: number;
expanded?: boolean;
}
interface MindmapData {
nodedata: MindmapNode;
arrows: any[]; // If you know the structure, replace `any` with the correct type
summaries: any[];
direction: number;
theme: {
name: string;
type: string;
palette: string[];
cssvar: Record<string, string>; // Object with string keys and string values
};
}
// Recursive function to collect all topics
function collectTopics(node: MindmapNode): string[] {
// Collect the current node's topic
let topics = [node.topic];
// If the node has children, collect topics recursively
if (node.children && node.children.length > 0) {
for (const child of node.children) {
topics = topics.concat(collectTopics(child));
}
}
return topics;
}
// Start extracting from the root node
const topicsArray = collectTopics(mindMapcontent.nodedata);
// Combine topics into a single string
const topicsString = topicsArray.join(", ");
content = utils.normalize(topicsString.toString());
}
else if (type === 'canvas' && mime === 'application/json') {
interface Element {
@@ -145,12 +192,14 @@ class NoteContentFulltextExp extends Expression {
id: string;
[key: string]: any; // Other properties that may exist
}
console.log("hier")
let canvasContent = JSON.parse (content);
const elements: Element [] = canvasContent.elements;
const texts = elements
.filter((element: Element) => element.type === 'text' && element.text) // Filter for 'text' type elements with a 'text' property
.map((element: Element) => element.text!); // Use `!` to assert `text` is defined after filtering
content =utils.normalize(texts.toString())
}