Update search_kws rule for tantivy

This commit is contained in:
2026-06-23 08:30:07 +08:00
parent 8f8d12a5e7
commit 333f2cff43

View File

@@ -207,16 +207,20 @@ export class HighlightedMarkdown extends Component {
['nickname', NICKNAME_RE],
];
if (props.search_param) {
let search_kws = props.search_param.split(' ').filter((s) => !!s);
rules.push([
'search',
new RegExp(
`(${search_kws
.map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
.join('|')})`,
'g',
),
]);
let search_kws = props.search_param
.split(/[\s()+-]+/)
.filter((s) => s && s !== 'AND' && s !== 'OR');
if (search_kws.length) {
rules.push([
'search',
new RegExp(
`(${search_kws
.map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
.join('|')})`,
'g',
),
]);
}
}
const splitted = split_text(originalText, rules);