IPB

Welcome Guest ( Log In | Register )

> foobar2000 Development Forum Rules

This forum is for developer discussions only. If you have a problem / bug report / idea / feature request that isn't related to foobar2000 SDK, post it in an appropiate forum instead - tech support questions go to support forum, everything else goes to general forum.
All non-developer posts on this forum will be removed. Continued abuse of this forum will result in admin actions (warnings, account suspension).

 
Reply to this topicStart new topic
Is there a 'fuzzy search' API in foobar?
hymerman
post Oct 12 2012, 09:24
Post #1





Group: Members
Posts: 85
Joined: 1-June 05
Member No.: 22429



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:

CODE
// 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.
Go to the top of the page
+Quote Post
foosion
post Oct 12 2012, 12:12
Post #2





Group: FB2K Moderator (Donating)
Posts: 4431
Joined: 24-February 03
Member No.: 5153



QUOTE (hymerman @ Oct 12 2012, 09:24) *
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?
There is no (relational) database.

QUOTE (hymerman @ Oct 12 2012, 09:24) *
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?
I'm pretty sure that is what everyone else does.

IIRC there is an API for auto-completion which could provide you with the list of all values of particular tags. However that still doesn't give you the corresponding tracks.


--------------------
http://foosion.foobar2000.org/ - my components for foobar2000
Go to the top of the page
+Quote Post
hymerman
post Oct 13 2012, 02:10
Post #3





Group: Members
Posts: 85
Joined: 1-June 05
Member No.: 22429



Ah right, so the only library query mechanism is to get all tracks? It sounds crazy to me, but if that's what all other components do then I guess it's not a problem, since I've yet to encounter a component that is noticeably slow at searching.

Same goes for fuzzy searching; if that's what other components do then I'll do the same. I don't suppose you know of any components that implement fuzzy search that have source available do you? I'd like to re-invent as few wheels as possible smile.gif
Go to the top of the page
+Quote Post
NEMO7538
post Oct 13 2012, 08:23
Post #4





Group: Developer
Posts: 815
Joined: 28-November 03
Member No.: 10088



Look here and use foobar query syntax.
Although not exactly fuzzy, you can use wildcards (* and ?) to cope with a number of situations.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 17th September 2014 - 20:17