Merge pull request #1322 from danielaskdd/main
Add middle-content matching for GraphViewer
This commit is contained in:
@@ -1 +1 @@
|
||||
__api_version__ = "0140"
|
||||
__api_version__ = "0141"
|
||||
|
File diff suppressed because one or more lines are too long
2
lightrag/api/webui/index.html
generated
2
lightrag/api/webui/index.html
generated
@@ -8,7 +8,7 @@
|
||||
<link rel="icon" type="image/svg+xml" href="logo.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<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">
|
||||
</head>
|
||||
<body>
|
||||
|
@@ -46,8 +46,30 @@ const GraphLabels = () => {
|
||||
|
||||
let result: string[] = labels
|
||||
if (query) {
|
||||
// Search labels
|
||||
// Search labels using MiniSearch
|
||||
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
|
||||
|
@@ -123,13 +123,42 @@ export const GraphSearchInput = ({
|
||||
}
|
||||
|
||||
// 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))
|
||||
.map((r: { id: string }) => ({
|
||||
id: r.id,
|
||||
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
|
||||
return result.length <= searchResultLimit
|
||||
? result
|
||||
|
Reference in New Issue
Block a user