Refactor graph search to update search engin after node expand or prune

This commit is contained in:
yangdx
2025-03-15 10:52:47 +08:00
parent fdaf199b15
commit f4fceca7f3
4 changed files with 87 additions and 27 deletions

View File

@@ -11,6 +11,7 @@ import { useSettingsStore } from '@/stores/settings'
import { useTabVisibility } from '@/contexts/useTabVisibility'
import seedrandom from 'seedrandom'
import { searchCache, updateSearchEngine, removeFromSearchEngine } from '@/components/graph/graphSearchUtils'
const validateGraph = (graph: RawGraph) => {
if (!graph) {
@@ -544,6 +545,8 @@ const useLightrangeGraph = () => {
rawGraph.nodes.push(newNode);
// Update nodeIdMap
rawGraph.nodeIdMap[nodeId] = rawGraph.nodes.length - 1;
// Update search engine with new node
updateSearchEngine(nodeId, sigmaGraph);
}
}
@@ -572,8 +575,12 @@ const useLightrangeGraph = () => {
}
}
// Update the dynamic edge map
// Update the dynamic edge map and invalidate search cache
rawGraph.buildDynamicMap();
// Force search engine rebuild by invalidating cache
searchCache.graph = null;
searchCache.searchEngine = null;
// STEP 4: Update the expanded node's size
if (sigmaGraph.hasNode(nodeId)) {
@@ -710,11 +717,17 @@ const useLightrangeGraph = () => {
// Remove from nodeIdMap
delete rawGraph.nodeIdMap[nodeToDelete];
// Remove from search engine
removeFromSearchEngine(nodeToDelete);
}
}
// Rebuild the dynamic edge map
// Rebuild the dynamic edge map and invalidate search cache
rawGraph.buildDynamicMap();
// Force search engine rebuild by invalidating cache
searchCache.graph = null;
searchCache.searchEngine = null;
// Show notification if we deleted more than just the selected node
if (nodesToDelete.size > 1) {