I'd like to search the library for exact and inexact matches of some tags. Ideally this would be some library API to query for an artist and get returned a list of (track, relevance) pairs, where some tracks that don't quite match (e.g. different punctuation, capitalisation, perhaps slight variations in spelling) are returned with lower relevance.
So far the only way I've seen of querying the library is something like this, taken from foo_scrobblecharts:
// database needs to be locked for this to work
inline bool isTrackByArtist(const char * artist,metadb_handle_ptr &track){
const file_info * fileInfo;
if (track->get_info_async_locked(fileInfo)){
for (int j=0; j < fileInfo->meta_get_count_by_name("artist"); j++){
if(stricmp_utf8(fileInfo->meta_get("artist", j), artist) == 0){
return true;
}
}
}
return false;
}
// database has to be locked before calling this function
void filterTracksByArtist(const char * artist, pfc::list_base_t<metadb_handle_ptr> &p_data){
t_size n = p_data.get_count();
bit_array_bittable deleteMask(n);
for (int i = 0; i < n; i++){
const file_info * fileInfo;
deleteMask.set(i,!isTrackByArtist(artist,p_data[i]));
}
p_data.remove_mask(deleteMask);
}
...
pfc::list_t<metadb_handle_ptr> library;
static_api_ptr_t<library_manager> lm;
lm->get_all_items(library);
filterTracksByArtist("Some Artist",library);
Clearly this is literally grabbing everything from the library, then stripping that down to only items exactly matching the artist name passed in (albeit with a case-insensitive compare). This doesn't seem like a very efficient way of doing things to me; surely foobar stores metadata in a database, and that database has some efficient query mechanism developers can use? But that aside, would I have to implement fuzzy search myself by essentially iterating over everything in the library and doing some check more complicated than stricmp, and storing the relevance for each item? This sounds like it would make the inefficiency much, much worse. I'm hoping there's some API in place for this already since I've seen a few components use some kind of fuzzy search.