Skip to content

Commit

Permalink
Add armenian support
Browse files Browse the repository at this point in the history
  • Loading branch information
v4nn4 committed Apr 23, 2023
1 parent 24f03a2 commit 9f68d76
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Lunr Languages is a [Lunr](http://lunrjs.com/) addon that helps you search in do
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/CN.png) Chinese
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/IN.png) Tamil
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/KR.png) Korean
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/AM.png) Armenian
* [Contribute with a new language](CONTRIBUTING.md)

Lunr Languages is compatible with Lunr version `0.6`, `0.7`, `1.0` and `2.X`.
Expand Down
2 changes: 2 additions & 0 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ var list = [
locale: 'zh',
}, {
locale: 'ko',
}, {
locale: 'hy',
}
];

Expand Down
98 changes: 98 additions & 0 deletions lunr.hy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*!
* Lunr languages, `Armenian` language
* https://github.com/turbobit/lunr-languages
*
* Copyright 2021, Manikandan Venkatasubban
* http://www.mozilla.org/MPL/
*/
/*!
* based on
* Snowball JavaScript Library v0.3
* http://code.google.com/p/urim/
* http://snowball.tartarus.org/
*
* Copyright 2010, Oleg Mazko
* http://www.mozilla.org/MPL/
*/

/**
* export the module via AMD, CommonJS or as a browser global
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
*/
;
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory)
} else if (typeof exports === 'object') {
/**
* Node. Does not work with strict CommonJS, but
* only CommonJS-like environments that support module.exports,
* like Node.
*/
module.exports = factory()
} else {
// Browser globals (root is window)
factory()(root.lunr);
}
}(this, function() {
/**
* Just return a value to define the module export.
* This example returns an object, but the module
* can return a function as the exported value.
*/
return function(lunr) {
/* throw error if lunr is not yet included */
if ('undefined' === typeof lunr) {
throw new Error('Lunr is not present. Please include / require Lunr before this script.');
}

/* throw error if lunr stemmer support is not yet included */
if ('undefined' === typeof lunr.stemmerSupport) {
throw new Error('Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.');
}

/* register specific locale function */
lunr.hy = function() {
this.pipeline.reset();
this.pipeline.add(
lunr.hy.trimmer,
lunr.hy.stopWordFilter
);
};

/* lunr trimmer function */
// http://www.unicode.org/charts/
lunr.hy.wordCharacters = "[" +
"A-Za-z" +
"\u0530-\u058F" + // armenian alphabet
"\uFB00-\uFB4F" + // armenian ligatures
"]";
lunr.hy.trimmer = lunr.trimmerSupport.generateTrimmer(lunr.hy.wordCharacters);

lunr.Pipeline.registerFunction(lunr.hy.trimmer, 'trimmer-hy');


/* lunr stop word filter */
// https://www.ranks.nl/stopwords/armenian
lunr.hy.stopWordFilter = lunr.generateStopWordFilter('դու և եք էիր էիք հետո նաև նրանք որը վրա է որ պիտի են այս մեջ ն իր ու ի այդ որոնք այն կամ էր մի ես համար այլ իսկ էին ենք հետ ին թ էինք մենք նրա նա դուք եմ էի ըստ որպես ում'.split(' '));
lunr.Pipeline.registerFunction(lunr.hy.stopWordFilter, 'stopWordFilter-hy');

/* lunr stemmer function */
lunr.hy.stemmer = (function() {

return function(word) {
// for lunr version 2
if (typeof word.update === "function") {
return word.update(function(word) {
return word;
})
} else { // for lunr version <= 1
return word;
}

}
})();
lunr.Pipeline.registerFunction(lunr.hy.stemmer, 'stemmer-hy');
};
}))
1 change: 1 addition & 0 deletions min/lunr.hy.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions test/VersionsAndLanguagesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ var testDocuments = {
fr: require('./testdata/fr'),
hi: require('./testdata/hi'),
hu: require('./testdata/hu'),
hy: require('./testdata/hy'),
it: require('./testdata/it'),
ja: require('./testdata/ja'),
jp: require('./testdata/ja'),
ko: require('./testdata/ko'),
no: require('./testdata/no'),
pt: require('./testdata/pt'),
ro: require('./testdata/ro'),
Expand All @@ -42,8 +44,7 @@ var testDocuments = {
tr: require('./testdata/tr'),
th: require('./testdata/th'),
vi: require('./testdata/vi'),
zh: require('./testdata/zh'),
ko: require('./testdata/ko')
zh: require('./testdata/zh')
};

lunrVersions.forEach(function(lunrVersion) {
Expand Down
36 changes: 36 additions & 0 deletions test/testdata/hy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
fields: [
{
name: 'title',
config: { boost: 10 }
}, {
name: 'body'
}
],
documents: [
{
"title": "test",
"body": "Դուք չեք կարող փորձել աղալ միսը պատահականորեն, քանի որ ոչ բոլոր միսն է նույնը: Օրինակ՝ խոզի փորը աղալիս կարեւոր բաներ կան։",
"id": 1
}, {
"title": "թեստ",
"body": "test Այն չի տրամադրում կորեերեն stop լեզվի տվյալներ: Դա պայմանավորված է նրանով, որ դուք կարող եք հեռացնել անհարկի հետաքննությունները եւ զուգակցումները տոկենիզացիայի փուլում:",
"id": 2
},
],
tests: [
{
what: "find the word %w",
search: "test",
found: 2
}, {
what: "find the word %w",
search: "միսը",
found: 1
}, {
what: "never find a word that does not exist, like %w",
search: "ձուկ",
found: 0
}
]
}

0 comments on commit 9f68d76

Please sign in to comment.