Skip to content

Commit 3a64c7f

Browse files
committed
2.2.11 bugfix
1 parent 39253dc commit 3a64c7f

File tree

4 files changed

+101
-49
lines changed

4 files changed

+101
-49
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 2.2.11 - 2018-03-17
5+
6+
### Fixed
7+
8+
* Improved diacritic character handling for fuzzy matcher. For ex. `Pokémon Snap` should now be matched to `Pokemon Snap` with diacritic option enabled.
9+
10+
### Added
11+
12+
* More emulator examples (by **Chocobubba** and **Wesim**).
13+
414
## 2.2.10 - 2017-11-21
515

616
### Fixed

package-lock.json

Lines changed: 63 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "steam-rom-manager",
3-
"version": "2.2.10",
3+
"version": "2.2.11",
44
"license": "GPL-3.0",
55
"description": "An app for managing ROMs in Steam",
66
"author": {
@@ -110,7 +110,6 @@
110110
"@types/bluebird": "^3.5.20",
111111
"@types/crc": "^3.4.0",
112112
"@types/fs-extra": "^5.0.0",
113-
"@types/fuzzaldrin-plus": "0.0.1",
114113
"@types/glob": "^5.0.35",
115114
"@types/he": "^0.5.29",
116115
"@types/highlight.js": "^9.12.2",

src/lib/fuzzy-matcher.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ParsedDataWithFuzzy, FuzzyEventCallback, FuzzyMatcherOptions } from "../models";
2-
import * as Fuzzy from 'fuzzaldrin-plus';
2+
const Fuzzy = require('fuzzaldrin-plus');
33

44
export class FuzzyMatcher {
55
private list: { totalGames: number, games: string[] };
6+
private latinList: string[];
67

78
constructor(private eventCallback?: FuzzyEventCallback, list?: { totalGames: number, games: string[] }) {
89
this.setEventCallback(eventCallback || ((event: any, data: any) => { }));
@@ -15,6 +16,13 @@ export class FuzzyMatcher {
1516

1617
setFuzzyList(list: { totalGames: number, games: string[] }) {
1718
this.list = list;
19+
if (this.isLoaded()){
20+
this.latinList = new Array(list.games.length);
21+
22+
for (let i = 0; i < list.games.length; i++) {
23+
this.latinList[i] = list.games[i].replaceDiacritics();
24+
}
25+
}
1826
}
1927

2028
fuzzyMatchParsedData(data: ParsedDataWithFuzzy, options: FuzzyMatcherOptions, verbose: boolean = true) {
@@ -66,32 +74,44 @@ export class FuzzyMatcher {
6674
}
6775

6876
private matchFromList(input: string, options: FuzzyMatcherOptions) {
69-
if (input.length === 0){
77+
if (input.length === 0) {
7078
return { output: input, matched: false };
7179
}
7280
// Check if title contains ", The..."
7381
else if (/,\s*the/i.test(input)) {
7482
let modifiedInput = input.replace(/(.*?),\s*(.*)/i, '$2 $1');
7583
modifiedInput = this.modifyString(modifiedInput, options);
76-
let matches = this.performMatching(modifiedInput);
84+
let matches = this.performMatching(modifiedInput, options.replaceDiacritics);
7785
if (matches.matched)
7886
return matches;
7987
}
8088

8189
let modifiedInput = this.modifyString(input, options);
82-
return this.performMatching(modifiedInput);
90+
return this.performMatching(modifiedInput, options.replaceDiacritics);
8391
}
8492

85-
private performMatching(input: string){
86-
let matches = Fuzzy.filter(this.list.games, input);
93+
private performMatching(input: string, diacriticsRemoved: boolean) {
94+
const list = diacriticsRemoved ? this.latinList : this.list.games;
95+
const preparedQuery = Fuzzy.prepareQuery(input, { usePathScoring: false });
96+
let bestScore = 0;
97+
let matches: string[] = [];
98+
99+
for (let i = 0; i < list.length; i++) {
100+
let score = Fuzzy.score(list[i], preparedQuery.query, { preparedQuery, usePathScoring: false });
101+
if (score >= bestScore && score !== 0){
102+
bestScore = score;
103+
matches.push(this.list.games[i]);
104+
}
105+
}
106+
87107
if (matches.length)
88108
return { output: this.getBestMatch(input, matches), matched: true };
89109
else
90110
return { output: input, matched: false };
91111
}
92112

93113
private modifyString(input: string, options: FuzzyMatcherOptions) {
94-
if (options.replaceDiacritics){
114+
if (options.replaceDiacritics) {
95115
input = input.replaceDiacritics();
96116
}
97117

0 commit comments

Comments
 (0)