Merge pull request #6741 from svbergerem/fix-typeahead-nonlatin-suggestions
Fix typeahead suggestions with nonlatin chars
This commit is contained in:
commit
f2105d2fce
3 changed files with 40 additions and 3 deletions
|
|
@ -110,6 +110,7 @@ Contributions are very welcome, the hard work is done!
|
|||
* Fixed profile image upload in the mobile UI [#6684](https://github.com/diaspora/diaspora/pull/6684)
|
||||
* Fixed eye not stopping all processes when trying to exit `script/server` [#6693](https://github.com/diaspora/diaspora/pull/6693)
|
||||
* Do not change contacts count when marking notifications on the contacts page as read [#6718](https://github.com/diaspora/diaspora/pull/6718)
|
||||
* Fix typeahead for non-latin characters [#6741](https://github.com/diaspora/diaspora/pull/6741)
|
||||
|
||||
## Features
|
||||
* Support color themes [#6033](https://github.com/diaspora/diaspora/pull/6033)
|
||||
|
|
|
|||
|
|
@ -10,13 +10,18 @@ app.views.SearchBase = app.views.Base.extend({
|
|||
if(options.autoselect) { this.setupAutoselect(); }
|
||||
},
|
||||
|
||||
bloodhoundTokenizer: function(str) {
|
||||
if(typeof str !== "string") { return []; }
|
||||
return str.split(/[\s\.:,;\?\!#@\-_\[\]\{\}\(\)]+/).filter(function(s) { return s !== ""; });
|
||||
},
|
||||
|
||||
setupBloodhound: function(options) {
|
||||
var bloodhoundOptions = {
|
||||
datumTokenizer: function(datum) {
|
||||
var nameTokens = Bloodhound.tokenizers.nonword(datum.name);
|
||||
var handleTokens = datum.handle ? Bloodhound.tokenizers.nonword(datum.name) : [];
|
||||
var nameTokens = this.bloodhoundTokenizer(datum.name);
|
||||
var handleTokens = datum.handle ? this.bloodhoundTokenizer(datum.handle) : [];
|
||||
return nameTokens.concat(handleTokens);
|
||||
},
|
||||
}.bind(this),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
prefetch: {
|
||||
url: "/contacts.json",
|
||||
|
|
|
|||
|
|
@ -65,6 +65,37 @@ describe("app.views.SearchBase", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("bloodhoundTokenizer", function() {
|
||||
beforeEach(function() {
|
||||
this.view = new app.views.SearchBase({ el: "#search_people_form", typeaheadInput: $("#q") });
|
||||
});
|
||||
|
||||
it("splits the string at whitespaces and punctuation chars", function() {
|
||||
expect(this.view.bloodhoundTokenizer("ab.c-d_ef g;h,i #jkl?mnopq!rstu[vwx]::y(z){}")).toEqual(
|
||||
["ab", "c", "d", "ef", "g", "h", "i", "jkl", "mnopq", "rstu", "vwx", "y", "z"]
|
||||
);
|
||||
});
|
||||
|
||||
it("doesn't split the string at Cyrillic chars", function() {
|
||||
expect(this.view.bloodhoundTokenizer("АаБбВвГгДдЕеЁё ЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФф")).toEqual(
|
||||
["АаБбВвГгДдЕеЁё", "ЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФф"]
|
||||
);
|
||||
});
|
||||
|
||||
it("doesn't split the string at Malayalam chars", function() {
|
||||
expect(this.view.bloodhoundTokenizer("ബിപിൻദാസ്")).toEqual(
|
||||
["ബിപിൻദാസ്"]
|
||||
);
|
||||
});
|
||||
|
||||
it("returns an empty array inputs which are not a string", function() {
|
||||
expect(this.view.bloodhoundTokenizer(undefined)).toEqual([]);
|
||||
expect(this.view.bloodhoundTokenizer(null)).toEqual([]);
|
||||
expect(this.view.bloodhoundTokenizer(23)).toEqual([]);
|
||||
expect(this.view.bloodhoundTokenizer({foo: "bar"})).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("setupCustomSearch", function() {
|
||||
it("sets bloodhound.customSearch", function() {
|
||||
this.view = new app.views.SearchBase({el: "#search_people_form", typeaheadInput: $("#q")});
|
||||
|
|
|
|||
Loading…
Reference in a new issue