-
Notifications
You must be signed in to change notification settings - Fork 71
Add "Fuzzy" search #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bagelbyheart
wants to merge
23
commits into
libretro:master
Choose a base branch
from
bagelbyheart:fuzzy_search
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add "Fuzzy" search #523
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
46098ef
Basic functionality within ludo
5ce1b2d
cleaned up the pbp file check
aa7043c
cleaned up trailing whitespace
5c56421
Added m3u support and improved multi disc playlist support.
42b97cf
Starting on fuzzy search
26ed695
I've broken something, but I'm not sure what.
877fc20
update to g1.18 to slices support.
cb4772c
fixed CRC fallthrough to name
6f86332
fixed no match debugging
c43df73
I seem to have broken my lookup for multidisc entries
3dd61b1
basic fuzzy search is working fully. Next up is searching without par…
55c9427
configurable starting path added.
723ec5e
Merge branch 'set_default_path' into fuzzy_search
3aed43e
almost there. need to update FindByROMName to take file extension int…
8298d8c
I'm spiraling a bit. Matches are better but I'm failing to limit to t…
1a0ee1e
enforcing extension match
41da337
Merge branch 'extension_matching' into fuzzy_search
30a2840
I broke n64 somehow, but everything else is working.
6463e75
fixed n64 support by adding .z64 to the scanner matches.
b1c0159
Merge branch 'master' into fuzzy_search
bagelbyheart 4837758
satisfy staticcheck
9cb0c2f
Merge branch 'master' into fuzzy_search
bagelbyheart fa831ff
hopefully this fixes the build errors in x86 linux.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,17 @@ package dat | |
|
||
import ( | ||
"encoding/xml" | ||
"fmt" | ||
"strings" | ||
//"slices" | ||
"sort" | ||
//"github.com/kr/pretty" | ||
"log" | ||
//"path/filepath" | ||
"strconv" | ||
"sync" | ||
"path/filepath" | ||
//"github.com/libretro/ludo/utils" | ||
) | ||
|
||
// DB is a database that contains many Dats, mapped to their system name | ||
|
@@ -63,9 +71,15 @@ func Parse(dat []byte) Dat { | |
} | ||
|
||
// FindByCRC loops over the Dats in the DB and concurrently matches CRC checksums. | ||
func (db *DB) FindByCRC(romPath string, romName string, crc uint32, games chan (Game)) { | ||
func (db *DB) FindByCRC(romPath string, romName string, crc uint32, games chan (Game)) (bool) { | ||
var wg sync.WaitGroup | ||
wg.Add(len(*db)) | ||
// this structure and subsequent object are remade ever run. | ||
type SafeBool struct { | ||
mu sync.Mutex | ||
found bool | ||
} | ||
game_found := SafeBool{found: false} | ||
// For every Dat in the DB | ||
for system, dat := range *db { | ||
go func(dat Dat, crc uint32, system string) { | ||
|
@@ -79,17 +93,41 @@ func (db *DB) FindByCRC(romPath string, romName string, crc uint32, games chan ( | |
game.Path = romPath | ||
game.System = system | ||
games <- game | ||
game_found.mu.Lock() | ||
fmt.Printf("CRC match: %s -> %s\n", romName, game.Name) | ||
game_found.found = true | ||
game_found.mu.Unlock() | ||
} | ||
} | ||
wg.Done() | ||
}(dat, crc, system) | ||
} | ||
// Synchronize all the goroutines | ||
wg.Wait() | ||
// then check if the game was found or not. If it wasn't pass it to | ||
// FindByROMName. For some reason this isn't consistently working. | ||
//fmt.Printf("%s: %v\n", romName, game_found.found) | ||
return game_found.found | ||
// if !game_found.found { | ||
// db.FindByROMName(romPath, filepath.Base(romPath), crc, games) | ||
// } | ||
} | ||
|
||
// FindByROMName loops over the Dats in the DB and concurrently matches ROM names. | ||
func (db *DB) FindByROMName(romPath string, romName string, crc uint32, games chan (Game)) { | ||
// I'm going to update this to do fuzzy matching. To me that means: | ||
// - try to build a list with a mutex, | ||
// - if there is an exact name match use that | ||
// - otherwise at the end look through the potential matches with a few | ||
// adjustments for country codes (hoping for exact match) | ||
// - finally try to find a match without country code | ||
// - before failing | ||
func (db *DB) FindByROMName(romPath string, romName string, crc uint32, games chan (Game)) (bool) { | ||
type SafeLookup struct { | ||
mu sync.Mutex | ||
options []Game | ||
found bool | ||
} | ||
game_found := SafeLookup{found: false} | ||
var wg sync.WaitGroup | ||
wg.Add(len(*db)) | ||
// For every Dat in the DB | ||
|
@@ -103,16 +141,57 @@ func (db *DB) FindByROMName(romPath string, romName string, crc uint32, games ch | |
// If the checksums match | ||
for _, ROM := range game.ROMs { | ||
if romName == ROM.Name { | ||
fmt.Printf("Exact match: %s -> %s\n", romName, ROM.Name) | ||
game.Path = romPath | ||
game.System = system | ||
games <- game | ||
game_found.mu.Lock() | ||
game_found.found = true | ||
game_found.mu.Unlock() | ||
} else { | ||
var gameName = strings.Split(romName, ".")[0] | ||
var gameExt = strings.Split(romName, ".")[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the file may contain multiple dots or even no dots. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call! |
||
if (strings.Contains(ROM.Name, gameName)) && | ||
(strings.Contains(ROM.Name, gameExt)) { | ||
var option_has bool | ||
for _, option := range game_found.options { | ||
//fmt.Println(romName, option.Name) | ||
if option.Name == game.Name { | ||
option_has = true | ||
} | ||
} | ||
if !(option_has) { | ||
game_found.mu.Lock() | ||
//fmt.Println(romName, game.Name) | ||
game.Path = romPath | ||
game.System = system | ||
game_found.options = append(game_found.options, game) | ||
game_found.mu.Unlock() | ||
} | ||
} | ||
} | ||
// element is the element from someSlice for where we are | ||
} | ||
} | ||
wg.Done() | ||
}(dat, crc, system) | ||
} | ||
// Synchronize all the goroutines | ||
wg.Wait() | ||
if !game_found.found { | ||
if len(game_found.options) > 0 { | ||
game_found.found = true | ||
sort.SliceStable(game_found.options, func(i, j int) bool { | ||
return len(game_found.options[i].Name) < len(game_found.options[j].Name) | ||
}) | ||
for _, option := range game_found.options { | ||
fmt.Printf("Fuzzy match: %s -> %s for %s\n", filepath.Base(romPath), option.Name, option.System) | ||
games <- option | ||
break | ||
} | ||
} | ||
//if game_found.found == false { | ||
// fmt.Printf("No match: %s\n", romName) | ||
//} | ||
} | ||
return game_found.found | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Didn't analyze it deeply, but do you really need a mutex or a
atomic.Bool
fits your needs?