Skip to content

Commit

Permalink
fix issues #8
Browse files Browse the repository at this point in the history
  • Loading branch information
weixsong committed Mar 7, 2016
1 parent e492d9b commit 4c286bf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ elasticlunr.tokenizer = function (str) {
return true;
});

return arr.map(function (t) {
arr = arr.map(function (t) {
return elasticlunr.utils.toString(t).toLowerCase();
});

var out = [];
arr.forEach(function(item) {
var tokens = item.split(elasticlunr.tokenizer.seperator);
out = out.concat(tokens);
}, this);

return out;
}

return str.toString().trim().toLowerCase().split(elasticlunr.tokenizer.seperator);
Expand Down
24 changes: 24 additions & 0 deletions test/tokenizer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,27 @@ test("test get seperator function", function () {
elasticlunr.tokenizer.setSeperator(sep2);
deepEqual(elasticlunr.tokenizer.getSeperator(), sep2);
});

test("tokenize array", function () {
var str = ['hello world', 'glad to see you'];
var tokens = elasticlunr.tokenizer(str);
deepEqual(tokens, ['hello', 'world', 'glad', 'to', 'see', 'you']);
});

test("tokenize array 2", function () {
var str = ['helloworld', 'glad to see you'];
var tokens = elasticlunr.tokenizer(str);
deepEqual(tokens, ['helloworld', 'glad', 'to', 'see', 'you']);
});

test("tokenize array", function () {
var str = ['helloworld', null, undefined, 'glad to see you'];
var tokens = elasticlunr.tokenizer(str);
deepEqual(tokens, ['helloworld', 'glad', 'to', 'see', 'you']);
});

test("tokenize array", function () {
var str = ['helloworld', 'glad to see you', 'hyper-parameters'];
var tokens = elasticlunr.tokenizer(str);
deepEqual(tokens, ['helloworld', 'glad', 'to', 'see', 'you', 'hyper', 'parameters']);
});

0 comments on commit 4c286bf

Please sign in to comment.