Better selection for top excerpt
This commit is contained in:
@@ -98,4 +98,13 @@ export class Query {
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getBestStringForExcerpt(): string {
|
||||||
|
// If we have quoted expressions, return the longest one
|
||||||
|
if (this.#inQuotes.length) {
|
||||||
|
return this.#inQuotes.sort((a, b) => b.length - a.length)[0] ?? ''
|
||||||
|
}
|
||||||
|
// Otherwise, just return the query as is
|
||||||
|
return this.segmentsToStr()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,18 +134,18 @@ export function getMatches(
|
|||||||
.substring(matchStartIndex, matchEndIndex)
|
.substring(matchStartIndex, matchEndIndex)
|
||||||
.trim()
|
.trim()
|
||||||
if (originalMatch && match.index >= 0) {
|
if (originalMatch && match.index >= 0) {
|
||||||
matches.push({ match: originalMatch, offset: match.index + 1 })
|
matches.push({ match: originalMatch, offset: match.index })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the query is more than 1 token and can be found "as is" in the text, put this match first
|
// If the query is more than 1 token and can be found "as is" in the text, put this match first
|
||||||
if (query && query.query.text.length > 1) {
|
if (query && (query.query.text.length > 1 || query.getExactTerms().length > 0)) {
|
||||||
const best = text.indexOf(query.segmentsToStr())
|
const best = text.indexOf(query.getBestStringForExcerpt())
|
||||||
if (best > -1 && matches.find(m => m.offset === best)) {
|
if (best > -1 && matches.find(m => m.offset === best)) {
|
||||||
matches = matches.filter(m => m.offset !== best)
|
matches = matches.filter(m => m.offset !== best)
|
||||||
matches.unshift({
|
matches.unshift({
|
||||||
offset: best,
|
offset: best,
|
||||||
match: query.segmentsToStr(),
|
match: query.getBestStringForExcerpt(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user