Fix az sort (#14347)

* add stopword package

* sort pet and potion quests by stopword-ized text

* chore(package): revert package lock
Will update after merge

* fix(package): Friday brain

Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
Sky Chrastina
2022-11-18 15:38:28 -07:00
committed by GitHub
parent 1d8e3d45a1
commit 4b4f073089
2 changed files with 56 additions and 1 deletions

View File

@@ -49,6 +49,7 @@
"sass": "^1.34.0",
"sass-loader": "^8.0.2",
"smartbanner.js": "^1.19.1",
"stopword": "^2.0.5",
"svg-inline-loader": "^0.8.2",
"svg-url-loader": "^7.1.1",
"svgo": "^1.3.2",

View File

@@ -402,6 +402,8 @@ import _sortBy from 'lodash/sortBy';
import _throttle from 'lodash/throttle';
import _groupBy from 'lodash/groupBy';
import _map from 'lodash/map';
import _each from 'lodash/each';
import * as stopword from 'stopword/dist/stopword.esm.mjs';
import { mapState } from '@/libs/store';
import ShopItem from '../shopItem';
@@ -426,6 +428,51 @@ import SelectTranslatedArray from '@/components/tasks/modal-controls/selectTrans
import QuestPopover from './questPopover';
import { worldStateMixin } from '@/mixins/worldState';
function splitMultipleDelims (text, delims) {
const omniDelim = 'θνι';
let workingText = text;
for (const delim of delims) {
workingText = workingText.replace(new RegExp(delim, 'g'), omniDelim);
}
return workingText.split(omniDelim);
}
function removeStopwordsFromText (text, language) {
// list of supported languages https://www.npmjs.com/package/stopword
const langs = {
bg: stopword.bul,
cs: stopword.ces,
da: stopword.dan,
de: stopword.deu,
en: stopword.eng,
en_GB: stopword.eng,
'en@pirate': stopword.eng.concat(["th'"]),
es: stopword.spa,
es_419: stopword.spa,
fr: stopword.fra,
he: stopword.heb,
hu: stopword.hun,
id: stopword.ind,
it: stopword.ita,
ja: stopword.jpn,
nl: stopword.nld,
pl: stopword.pol,
pt: stopword.por,
pt_BR: stopword.porBr,
ro: stopword.ron,
ru: stopword.rus,
sk: stopword.slv,
// sr: stopword.,
sv: stopword.swe,
tr: stopword.tur,
uk: stopword.ukr,
zh: stopword.zho,
zh_TW: stopword.zho,
};
const splitText = splitMultipleDelims(text, [' ', "'"]);
return stopword.removeStopwords(splitText, langs[language] || stopword.eng).join(' ').toLowerCase();
}
export default {
components: {
QuestPopover,
@@ -539,7 +586,14 @@ export default {
switch (sortBy) { // eslint-disable-line default-case
case 'AZ': {
result = _sortBy(result, ['text']);
if (category.identifier === 'pet' || category.identifier === 'hatchingPotion') {
_each(result, item => {
item.sortText = removeStopwordsFromText(item.text, this.user.preferences.language);
});
result = _sortBy(result, ['sortText']);
} else {
result = _sortBy(result, ['text']);
}
break;
}