Fixed #336
This commit is contained in:
@@ -65,10 +65,20 @@
|
|||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (note) {
|
if (note) {
|
||||||
const groups = getGroups(note.matches)
|
let groups = getGroups(note.matches)
|
||||||
groupedOffsets = groups.map(group =>
|
|
||||||
Math.round((group.first()!.offset + group.last()!.offset) / 2)
|
// If there are quotes in the search,
|
||||||
)
|
// only show results that match at least one of the quotes
|
||||||
|
const exactTerms = query.getExactTerms()
|
||||||
|
if (exactTerms.length) {
|
||||||
|
groups = groups.filter(group =>
|
||||||
|
exactTerms.every(exact =>
|
||||||
|
group.some(match => match.match.includes(exact))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
groupedOffsets = groups.map(group => Math.round(group.first()!.offset))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,13 +88,12 @@
|
|||||||
function getGroups(matches: SearchMatch[]): SearchMatch[][] {
|
function getGroups(matches: SearchMatch[]): SearchMatch[][] {
|
||||||
const groups: SearchMatch[][] = []
|
const groups: SearchMatch[][] = []
|
||||||
let lastOffset = -1
|
let lastOffset = -1
|
||||||
let count = 0 // TODO: FIXME: this is a hack to avoid infinite loops
|
let count = 0 // Avoid infinite loops
|
||||||
while (true) {
|
while (++count < 100) {
|
||||||
const group = getGroupedMatches(matches, lastOffset, excerptAfter)
|
const group = getGroupedMatches(matches, lastOffset, excerptAfter)
|
||||||
if (!group.length) break
|
if (!group.length) break
|
||||||
lastOffset = group.last()!.offset
|
lastOffset = group.last()!.offset
|
||||||
groups.push(group)
|
groups.push(group)
|
||||||
if (++count > 100) break
|
|
||||||
}
|
}
|
||||||
return groups
|
return groups
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user