#261 - Fixed supernumerary result
This commit is contained in:
@@ -216,7 +216,7 @@ export class Omnisearch {
|
|||||||
headings1: settings.weightH1,
|
headings1: settings.weightH1,
|
||||||
headings2: settings.weightH2,
|
headings2: settings.weightH2,
|
||||||
headings3: settings.weightH3,
|
headings3: settings.weightH3,
|
||||||
unmarkedTags: settings.weightUnmarkedTags
|
unmarkedTags: settings.weightUnmarkedTags,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -343,7 +343,7 @@ export class Omnisearch {
|
|||||||
public getMatches(text: string, reg: RegExp, query: Query): SearchMatch[] {
|
public getMatches(text: string, reg: RegExp, query: Query): SearchMatch[] {
|
||||||
const startTime = new Date().getTime()
|
const startTime = new Date().getTime()
|
||||||
let match: RegExpExecArray | null = null
|
let match: RegExpExecArray | null = null
|
||||||
const matches: SearchMatch[] = []
|
let matches: SearchMatch[] = []
|
||||||
let count = 0
|
let count = 0
|
||||||
while ((match = reg.exec(text)) !== null) {
|
while ((match = reg.exec(text)) !== null) {
|
||||||
// Avoid infinite loops, stop looking after 100 matches or if we're taking too much time
|
// Avoid infinite loops, stop looking after 100 matches or if we're taking too much time
|
||||||
@@ -351,13 +351,14 @@ export class Omnisearch {
|
|||||||
warnDebug('Stopped getMatches at', count, 'results')
|
warnDebug('Stopped getMatches at', count, 'results')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
const m = match[0]
|
const m = match[2]
|
||||||
if (m) matches.push({ match: m, offset: match.index })
|
if (m) matches.push({ match: m, offset: match.index + 1 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the query can be found "as is" in the text, put this match first
|
// If the query can be found "as is" in the text, put this match first
|
||||||
const best = text.toLowerCase().indexOf(query.segmentsToStr())
|
const best = text.toLowerCase().indexOf(query.segmentsToStr())
|
||||||
if (best > -1) {
|
if (best > -1) {
|
||||||
|
matches = matches.filter(m => m.offset !== best)
|
||||||
matches.unshift({
|
matches.unshift({
|
||||||
offset: best,
|
offset: best,
|
||||||
match: query.segmentsToStr(),
|
match: query.segmentsToStr(),
|
||||||
|
|||||||
Reference in New Issue
Block a user