Support different languages in search (#21)

This commit is contained in:
Przemek Wiech 2020-11-13 22:40:06 +01:00
parent ef5fe7502a
commit eab1c707f3
3 changed files with 15 additions and 0 deletions

5
package-lock.json generated
View File

@ -11145,6 +11145,11 @@
"resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz",
"integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow=="
},
"lunr-languages": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/lunr-languages/-/lunr-languages-1.4.0.tgz",
"integrity": "sha512-YWfZDExJN/MJEVE/DbM4AuVRLsqeHi+q3wmECMsWjGIOkd5mr9DUNos7fv8f5do9VLRMYXIzFjn+N4+KPI9pQA=="
},
"make-dir": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz",

View File

@ -18,6 +18,7 @@
"js-cookie": "^2.2.1",
"jspdf": "^1.5.3",
"lunr": "^2.3.6",
"lunr-languages": "^1.4.0",
"md5": "^2.2.1",
"parse-gedcom": "^1.0.5",
"query-string": "^5.1.1",

View File

@ -3,6 +3,14 @@ import naturalSort from 'javascript-natural-sort';
import {idToFamMap, idToIndiMap} from '../util/gedcom_util';
import {JsonFam, JsonGedcomData, JsonIndi} from 'topola';
// TODO: Add type declarations and use import instead of require.
require('lunr-languages/lunr.stemmer.support')(lunr);
require('lunr-languages/lunr.multi')(lunr);
require('lunr-languages/lunr.de')(lunr);
require('lunr-languages/lunr.fr')(lunr);
require('lunr-languages/lunr.it')(lunr);
require('lunr-languages/lunr.ru')(lunr);
const MAX_RESULTS = 8;
export interface SearchResult {
@ -58,6 +66,7 @@ class LunrSearchIndex implements SearchIndex {
initialize() {
const self = this;
this.index = lunr(function() {
this.use((lunr as any).multiLanguage('de', 'en', 'fr', 'it', 'ru'));
this.ref('id');
this.field('id');
this.field('name', {boost: 10});