elasticlunr.js
elasticlunr.js copied to clipboard
Wildcard Search
I'm happily using elasticlunr.js, but I don't see any examples or documentation around supporting wildcards, which my users are requesting. It looks like this is available in lunr.js but I would rather not switch -- is there any way to deliver it in elasticlunr.js that I am missing?
@dveuve , thanks very much for using elasticlunr.js.
Do you mean wildcars like this "*ello", ".ello"?
Elasticlunr.js not support it, and actually I don't have time to support it, maybe when I have time I could support it or if you could contribute it that would be great.
Would like to have it, too.
@weixsong is it possible to use wildcard for the fields as well ?, so
var index = elasticlunr(function () {
this.addField('title.*'); // title.en, title.fr, title.etc..
this.addField('body.*');
this.setRef('id');
});
I'm not quite sure what you want to achieve with this while index-creation @ctf0
const languages = ['en', 'it', 'de', 'sp'];
languages.forEach(lang => {
this.addField('title.' + lang);
});
You could set up a Configuration for each language and add it as parameter to the 'search'-method, if you want to react on different language depending queries
@ToLuSt do u have an example or a link for me to read more about this ?
i've read both
- https://github.com/weixsong/elasticlunr.js#other-languages-example-in-browser
- https://github.com/weixsong/lunr-languages
but not sure how the multi locale search/index works
So your goal is to retrieve information on many different languages and you have docs which are either in english, spanish or german aso..
i didn't work with multi languages yet, but I tried it in my application and indexing is working how it should. Don't know if it is what u are looking for:
const elasticlunr = require('elasticlunr');
require('lunr-languages/lunr.stemmer.support.js')(elasticlunr);
require('lunr-languages/lunr.multi.js')(elasticlunr)
require('lunr-languages/lunr.de.js')(elasticlunr);
require('lunr-languages/lunr.es.js')(elasticlunr);
const index = elasticlunr(function () {
this.use(elasticlunr.multiLanguage('en', 'de', 'es'));
const languages = ['en', 'it', 'de', 'sp'];
languages.forEach(lang => { // could use this to create language specific fields
this.addField('title.' + lang);
});
this.setRef('id');
});
So the language specific Stemmer is used to create the index.
It's your choice to use language specific fields or not. You are also free to search on only those fields which language is currently used. (if your app knows which language is currently used)
yeah thats exactly what am after, for the search part am still not sure how, the docs doesnt have this part.
Maybe s.th. like this for individual configs.
/**
* Configure search config
*/
searchConfig(language: string): any {
let userConfig;
// Choose Config depending on chosen language
if (language === 'en') {
userConfig = {
fields: {
title.en: { boost: 2 }
},
bool: 'OR',
expand: true
};
} else if () {
} else { // All Languages
userConfig = {
fields: {
title.en: { boost: 2 },
title.sp: { boost: 2 }
},
bool: 'OR',
expand: true
};
}
let configStr = null;
if (userConfig != null) {
configStr = JSON.stringify(userConfig);
}
const config = new elasticlunr.Configuration(configStr, this.fields).get();
return config; // add this to search method
}
maybe it could be as simple as this ?
index.search("Oracle database profit", {
fields: {
title[this.currentLocale]: {boost: 2},
body[this.currentLocale]: {boost: 1}
}
});
So your goal is to retrieve information on many different languages and you have docs which are either in english, spanish or german aso..
i didn't work with multi languages yet, but I tried it in my application and indexing is working how it should. Don't know if it is what u are looking for:
const elasticlunr = require('elasticlunr'); require('lunr-languages/lunr.stemmer.support.js')(elasticlunr); require('lunr-languages/lunr.multi.js')(elasticlunr) require('lunr-languages/lunr.de.js')(elasticlunr); require('lunr-languages/lunr.es.js')(elasticlunr); const index = elasticlunr(function () { this.use(elasticlunr.multiLanguage('en', 'de', 'es')); const languages = ['en', 'it', 'de', 'sp']; languages.forEach(lang => { // could use this to create language specific fields this.addField('title.' + lang); }); this.setRef('id'); });
So the language specific Stemmer is used to create the index.
It's your choice to use language specific fields or not. You are also free to search on only those fields which language is currently used. (if your app knows which language is currently used)
@ToLuSt it shows me
Uncaught TypeError: elasticlunr.multiLanguage is not a function