== Files == ocarina/include/ filter.h ocarina/lib/ filter.cpp == Depends == database Filter: (lib/filter.cpp) Filtering is used to generate a subset of songs displayed by the UI to that users can choose from. The inverted index is generated at startup so there is no need for a remove() function, since it will be wiped the next time the application starts. - Index: Database filter_index; map lowercase_cache; unsigned int lowercase_cache_hits; - Parsing: 1) Convert the provided string into a list of words, using whitespace and the following characters as delimiters: \/,;()_-~+" For each word: 2) Check the lowercase_cache to see if we have seen the word before, a) If we have, return the stored string b) Convert the string to lowercase and strip out remaining special characters. Add the result to the lowercase_cache; - API: void filter :: add(string, track_id); Parse the string into substrings following the "Parsing" section (above). Add each (substring, track_id) pair to the filter_index. To generate substrings, iterate over the word starting from the front. For example: "goron" would contain the substrings {g, go, gor, goro, goron}. void filter :: search(string, set &); Parse the string into substrings following the "Parsing" section (above). We want to find track_ids that match ALL substrings, so take the intersection of all sets returned by the filter_index for a given substring. std::string filter :: to_lowercase(const std::string &string); Split the string into words following step 1 of "Parsing" (above). Assemble and return a result string using the lower case cache to convert each term to lowercase. void filter :: print_cache_stats(); Print cache hit and size information. void filter :: get_index(); This function only exists if CONFIG_TEST is enabled. Return the index storing all the filter data.