-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
closes #6139
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ export function presetCollection(collection) { | |
|
||
// matches value to preset.name | ||
const leadingNames = searchable | ||
.filter(a => leading(a.searchName())) | ||
.filter(a => leading(a.searchName()) || a.searchAliases().some(leading)) | ||
.sort(sortPresets('searchName')); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tyrasd
Author
Member
|
||
|
||
// matches value to preset suggestion name | ||
|
@@ -107,7 +107,7 @@ export function presetCollection(collection) { | |
.sort(sortPresets('searchName')); | ||
|
||
const leadingNamesStripped = searchable | ||
.filter(a => leading(a.searchNameStripped())) | ||
.filter(a => leading(a.searchNameStripped()) || a.searchAliasesStripped().some(leading)) | ||
.sort(sortPresets('searchNameStripped')); | ||
|
||
const leadingSuggestionsStripped = suggestions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { | |
let _resolvedMoreFields; // cache | ||
let _searchName; // cache | ||
let _searchNameStripped; // cache | ||
let _searchAliases; // cache | ||
let _searchAliasesStripped; // cache | ||
|
||
_this.id = presetID; | ||
|
||
|
@@ -26,6 +28,8 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { | |
|
||
_this.originalName = _this.name || ''; | ||
|
||
_this.originalAliases = _this.aliases || ''; | ||
|
||
_this.originalScore = _this.matchScore || 1; | ||
|
||
_this.originalReference = _this.reference || {}; | ||
|
@@ -123,6 +127,11 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { | |
}; | ||
|
||
|
||
_this.aliases = () => { | ||
return _this.t('aliases', { 'default': _this.originalAliases }).trim().split(/\s*\n\s*/); | ||
This comment has been minimized.
Sorry, something went wrong.
westnordost
Contributor
|
||
}; | ||
|
||
|
||
_this.terms = () => _this.t('terms', { 'default': _this.originalTerms }) | ||
.toLowerCase().trim().split(/\s*,+\s*/); | ||
|
||
|
@@ -135,15 +144,26 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { | |
|
||
_this.searchNameStripped = () => { | ||
if (!_searchNameStripped) { | ||
_searchNameStripped = _this.searchName(); | ||
// split combined diacritical characters into their parts | ||
if (_searchNameStripped.normalize) _searchNameStripped = _searchNameStripped.normalize('NFD'); | ||
// remove diacritics | ||
_searchNameStripped = _searchNameStripped.replace(/[\u0300-\u036f]/g, ''); | ||
_searchNameStripped = stripDiacritics(_this.searchName()); | ||
} | ||
return _searchNameStripped; | ||
}; | ||
|
||
_this.searchAliases = () => { | ||
if (!_searchAliases) { | ||
_searchAliases = _this.aliases().map(alias => alias.toLowerCase()); | ||
} | ||
return _searchAliases; | ||
}; | ||
|
||
_this.searchAliasesStripped = () => { | ||
if (!_searchAliasesStripped) { | ||
_searchAliasesStripped = _this.searchAliases(); | ||
_searchAliasesStripped = _searchAliasesStripped.map(stripDiacritics); | ||
} | ||
return _searchAliasesStripped; | ||
}; | ||
|
||
_this.isFallback = () => { | ||
const tagCount = Object.keys(_this.tags).length; | ||
return tagCount === 0 || (tagCount === 1 && _this.tags.hasOwnProperty('area')); | ||
|
@@ -306,5 +326,13 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { | |
} | ||
|
||
|
||
function stripDiacritics(s) { | ||
// split combined diacritical characters into their parts | ||
if (s.normalize) s = s.normalize('NFD'); | ||
// remove diacritics | ||
s = s.replace(/[\u0300-\u036f]/g, ''); | ||
return s; | ||
} | ||
|
||
return _this; | ||
} |
1 comment
on commit 8796a41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For preset matching, there are a lot of tests that also serve as kind of a documentation how the presets match. It would be consistent and helpful to replicate the same matching in other libs/apps to also add tests for this new behavior.
How can this work? Doesn't the
sortPresets
function sort by preset name here? It looks like that matches with aliases will not be sorted at all. (Hence, unit tests would make sense)