Merge pull request #1322 from danielaskdd/main

Add middle-content matching for GraphViewer
This commit is contained in:
Daniel.y
2025-04-09 18:47:52 +08:00
committed by GitHub
5 changed files with 56 additions and 5 deletions

View File

@@ -1 +1 @@
__api_version__ = "0140" __api_version__ = "0141"

File diff suppressed because one or more lines are too long

View File

@@ -8,7 +8,7 @@
<link rel="icon" type="image/svg+xml" href="logo.png" /> <link rel="icon" type="image/svg+xml" href="logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lightrag</title> <title>Lightrag</title>
<script type="module" crossorigin src="/webui/assets/index-1f7er6cN.js"></script> <script type="module" crossorigin src="/webui/assets/index-DVJJypi_.js"></script>
<link rel="stylesheet" crossorigin href="/webui/assets/index-CTB4Vp_z.css"> <link rel="stylesheet" crossorigin href="/webui/assets/index-CTB4Vp_z.css">
</head> </head>
<body> <body>

View File

@@ -46,8 +46,30 @@ const GraphLabels = () => {
let result: string[] = labels let result: string[] = labels
if (query) { if (query) {
// Search labels // Search labels using MiniSearch
result = searchEngine.search(query).map((r: { id: number }) => labels[r.id]) result = searchEngine.search(query).map((r: { id: number }) => labels[r.id])
// Add middle-content matching if results are few
// This enables matching content in the middle of text, not just from the beginning
if (result.length < 5) {
// Get already matched labels to avoid duplicates
const matchedLabels = new Set(result)
// Perform middle-content matching on all labels
const middleMatchResults = labels.filter(label => {
// Skip already matched labels
if (matchedLabels.has(label)) return false
// Match if label contains query string but doesn't start with it
return label &&
typeof label === 'string' &&
!label.toLowerCase().startsWith(query.toLowerCase()) &&
label.toLowerCase().includes(query.toLowerCase())
})
// Merge results
result = [...result, ...middleMatchResults]
}
} }
return result.length <= labelListLimit return result.length <= labelListLimit

View File

@@ -123,13 +123,42 @@ export const GraphSearchInput = ({
} }
// If has query, search nodes and verify they still exist // If has query, search nodes and verify they still exist
const result: OptionItem[] = searchEngine.search(query) let result: OptionItem[] = searchEngine.search(query)
.filter((r: { id: string }) => graph.hasNode(r.id)) .filter((r: { id: string }) => graph.hasNode(r.id))
.map((r: { id: string }) => ({ .map((r: { id: string }) => ({
id: r.id, id: r.id,
type: 'nodes' type: 'nodes'
})) }))
// Add middle-content matching if results are few
// This enables matching content in the middle of text, not just from the beginning
if (result.length < 5) {
// Get already matched IDs to avoid duplicates
const matchedIds = new Set(result.map(item => item.id))
// Perform middle-content matching on all nodes
const middleMatchResults = graph.nodes()
.filter(id => {
// Skip already matched nodes
if (matchedIds.has(id)) return false
// Get node label
const label = graph.getNodeAttribute(id, 'label')
// Match if label contains query string but doesn't start with it
return label &&
typeof label === 'string' &&
!label.toLowerCase().startsWith(query.toLowerCase()) &&
label.toLowerCase().includes(query.toLowerCase())
})
.map(id => ({
id,
type: 'nodes' as const
}))
// Merge results
result = [...result, ...middleMatchResults]
}
// prettier-ignore // prettier-ignore
return result.length <= searchResultLimit return result.length <= searchResultLimit
? result ? result