Index: graphspell-js/ibdawg.js ================================================================== --- graphspell-js/ibdawg.js +++ graphspell-js/ibdawg.js @@ -61,12 +61,15 @@ let dDistTemp = new Map(); lRes.forEach((sSugg) => { dDistTemp.set(sSugg, str_transform.distanceDamerauLevenshtein(this.sWord, sSugg)); }); lRes = lRes.sort((sA, sB) => { return dDistTemp.get(sA) - dDistTemp.get(sB); }); dDistTemp.clear(); } - for (let lSugg of this.dSugg.values()) { - for (let sSugg of lSugg) { lRes.push(sSugg); } + for (let [nDist, lSugg] of this.dSugg.entries()) { + if (nDist > this.nDistLimit) { + break; + } + lRes.push(...lSugg); if (lRes.length > nSuggLimit) { break; } } lRes = char_player.filterSugg(lRes); Index: graphspell/ibdawg.py ================================================================== --- graphspell/ibdawg.py +++ graphspell/ibdawg.py @@ -58,18 +58,19 @@ self.nMinDist = nDist self.nDistLimit = min(self.nDistLimit, self.nMinDist+2) def getSuggestions (self, nSuggLimit=10, nDistLimit=-1): "return a list of suggestions" - lRes = [] if self.dSugg[0]: # we sort the better results with the original word self.dSugg[0].sort(key=lambda sSugg: st.distanceDamerauLevenshtein(self.sWord, sSugg)) - for lSugg in self.dSugg.values(): - lRes.extend(lSugg) - if len(lRes) > nSuggLimit: - break + lRes = self.dSugg.pop(0) + for nDist, lSugg in self.dSugg.items(): + if nDist >= self.nDistLimit: + lRes.extend(lSugg) + if len(lRes) > nSuggLimit: + break lRes = list(cp.filterSugg(lRes)) if self.sWord.isupper(): lRes = list(map(lambda sSugg: sSugg.upper(), lRes)) elif self.sWord[0:1].isupper(): lRes = list(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes)) # dont’ use <.istitle>