mirror of
https://github.com/kou029w/nodejs-hands-on.git
synced 2025-01-18 08:05:10 +00:00
17 lines
407 B
JavaScript
17 lines
407 B
JavaScript
|
"use strict";
|
||
|
|
||
|
// 正規表現検索を有効化
|
||
|
window.elasticlunr.Index.load = (index) => ({
|
||
|
search(keyword) {
|
||
|
const regexp = new RegExp(keyword, "gi");
|
||
|
|
||
|
return [...Object.entries(index.documentStore.docs)].flatMap(
|
||
|
([ref, doc]) => {
|
||
|
const match = `${doc.title} ${doc.body}`.match(regexp);
|
||
|
|
||
|
return match ? [{ ref, doc, score: match.length }] : [];
|
||
|
},
|
||
|
);
|
||
|
},
|
||
|
});
|