olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.87k stars 546 forks source link

Usage of Lunr js with Turkish language #488

Open irfancnk opened 3 years ago

irfancnk commented 3 years ago

I am trying to use Lunr library in my nodejs environment. Here is the code block that makes the basic search.

const lunr = require("lunr");
require('lunr-languages/lunr.stemmer.support.js')(lunr);
require('lunr-languages/lunr.tr.js')(lunr);

var idx = lunr(function () {
    this.use(lunr.tr);
    this.ref('name');
    this.field('text');
    this.metadataWhitelist = ['position'];
    this.add({
        "name": "./file1.txt",
        "text": "türkçe"
    });
    this.add({
        "name": "./file2.txt",
        "text": "kullanıcı"
    });
});

function searchFor(token) {
    let searchResult = idx.search(`*${token}*`);
    console.log(searchResult.length);
}

searchFor("türkçe")
searchFor("kullanıcı")

The first search hits 1 result as expected. However the second one finds no match. I wonder the reason behind. I have tried using the multi-language as well by adding this.use(lunr.multiLanguage("tr")); and removing this.use(lunr.tr);. Also I tried removing the wildcards * from my search that hits a result but that is not the scenario I need. Is it a problem with the 'tr' support or there is a misunderstanding with my usage?