Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lunr-languages? #22

Closed
juju2143 opened this issue Jul 31, 2016 · 11 comments
Closed

lunr-languages? #22

juju2143 opened this issue Jul 31, 2016 · 11 comments

Comments

@juju2143
Copy link

The README.md mentions using elasticlunr.js to index other language documents with lunr-languages, but the repository seems gone now. Can I still index, say, French documents, or it's only English-only for now?

@weixsong
Copy link
Owner

weixsong commented Aug 1, 2016

https://github.com/MihaiValentin/lunr-languages

@weixsong
Copy link
Owner

weixsong commented Aug 1, 2016

I will update the link.

@weixsong weixsong closed this as completed Aug 1, 2016
@juju2143
Copy link
Author

juju2143 commented Aug 1, 2016

Thanks for the answer, but unfortunately, it gives an error about lunr.SortedSet when I try it.

lunr.fr.js:688
    lunr.fr.stopWordFilter.stopWords = new lunr.SortedSet();
                                       ^

TypeError: lunr.SortedSet is not a function
    at /home/juju/mlpsubs/lunr.fr.js:688:40
    at Object.<anonymous> (/home/juju/mlpsubs/serialize.js:8:24)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:134:18)
    at node.js:962:3

Here's my node.js code:

var lunr = require('elasticlunr');

require('./lunr.stemmer.support.js')(lunr);
require('./lunr.fr.js')(lunr);

var index = lunr(function() {
  this.use(lunr.fr);
  this.addField('text');
  this.setRef('id');
  this.saveDocument(false);
});

Am I doing it right or that's a legitimate error?

@weixsong weixsong reopened this Sep 6, 2016
@Kreozot
Copy link

Kreozot commented Sep 6, 2016

Thanks!

@Kreozot
Copy link

Kreozot commented Sep 6, 2016

I think it would make sense to cherry pick this from lunr.js to improve compatibility.

I think it needs some refactoring. Because it uses global lunr object which doesn't exist in elasticlunr implementation.

@Kreozot
Copy link

Kreozot commented Sep 6, 2016

@weixsong If I prepare this PR, will you merge it?

@weixsong
Copy link
Owner

weixsong commented Sep 7, 2016

Hi, @Kreozot , I did not use elasticlunr.js with other languages so I did not notice that it does not work with lunr-languages, and I have checked the code, it did need some refactor to support other languages to make elasticlunr.js more powerful.

I will try to refactor the code to provide other language support. But if you could do that is good. But my idea is refactor totally to add other language support, that need to design a abstract interface that for function such as tokenizer, stemmer, etc. I dont want to just make a copy of Sorted_set in lunr.js, actually in the beginning I removed Sorted_set.js just because the performance of it and it's useless in elasticlunr.js.

:)

@Kreozot
Copy link

Kreozot commented Sep 7, 2016

Wow, it will be cool! Good luck with that!

So, for now it is possible to using lunr-languages with elasticlunr in node.js with this code (it needs to have lunr and lunr-languages in your deps, but do not need to edit any code):

var elasticlunr = require('elasticlunr');
global.lunr = elasticlunr;
require('lunr/lib/sorted_set.js');
require('lunr-languages/lunr.stemmer.support.js')(elasticlunr);
require('lunr-languages/lunr.ru.js')(elasticlunr);

@weixsong
Copy link
Owner

weixsong commented Sep 8, 2016

Lunr-languages.js is now supported both in browser & Node.js, please try:

Other Languages

Default supported language of elasticlunr.js is English, if you want to use elasticlunr.js to index other language documents, then you need to use elasticlunr.js combined with lunr-languages.

Other languages example in Browser

Suppose you are using elasticlunr.js in browser for other languages, you could download the corresponding language support from lunr-languages, then include the scripts as:

<script src="lunr.stemmer.support.js"></script>
<script src="lunr.de.js"></script>

then, you could use elasticlunr.js as normal:

var index = elasticlunr(function () {
    // use the language (de)
    this.use(elasticlunr.de);
    // then, the normal elasticlunr index initialization
    this.addField('title')
    this.addField('body')
});

Pay attention to the special code:

    this.use(elasticlunr.de);

If you are using other language, such as es(Spanish), download the corresponding lunr.es.js file and lunr.stemmer.support.js, and change the above line to:

    this.use(elasticlunr.es);

Other languages example in Node.js

Suppose you are using elasticlunr.js in Node.js for other languages, you could download the corresponding language support from lunr-languages, put the files lunr.es.js file and lunr.stemmer.support.js in your project, then in your Node.js module, use elasticlunr.js as:

var elasticlunr = require('elasticlunr');
require('./lunr.stemmer.support.js')(elasticlunr);
require('./lunr.de.js')(elasticlunr);

var index = elasticlunr(function () {
    // use the language (de)
    this.use(elasticlunr.de);
    // then, the normal elasticlunr index initialization
    this.addField('title')
    this.addField('body')
});

For more details, please go to lunr-languages.

@weixsong weixsong closed this as completed Sep 8, 2016
@biodranik
Copy link

@weixsong Is it possible to support multi-language feature? When the text contains strings in two different languages, e.g. Russian and English?

@stevedevhere
Copy link

@biodranik

@weixsong Is it possible to support multi-language feature? When the text contains strings in two different languages, e.g. Russian and English?

Hi, have you solved this question? I also need to do a search where the article contains Russian and English text

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants