@@ -131,52 +131,7 @@ class NoteContentFulltextExp extends Expression {
131
131
132
132
content = content . replace ( / & n b s p ; / g, " " ) ;
133
133
} else if ( type === "mindMap" && mime === "application/json" ) {
134
- let mindMapcontent = JSON . parse ( content ) ;
135
-
136
- // Define interfaces for the JSON structure
137
- interface MindmapNode {
138
- id : string ;
139
- topic : string ;
140
- children : MindmapNode [ ] ; // Recursive structure
141
- direction ?: number ;
142
- expanded ?: boolean ;
143
- }
144
-
145
- interface MindmapData {
146
- nodedata : MindmapNode ;
147
- arrows : any [ ] ; // If you know the structure, replace `any` with the correct type
148
- summaries : any [ ] ;
149
- direction : number ;
150
- theme : {
151
- name : string ;
152
- type : string ;
153
- palette : string [ ] ;
154
- cssvar : Record < string , string > ; // Object with string keys and string values
155
- } ;
156
- }
157
-
158
- // Recursive function to collect all topics
159
- function collectTopics ( node : MindmapNode ) : string [ ] {
160
- // Collect the current node's topic
161
- let topics = [ node . topic ] ;
162
-
163
- // If the node has children, collect topics recursively
164
- if ( node . children && node . children . length > 0 ) {
165
- for ( const child of node . children ) {
166
- topics = topics . concat ( collectTopics ( child ) ) ;
167
- }
168
- }
169
-
170
- return topics ;
171
- }
172
-
173
- // Start extracting from the root node
174
- const topicsArray = collectTopics ( mindMapcontent . nodedata ) ;
175
-
176
- // Combine topics into a single string
177
- const topicsString = topicsArray . join ( ", " ) ;
178
-
179
- content = normalize ( topicsString . toString ( ) ) ;
134
+ content = processMindmapContent ( content ) ;
180
135
} else if ( type === "canvas" && mime === "application/json" ) {
181
136
interface Element {
182
137
type : string ;
@@ -215,4 +170,63 @@ class NoteContentFulltextExp extends Expression {
215
170
}
216
171
}
217
172
173
+ export function processMindmapContent ( content : string ) {
174
+ let mindMapcontent ;
175
+
176
+ try {
177
+ mindMapcontent = JSON . parse ( content ) ;
178
+ } catch ( e ) {
179
+ return "" ;
180
+ }
181
+
182
+ // Define interfaces for the JSON structure
183
+ interface MindmapNode {
184
+ id : string ;
185
+ topic : string ;
186
+ children : MindmapNode [ ] ; // Recursive structure
187
+ direction ?: number ;
188
+ expanded ?: boolean ;
189
+ }
190
+
191
+ interface MindmapData {
192
+ nodedata : MindmapNode ;
193
+ arrows : any [ ] ; // If you know the structure, replace `any` with the correct type
194
+ summaries : any [ ] ;
195
+ direction : number ;
196
+ theme : {
197
+ name : string ;
198
+ type : string ;
199
+ palette : string [ ] ;
200
+ cssvar : Record < string , string > ; // Object with string keys and string values
201
+ } ;
202
+ }
203
+
204
+ // Recursive function to collect all topics
205
+ function collectTopics ( node ?: MindmapNode ) : string [ ] {
206
+ if ( ! node ) {
207
+ return [ ] ;
208
+ }
209
+
210
+ // Collect the current node's topic
211
+ let topics = [ node . topic ] ;
212
+
213
+ // If the node has children, collect topics recursively
214
+ if ( node . children && node . children . length > 0 ) {
215
+ for ( const child of node . children ) {
216
+ topics = topics . concat ( collectTopics ( child ) ) ;
217
+ }
218
+ }
219
+
220
+ return topics ;
221
+ }
222
+
223
+ // Start extracting from the root node
224
+ const topicsArray = collectTopics ( mindMapcontent . nodedata ) ;
225
+
226
+ // Combine topics into a single string
227
+ const topicsString = topicsArray . join ( ", " ) ;
228
+
229
+ return normalize ( topicsString . toString ( ) ) ;
230
+ }
231
+
218
232
export default NoteContentFulltextExp ;
0 commit comments